Skip to content

Commit

Permalink
Enhanced algebra boolean operations Issue #537
Browse files Browse the repository at this point in the history
  • Loading branch information
gumyr committed Feb 6, 2024
1 parent 7b5e154 commit 4498b11
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions src/build123d/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
limitations under the License.
"""

from __future__ import annotations

# pylint has trouble with the OCP imports
Expand Down Expand Up @@ -1666,11 +1667,11 @@ def __add__(self, other: Union[list[Shape], Shape]) -> Self:
if SkipClean.clean:
new_shape = new_shape.clean()

if isinstance(self, Part):
if self._dim == 3:
new_shape = Part(new_shape.wrapped)
elif isinstance(self, Sketch):
elif self._dim == 2:
new_shape = Sketch(new_shape.wrapped)
elif isinstance(self, (Wire, Curve)):
elif self._dim == 1:
new_shape = Curve(Compound(new_shape.edges()).wrapped)

return new_shape
Expand Down Expand Up @@ -1698,11 +1699,11 @@ def __sub__(self, other: Shape) -> Self:
if new_shape is not None and SkipClean.clean:
new_shape = new_shape.clean()

if isinstance(self, Part):
if self._dim == 3:
new_shape = Part(new_shape.wrapped)
elif isinstance(self, Sketch):
elif self._dim == 2:
new_shape = Sketch(new_shape.wrapped)
elif isinstance(self, (Wire, Curve)):
elif self._dim == 1:
new_shape = Curve(Compound(new_shape.edges()).wrapped)

return new_shape
Expand All @@ -1718,11 +1719,11 @@ def __and__(self, other: Shape) -> Self:
if new_shape.wrapped is not None and SkipClean.clean:
new_shape = new_shape.clean()

if isinstance(self, Part):
if self._dim == 3:
new_shape = Part(new_shape.wrapped)
elif isinstance(self, Sketch):
elif self._dim == 2:
new_shape = Sketch(new_shape.wrapped)
elif isinstance(self, (Wire, Curve)):
elif self._dim == 1:
new_shape = Curve(Compound(new_shape.edges()).wrapped)

return new_shape
Expand Down Expand Up @@ -2079,9 +2080,9 @@ def _entities(self, topo_type: Shapes) -> list[TopoDS_Shape]:

while explorer.More():
item = explorer.Current()
out[
item.HashCode(HASH_CODE_MAX)
] = item # needed to avoid pseudo-duplicate entities
out[item.HashCode(HASH_CODE_MAX)] = (
item # needed to avoid pseudo-duplicate entities
)
explorer.Next()

return list(out.values())
Expand Down Expand Up @@ -2815,15 +2816,17 @@ def tessellate(
# add triangles
triangles += [
(
t.Value(1) + offset - 1,
t.Value(3) + offset - 1,
t.Value(2) + offset - 1,
)
if reverse
else (
t.Value(1) + offset - 1,
t.Value(2) + offset - 1,
t.Value(3) + offset - 1,
(
t.Value(1) + offset - 1,
t.Value(3) + offset - 1,
t.Value(2) + offset - 1,
)
if reverse
else (
t.Value(1) + offset - 1,
t.Value(2) + offset - 1,
t.Value(3) + offset - 1,
)
)
for t in poly.Triangles()
]
Expand Down Expand Up @@ -3237,12 +3240,10 @@ class Comparable(metaclass=ABCMeta):
"""Abstract base class that requires comparison methods"""

@abstractmethod
def __lt__(self, other: Any) -> bool:
...
def __lt__(self, other: Any) -> bool: ...

@abstractmethod
def __eq__(self, other: Any) -> bool:
...
def __eq__(self, other: Any) -> bool: ...


# This TypeVar allows IDEs to see the type of objects within the ShapeList
Expand All @@ -3253,8 +3254,7 @@ def __eq__(self, other: Any) -> bool:
class ShapePredicate(Protocol):
"""Predicate for shape filters"""

def __call__(self, shape: Shape) -> bool:
...
def __call__(self, shape: Shape) -> bool: ...


class ShapeList(list[T]):
Expand Down Expand Up @@ -3700,12 +3700,10 @@ def __and__(self, other: ShapeList):
return ShapeList(set(self) & set(other))

@overload
def __getitem__(self, key: int) -> T:
...
def __getitem__(self, key: int) -> T: ...

@overload
def __getitem__(self, key: slice) -> ShapeList[T]:
...
def __getitem__(self, key: slice) -> ShapeList[T]: ...

def __getitem__(self, key: Union[int, slice]) -> Union[T, ShapeList[T]]:
"""Return slices of ShapeList as ShapeList"""
Expand Down

0 comments on commit 4498b11

Please sign in to comment.