Skip to content

Commit 8e23195

Browse files
Implement close for wires
1 parent 650b2ff commit 8e23195

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

cadquery/occ_impl/shapes.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,8 +1404,7 @@ def close(self) -> Union["Edge", "Wire"]:
14041404
rv: Union[Wire, Edge]
14051405

14061406
if not self.IsClosed():
1407-
e = Edge.makeLine(self.endPoint(), self.startPoint())
1408-
rv = Wire.assembleEdges((self, e))
1407+
rv = Wire.assembleEdges((self,)).close()
14091408
else:
14101409
rv = self
14111410

@@ -1673,6 +1672,19 @@ def _geomAdaptorH(self) -> Tuple[BRepAdaptor_CompCurve, BRepAdaptor_HCompCurve]:
16731672

16741673
return curve, BRepAdaptor_HCompCurve(curve)
16751674

1675+
def close(self) -> "Wire":
1676+
"""
1677+
Close a Wire
1678+
"""
1679+
1680+
if not self.IsClosed():
1681+
e = Edge.makeLine(self.endPoint(), self.startPoint())
1682+
rv = Wire.combine((self, e))[0]
1683+
else:
1684+
rv = self
1685+
1686+
return rv
1687+
16761688
@classmethod
16771689
def combine(
16781690
cls: Type["Wire"], listOfWires: Iterable[Union["Wire", Edge]], tol: float = 1e-9

tests/test_cadquery.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4476,7 +4476,7 @@ def testParametricSurface(self):
44764476
self.assertTrue(r2.solids().val().isValid())
44774477
self.assertEqual(r2.solids().size(), 2)
44784478

4479-
def testEdgeClose(self):
4479+
def testEdgeWireClose(self):
44804480

44814481
# test with edge
44824482
e0 = Edge.makeThreePointArc(Vector(0, 0, 0), Vector(1, 1, 0), Vector(0, 2, 0))
@@ -4491,6 +4491,12 @@ def testEdgeClose(self):
44914491
self.assertTrue(e2.IsClosed())
44924492
self.assertEqual(type(e1), type(e2))
44934493

4494+
# test with already closed WIRE
4495+
w1 = Wire.makeCircle(1, Vector(), Vector(0, 0, 1))
4496+
self.assertTrue(w1.IsClosed())
4497+
w2 = w1.close()
4498+
self.assertTrue(w1 is w2)
4499+
44944500
def testSplitShape(self):
44954501
"""
44964502
Testing the Shape.split method.

0 commit comments

Comments
 (0)