Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Workplane.close bug with 3D points #1271

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -2651,8 +2651,7 @@ def polyline(
"""
Create a polyline from a list of points

:param listOfXYTuple: a list of points in Workplane coordinates
:type listOfXYTuple: list of 2-tuples
:param listOfXYTuple: a list of points in Workplane coordinates (2D or 3D)
:param forConstruction: whether or not the edges are used for reference
:type forConstruction: true if the edges are for reference, false if they are for creating geometry
part geometry
Expand Down Expand Up @@ -2688,15 +2687,15 @@ def polyline(

def close(self: T) -> T:
"""
End 2D construction, and attempt to build a closed wire.
End construction, and attempt to build a closed wire.

:return: a CQ object with a completed wire on the stack, if possible.

After 2D drafting with methods such as lineTo, threePointArc,
After 2D (or 3D) drafting with methods such as lineTo, threePointArc,
tangentArcPoint and polyline, it is necessary to convert the edges
produced by these into one or more wires.

When a set of edges is closed, cadQuery assumes it is safe to build
When a set of edges is closed, CadQuery assumes it is safe to build
the group of edges into a wire. This example builds a simple triangular
prism::

Expand All @@ -2713,7 +2712,7 @@ def close(self: T) -> T:
# that is larger than what is considered a numerical error.
# If so; add a line segment between endPoint and startPoint
if endPoint.sub(startPoint).Length > 1e-6:
self.lineTo(self.ctx.firstPoint.x, self.ctx.firstPoint.y)
self.polyline([endPoint, startPoint])

# Need to reset the first point after closing a wire
self.ctx.firstPoint = None
Expand Down
4 changes: 4 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5113,6 +5113,10 @@ def testEdgeWireClose(self):
w2 = w1.close()
self.assertTrue(w1 is w2)

def test_close_3D_points(self):
r = Workplane().polyline([(0, 0, 10), (5, 0, 12), (0, 5, 10),]).close()
assert r.wire().val().Closed()

def testSplitShape(self):
"""
Testing the Shape.split method.
Expand Down