gumyr / build123d

A python CAD programming library
Apache License 2.0
546 stars 90 forks source link

Algebra mode subtraction would not need to be limited to same dimension #446

Closed voneiden closed 10 months ago

voneiden commented 10 months ago

Boolean subtraction has a built in limitation that checks that all other shapes have same dimension as self.

https://github.com/gumyr/build123d/blob/cb5625cbe6bf1220ea82819632c21d6c9a394c58/src/build123d/topology.py#L1692-L1696

This is more limiting as necessary. OpenCascade documentation on Boolean Operations Algorithm states that

For Boolean operation Cut the minimal dimension of S2 should not be less than the maximal dimension of S1.

Further down the line it is elaborated a bit more:

The result of the operation Cut is defined for arguments S1 and S2 that have values of dimensions Dim(S2) that should not be less than Dim(S1). The result can contain shapes of different dimensions, but the minimal dimension of the result will be equal to the minimal dimension of the objects Dim(S1). The result of the operation Cut12 is not defined for other cases. For example, it is impossible to cut an edge from a solid, because a solid without an edge is not defined.

Therefore, for example, subtracting a 3D shape from a 2D shape is from OpenCascade perspective.

Should be a fairly straightforward fix. I'm open to making a PR if requested.

Thoughts?

gumyr commented 10 months ago

You are correct, the dimension check is overly limiting. The fix should be relatively easy; however, we'll need some unit tests to check limits like subtracting from a Vertex, etc. A PR would be great, thanks for the offer.