Add closed param to kerf()

Allow for non close line segments and handle ends correctly
This commit is contained in:
Florian Festi 2016-10-07 19:21:58 +02:00
parent de7a168377
commit 33681db645
1 changed files with 7 additions and 1 deletions

View File

@ -83,7 +83,7 @@ def mmul(m0, m1):
return result
def kerf(points, k):
def kerf(points, k, closed=True):
"""Outset points by k
Assumes a closed loop of points
"""
@ -94,6 +94,12 @@ def kerf(points, k):
# get normalized orthogonals of both segments
v1 = vorthogonal(normalize(vdiff(points[i - 1], points[i])))
v2 = vorthogonal(normalize(vdiff(points[i], points[(i + 1) % lp])))
if not closed:
if i == 0:
v1 = v2
if i == lp-1:
v2 = v1
# direction the point has to move
d = normalize(vadd(v1, v2))
# cos of the half the angle between the segments