Skip to content

Commit 4ea553c

Browse files
author
Oliver Robson
committed
Added additional 'add' support to OpenSCADObjects
* Added support for __radd__ * Functions as per __add__ * Added support for adding ints * ValueErrors if not 0 * Adding an OpenSCADObject and 0 just returns the OpenSCADObject These changes allow for the use of sum() on OpenSCADOBject lists
1 parent 19d0ef9 commit 4ea553c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

solid/solidpython.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,10 @@ def add(self, child):
475475
if len(child) == 1 and isinstance(child[0], (list, tuple)):
476476
child = child[0]
477477
[self.add(c) for c in child]
478+
elif isinstance(child, int):
479+
# Allowing for creating object by adding to 0 (as in sum())
480+
if child != 0:
481+
raise ValueError
478482
else:
479483
self.children.append(child)
480484
child.set_parent(self)
@@ -531,6 +535,13 @@ def __add__(self, x):
531535
'''
532536
return objects.union()(self, x)
533537

538+
def __radd__(self, x):
539+
'''
540+
This makes u = a+b identical to:
541+
u = union()(a, b )
542+
'''
543+
return objects.union()(self, x)
544+
534545
def __sub__(self, x):
535546
'''
536547
This makes u = a - b identical to:

0 commit comments

Comments
 (0)