ukaea / paramak

Create parametric 3D fusion reactor CAD models
https://paramak.readthedocs.io/en/main/
37 stars 12 forks source link

added new method of performing ordered boolean operations #770

Open billingsley-john opened 3 years ago

billingsley-john commented 3 years ago

Proposed changes

Starting PR which updates the method for performing boolean operations of cut, union and intersect. At the moment, the order in which these operations are performed is hard coded. This PR introduces a boolean_operations dictionary to shapes in which the boolean operations and their orders can be specified.

Types of changes

What types of changes does your code introduce to the Paramak? Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

Further comments

If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...

billingsley-john commented 3 years ago

Usage:

billingsley-john commented 3 years ago

Need to be careful when defining new boolean operations after a shape class has already been defined. I.e. as boolean_operations now controls cut, union and intersect, if we want to 'add' a boolean operation, we need to make sure we don't overwrite any original boolean operations that may already exist. E.g. my_shape = p.RotateStraightShape(boolean_operations={"cut": shape_1})

If we now want to add a union, we need to make sure to include the original cut: my_shape.boolean_operations={"cut": shape_1, "union": shape_2}, or, alternatively, add the key-value pair like this: my_shape.boolean_operations["union"] = shape_2 Note. this second method only works if boolean_operations is already a dictionary