gumyr / build123d

A python CAD programming library
Apache License 2.0
386 stars 72 forks source link

Mix of Compound and 3D geometry types after mirroring operations. #556

Open Fellow-baka opened 4 months ago

Fellow-baka commented 4 months ago

This is mostly a copy from our Discord discussion with Roger Maitland. Many thanks to him!

Here is what is happening - starting with this:

radius_guide_holes = 1
thickness = 2
rail_holes_loc = Pos(0, 3, 0) * GridLocations(4, 4, 2, 1)
plate = Box(10, 10, 3, align=(Align.CENTER, Align.CENTER, Align.MAX))
bolt_holes = [
    loc * Cylinder(radius=radius_guide_holes, height=thickness)
    for loc in Locations(rail_holes_loc)
]

If we print bolt_holes we get:

[Cylinder at 0x7fd85da57940, label(), #children(0), Cylinder at 0x7fd875fd2850, label(), #children(0)]

as one would expect, a list of Cylinder which is a specialized 3D only subclass of the Compound class. At this point, If we add:

print(mirror(bolt_holes, about=Plane.XZ))

we'll see that mirror has created Part at 0x7fd875fd2730, label(), #children(0). Part is another specialized version of the Compound class for 3D objects. So when we do:

ex2 = plate - bolt_holes - mirror(bolt_holes, about=Plane.XZ)

which from a typing point of view we get:

ex2 = Box(3D) - [Cylinder(3D)] - Part(3D)

However, when we do this: bolt_holes += mirror(bolt_holes, about=Plane.XZ) we are adding a Part to a list so the code extracts the objects from the Part and adds them to the list. Unfortunately, the objects extracted are of type Compound which could be any dimension. Thus bolt_holes becomes:

[Cylinder at 0x7fd85da57940, label(), #children(0), Cylinder at 0x7fd875fd2850, label(), #children(0), Compound at 0x7fd85da57d00, label(), #children(0), Compound at 0x7fd875fd2820, label(), #children(0)]

a mix of Cylinder (3D) and Compound (?D).

Finally, when doing ex2 = plate - bolt_holes the first two subtractions work fine but when the code gets to the Compound objects its check to see if the dimensions are okay fails as there is no defined dimension for a Compound.

That was a lot of words to say this doesn't work. Please raise an Issue for it and maybe we can figure out a fix.