Fixed Edge.filter_by not respecting location Issue #1083

This commit is contained in:
gumyr 2025-09-01 13:45:50 -04:00
parent a52f112375
commit cc7b3ffa82
2 changed files with 22 additions and 1 deletions

View file

@ -2531,9 +2531,9 @@ class ShapeList(list[T]):
def plane_parallel_predicate(plane: Plane, tolerance: float):
plane_axis = Axis(plane.origin, plane.z_dir)
plane_xyz = plane.z_dir.wrapped.XYZ()
def pred(shape: Shape):
if shape.is_planar_face:
assert shape.wrapped is not None and isinstance(
shape.wrapped, TopoDS_Face
@ -2550,6 +2550,9 @@ class ShapeList(list[T]):
if isinstance(shape.wrapped, TopoDS_Wire):
return all(pred(e) for e in shape.edges())
if isinstance(shape.wrapped, TopoDS_Edge):
plane_xyz = (
plane * Location(shape.location).inverse()
).z_dir.wrapped.XYZ()
for curve in shape.wrapped.TShape().Curves():
if curve.IsCurve3D():
return ShapeAnalysis_Curve.IsPlanar_s(

View file

@ -118,6 +118,24 @@ class TestShapeList(unittest.TestCase):
self.assertEqual(len(box.edges().filter_by(Axis.X)), 4)
self.assertEqual(len(box.vertices().filter_by(Axis.X)), 0)
def test_filter_by_plane(self):
c1 = Cylinder(1, 3)
c2 = Cylinder(1, 3, rotation=(90, 0, 0))
sel1 = c1.faces().filter_by(Plane.XY)
sel2 = c1.edges().filter_by(Plane.XY)
sel3 = c2.faces().filter_by(Plane.XZ)
sel4 = c2.edges().filter_by(Plane.XZ)
sel5 = c1.wires().filter_by(Plane.XY)
sel6 = c2.wires().filter_by(Plane.XZ)
self.assertEqual(len(sel1), 2)
self.assertEqual(len(sel2), 2)
self.assertEqual(len(sel3), 2)
self.assertEqual(len(sel4), 2)
self.assertEqual(len(sel5), 2)
self.assertEqual(len(sel6), 2)
def test_filter_by_callable_predicate(self):
boxes = [Solid.make_box(1, 1, 1) for _ in range(3)]
boxes[0].label = "A"