mirror of
https://github.com/gumyr/build123d.git
synced 2025-12-07 03:01:18 -08:00
Merge pull request #476 from MatthiasJ1/chamfer_performance
Improve chamfer performance on m1
This commit is contained in:
commit
047d9cc53f
1 changed files with 21 additions and 16 deletions
|
|
@ -2104,6 +2104,7 @@ class Shape(NodeMixin):
|
||||||
def _entities_from(
|
def _entities_from(
|
||||||
self, child_type: Shapes, parent_type: Shapes
|
self, child_type: Shapes, parent_type: Shapes
|
||||||
) -> Dict[Shape, list[Shape]]:
|
) -> Dict[Shape, list[Shape]]:
|
||||||
|
"""This function is very slow on M1 macs and is currently unused"""
|
||||||
res = TopTools_IndexedDataMapOfShapeListOfShape()
|
res = TopTools_IndexedDataMapOfShapeListOfShape()
|
||||||
|
|
||||||
TopExp.MapShapesAndAncestors_s(
|
TopExp.MapShapesAndAncestors_s(
|
||||||
|
|
@ -5596,28 +5597,33 @@ class Face(Shape):
|
||||||
Face: face with a chamfered corner(s)
|
Face: face with a chamfered corner(s)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
reference_edge = edge
|
||||||
|
del edge
|
||||||
|
|
||||||
chamfer_builder = BRepFilletAPI_MakeFillet2d(self.wrapped)
|
chamfer_builder = BRepFilletAPI_MakeFillet2d(self.wrapped)
|
||||||
edge_map = self._entities_from(Vertex.__name__, Edge.__name__)
|
|
||||||
|
|
||||||
for vertex in vertices:
|
vertex_edge_map = TopTools_IndexedDataMapOfShapeListOfShape()
|
||||||
edges = edge_map[vertex]
|
TopExp.MapShapesAndAncestors_s(self.wrapped, ta.TopAbs_VERTEX, ta.TopAbs_EDGE, vertex_edge_map)
|
||||||
if len(edges) < 2:
|
|
||||||
raise ValueError("Cannot chamfer at this location")
|
|
||||||
|
|
||||||
if edge:
|
for v in vertices:
|
||||||
if edge not in edges:
|
edges = vertex_edge_map.FindFromKey(v.wrapped)
|
||||||
|
|
||||||
|
# Index or iterator access to OCP.TopTools.TopTools_ListOfShape is slow on M1 macs
|
||||||
|
# Using First() and Last() to omit
|
||||||
|
edges = [edges.First(), edges.Last()]
|
||||||
|
|
||||||
|
# Need to wrap in b3d objects for comparison to work
|
||||||
|
# ref.wrapped != edge.wrapped but ref == edge
|
||||||
|
edges = [Shape.cast(e) for e in edges]
|
||||||
|
|
||||||
|
if reference_edge:
|
||||||
|
if reference_edge not in edges:
|
||||||
raise ValueError("One or more vertices are not part of edge")
|
raise ValueError("One or more vertices are not part of edge")
|
||||||
|
edge1 = reference_edge
|
||||||
edge1 = edge
|
edge2 = [x for x in edges if x != reference_edge][0]
|
||||||
edge2 = [x for x in edges if x != edge][0]
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
edge1, edge2 = edges
|
edge1, edge2 = edges
|
||||||
|
|
||||||
if edge in edges:
|
|
||||||
pass
|
|
||||||
|
|
||||||
chamfer_builder.AddChamfer(
|
chamfer_builder.AddChamfer(
|
||||||
TopoDS.Edge_s(edge1.wrapped),
|
TopoDS.Edge_s(edge1.wrapped),
|
||||||
TopoDS.Edge_s(edge2.wrapped),
|
TopoDS.Edge_s(edge2.wrapped),
|
||||||
|
|
@ -5626,7 +5632,6 @@ class Face(Shape):
|
||||||
)
|
)
|
||||||
|
|
||||||
chamfer_builder.Build()
|
chamfer_builder.Build()
|
||||||
|
|
||||||
return self.__class__(chamfer_builder.Shape()).fix()
|
return self.__class__(chamfer_builder.Shape()).fix()
|
||||||
|
|
||||||
def is_coplanar(self, plane: Plane) -> bool:
|
def is_coplanar(self, plane: Plane) -> bool:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue