diff options
| author | George Steel <george.steel@gmail.com> | 2023-01-22 16:37:29 -0500 |
|---|---|---|
| committer | George Steel <george.steel@gmail.com> | 2023-01-22 16:37:29 -0500 |
| commit | 5a1ea7d4c7cf2c831b668a4c444c9d3ebe8b89a9 (patch) | |
| tree | f2157ba438b8bc7fb43fb34e132c154728ef1517 /lib/stitches | |
| parent | c56180fb99b94878fb16ac6d78e0eec63bc58ce0 (diff) | |
add comments and a rounding correction
Diffstat (limited to 'lib/stitches')
| -rw-r--r-- | lib/stitches/running_stitch.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/stitches/running_stitch.py b/lib/stitches/running_stitch.py index 42bb04bc..a2b8251a 100644 --- a/lib/stitches/running_stitch.py +++ b/lib/stitches/running_stitch.py @@ -127,6 +127,7 @@ class AngleInterval(): def cut_segment_with_angle(origin: Point, angle: float, a: Point, b: Point) -> Point: + # Assumes the crossing is inside the segment p = a - origin d = b - a c = Point(math.cos(angle), math.sin(angle)) @@ -137,6 +138,7 @@ def cut_segment_with_angle(origin: Point, angle: float, a: Point, b: Point) -> P def cut_segment_with_circle(origin: Point, r: float, a: Point, b: Point) -> Point: + # assumes that a is inside the circle and b is outside p = a - origin d = b - a # inner products @@ -191,7 +193,10 @@ def stitch_curve_even(points: typing.Sequence[Point], stitch_length: float, tole stitches = [] while i is not None and i < len(points): d = last.distance(points[i]) + distLeft[i] - stitch_len = d / math.ceil(d / stitch_length) if d > 0 else stitch_length + if d == 0: + return stitches + stitch_len = d / math.ceil(d / stitch_length) + 0.000001 # correction for rounding error + stitch, newidx = take_stitch(last, points, i, stitch_len, tolerance) i = newidx if stitch is not None: @@ -201,6 +206,7 @@ def stitch_curve_even(points: typing.Sequence[Point], stitch_length: float, tole def path_to_curves(points: typing.List[Point]): + # split a path at obvious corner points so that they get stitched exactly curves = [] last = 0 for i in range(1, len(points) - 1): |
