Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
Merge 679eb21 into c4df65c
Browse files Browse the repository at this point in the history
  • Loading branch information
gntech committed Apr 26, 2018
2 parents c4df65c + 679eb21 commit aae5e24
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,14 @@ def close(self):
s = Workplane().lineTo(1,0).lineTo(1,1).close().extrude(0.2)
"""
self.lineTo(self.ctx.firstPoint.x, self.ctx.firstPoint.y)
endPoint = self._findFromPoint(True)
startPoint = self.ctx.firstPoint

# Check if there is a distance between startPoint and endPoint
# 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)

# Need to reset the first point after closing a wire
self.ctx.firstPoint=None
Expand Down
22 changes: 22 additions & 0 deletions tests/TestCadQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,3 +1605,25 @@ def testExtrude(self):
self.assertTupleAlmostEquals(delta.toTuple(),
(0.,0.,2.*h),
decimal_places)

def testClose(self):
# Close without endPoint and startPoint coincide.
# Create a half-circle
a = Workplane(Plane.XY()).sagittaArc((10, 0), 2).close().extrude(2)

# Close when endPoint and startPoint coincide.
# Create a double half-circle
b = Workplane(Plane.XY()).sagittaArc((10, 0), 2).sagittaArc((0, 0), 2).close().extrude(2)

# The b shape shall have twice the volume of the a shape.
self.assertAlmostEqual(a.val().wrapped.Volume * 2.0, b.val().wrapped.Volume)

# Testcase 3 from issue #238
thickness = 3
length = 10
width = 5

obj = Workplane('XY', origin=(0, 0, -thickness / 2)) \
.moveTo(length / 2, 0).threePointArc((0, width / 2), (-length / 2, 0)) \
.threePointArc((0, -width / 2), (length / 2, 0)) \
.close().extrude(thickness)

0 comments on commit aae5e24

Please sign in to comment.