From 33681db6453ff9998d3dd402071a81d9f3feed82 Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Fri, 7 Oct 2016 19:21:58 +0200 Subject: [PATCH] Add closed param to kerf() Allow for non close line segments and handle ends correctly --- boxes/vectors.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/boxes/vectors.py b/boxes/vectors.py index d4e02d2..4ec98ce 100644 --- a/boxes/vectors.py +++ b/boxes/vectors.py @@ -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