Change default polyline and spline behavior

This commit is contained in:
adam-urbanczyk
2019-06-20 19:40:34 +02:00
parent ef0808f410
commit b77f59167b
2 changed files with 14 additions and 6 deletions

View File

@ -1345,7 +1345,7 @@ class Workplane(CQ):
return self.newObject([self.plane.toWorldCoords(newCenter)]) return self.newObject([self.plane.toWorldCoords(newCenter)])
def spline(self, listOfXYTuple, tangents=None, periodic=False, def spline(self, listOfXYTuple, tangents=None, periodic=False,
forConstruction=False, includeCurrent=True, makeWire=False): forConstruction=False, includeCurrent=False, makeWire=False):
""" """
Create a spline interpolated through the provided points. Create a spline interpolated through the provided points.
@ -1895,7 +1895,8 @@ class Workplane(CQ):
return self.eachpoint(_makePolygon, True) return self.eachpoint(_makePolygon, True)
def polyline(self, listOfXYTuple, forConstruction=False): def polyline(self, listOfXYTuple, forConstruction=False,
includeCurrent=False):
""" """
Create a polyline from a list of points Create a polyline from a list of points
@ -1904,6 +1905,7 @@ class Workplane(CQ):
:param forConstruction: whether or not the edges are used for reference :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 :type forConstruction: true if the edges are for reference, false if they are for creating geometry
part geometry part geometry
:param includeCurrent: use current point as a starting point of the polyline
:return: a new CQ object with a list of edges on the stack :return: a new CQ object with a list of edges on the stack
*NOTE* most commonly, the resulting wire should be closed. *NOTE* most commonly, the resulting wire should be closed.
@ -1912,11 +1914,13 @@ class Workplane(CQ):
# Our list of new edges that will go into a new CQ object # Our list of new edges that will go into a new CQ object
edges = [] edges = []
# The very first startPoint comes from our original object, but not after that if includeCurrent:
startPoint = self._findFromPoint(False) startPoint = self._findFromPoint(False)
else:
startPoint = self.plane.toWorldCoords(listOfXYTuple[0])
# Draw a line for each set of points, starting from the from-point of the original CQ object # Draw a line for each set of points, starting from the from-point of the original CQ object
for curTuple in listOfXYTuple: for curTuple in listOfXYTuple[1:]:
endPoint = self.plane.toWorldCoords(curTuple) endPoint = self.plane.toWorldCoords(curTuple)
edges.append(Edge.makeLine(startPoint, endPoint)) edges.append(Edge.makeLine(startPoint, endPoint))

View File

@ -400,6 +400,7 @@ class TestCadQuery(BaseTest):
Tests the operation of sweeping a wire(s) along a path Tests the operation of sweeping a wire(s) along a path
""" """
pts = [ pts = [
(0, 0),
(0, 1), (0, 1),
(1, 2), (1, 2),
(2, 4) (2, 4)
@ -1062,6 +1063,7 @@ class TestCadQuery(BaseTest):
t = 1.5 t = 1.5
points = [ points = [
(0, 0),
(0, t / 2), (0, t / 2),
(r / 2 - 1.5 * t, r / 2 - t), (r / 2 - 1.5 * t, r / 2 - t),
(s / 2, r / 2 - t), (s / 2, r / 2 - t),
@ -1087,6 +1089,7 @@ class TestCadQuery(BaseTest):
t = 1.5 t = 1.5
points = [ points = [
(0, 0),
(0, t/2), (0, t/2),
(r/2-1.5*t, r/2-t), (r/2-1.5*t, r/2-t),
(s/2, r/2-t), (s/2, r/2-t),
@ -1122,6 +1125,7 @@ class TestCadQuery(BaseTest):
# i just side-stepped it for now # i just side-stepped it for now
pts = [ pts = [
(0, 0),
(0, H / 2.0), (0, H / 2.0),
(W / 2.0, H / 2.0), (W / 2.0, H / 2.0),
(W / 2.0, (H / 2.0 - t)), (W / 2.0, (H / 2.0 - t)),
@ -1907,7 +1911,7 @@ class TestCadQuery(BaseTest):
""" """
decimal_places = 9 decimal_places = 9
pts = [(90,0),(90,30),(30,30),(30,60),(0.0,60)] pts = [(0,0),(90,0),(90,30),(30,30),(30,60),(0.0,60)]
r = Workplane("XY").polyline(pts).close().extrude(10.0) r = Workplane("XY").polyline(pts).close().extrude(10.0)