Skip to content

Commit 9c519e6

Browse files
authored
Merge pull request #1271 from lorenzncode/1253-close
Fix Workplane.close bug with 3D points
2 parents 4c2a038 + 24c2496 commit 9c519e6

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cadquery/cq.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2651,8 +2651,7 @@ def polyline(
26512651
"""
26522652
Create a polyline from a list of points
26532653
2654-
:param listOfXYTuple: a list of points in Workplane coordinates
2655-
:type listOfXYTuple: list of 2-tuples
2654+
:param listOfXYTuple: a list of points in Workplane coordinates (2D or 3D)
26562655
:param forConstruction: whether or not the edges are used for reference
26572656
:type forConstruction: true if the edges are for reference, false if they are for creating geometry
26582657
part geometry
@@ -2688,15 +2687,15 @@ def polyline(
26882687

26892688
def close(self: T) -> T:
26902689
"""
2691-
End 2D construction, and attempt to build a closed wire.
2690+
End construction, and attempt to build a closed wire.
26922691
26932692
:return: a CQ object with a completed wire on the stack, if possible.
26942693
2695-
After 2D drafting with methods such as lineTo, threePointArc,
2694+
After 2D (or 3D) drafting with methods such as lineTo, threePointArc,
26962695
tangentArcPoint and polyline, it is necessary to convert the edges
26972696
produced by these into one or more wires.
26982697
2699-
When a set of edges is closed, cadQuery assumes it is safe to build
2698+
When a set of edges is closed, CadQuery assumes it is safe to build
27002699
the group of edges into a wire. This example builds a simple triangular
27012700
prism::
27022701
@@ -2713,7 +2712,7 @@ def close(self: T) -> T:
27132712
# that is larger than what is considered a numerical error.
27142713
# If so; add a line segment between endPoint and startPoint
27152714
if endPoint.sub(startPoint).Length > 1e-6:
2716-
self.lineTo(self.ctx.firstPoint.x, self.ctx.firstPoint.y)
2715+
self.polyline([endPoint, startPoint])
27172716

27182717
# Need to reset the first point after closing a wire
27192718
self.ctx.firstPoint = None

tests/test_cadquery.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,6 +5113,10 @@ def testEdgeWireClose(self):
51135113
w2 = w1.close()
51145114
self.assertTrue(w1 is w2)
51155115

5116+
def test_close_3D_points(self):
5117+
r = Workplane().polyline([(0, 0, 10), (5, 0, 12), (0, 5, 10),]).close()
5118+
assert r.wire().val().Closed()
5119+
51165120
def testSplitShape(self):
51175121
"""
51185122
Testing the Shape.split method.

0 commit comments

Comments
 (0)