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

Commit

Permalink
Merge e23ccdc into 7a9317a
Browse files Browse the repository at this point in the history
  • Loading branch information
gntech committed Apr 29, 2018
2 parents 7a9317a + e23ccdc commit 81353ee
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cadquery/cq.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,10 +1321,8 @@ def threePointArc(self, point1, point2, forConstruction=False):
"""

startPoint = self._findFromPoint(False)
if not isinstance(point1, Vector):
point1 = self.plane.toWorldCoords(point1)
if not isinstance(point2, Vector):
point2 = self.plane.toWorldCoords(point2)
point1 = self.plane.toWorldCoords(point1)
point2 = self.plane.toWorldCoords(point2)

arc = Edge.makeThreePointArc(startPoint, point1, point2)

Expand Down Expand Up @@ -1800,7 +1798,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
33 changes: 33 additions & 0 deletions tests/TestCadQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1605,3 +1605,36 @@ 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.0
length = 10.0
width = 5.0

obj1 = 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)

os_x = 8.0 # Offset in X
os_y = -19.5 # Offset in Y

obj2 = Workplane('YZ', origin=(os_x, os_y, -thickness / 2)) \
.moveTo(os_x + length / 2, os_y).sagittaArc((os_x -length / 2, os_y), width / 2) \
.sagittaArc((os_x + length / 2, os_y), width / 2) \
.close().extrude(thickness)

# The obj1 shape shall have the same volume as the obj2 shape.
self.assertAlmostEqual(obj1.val().wrapped.Volume, obj2.val().wrapped.Volume)

0 comments on commit 81353ee

Please sign in to comment.