summaryrefslogtreecommitdiff
path: root/lib/utils/geometry.py
diff options
context:
space:
mode:
authorLex Neva <github.com@lexneva.name>2023-01-17 21:44:23 -0500
committerLex Neva <github.com@lexneva.name>2023-02-20 15:27:55 -0500
commit847e133f97d570e2967dfa7dcfc16a212dc2bbbc (patch)
treedf2fb20547bea95ad437155a1fac91290a9d07f3 /lib/utils/geometry.py
parente2965e78f03fb41c9a02c92ef120caf038b837ae (diff)
meander fill: more work
Diffstat (limited to 'lib/utils/geometry.py')
-rw-r--r--lib/utils/geometry.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py
index 2903bc56..366a433f 100644
--- a/lib/utils/geometry.py
+++ b/lib/utils/geometry.py
@@ -166,7 +166,7 @@ def _remove_duplicate_coordinates(coords_array):
return coords_array[keepers]
-def smooth_path(path, smoothness=100.0):
+def smooth_path(path, smoothness=1.0):
"""Smooth a path of coordinates.
Arguments:
@@ -178,6 +178,11 @@ def smooth_path(path, smoothness=100.0):
A list of Points.
"""
+ if smoothness == 0:
+ # s of exactly zero seems to indicate a default level of smoothing
+ # in splprep, so we'll just exit instead.
+ return path
+
# splprep blows up on duplicated consecutive points with "Invalid inputs"
coords = _remove_duplicate_coordinates(np.array(path))
num_points = len(coords)
@@ -188,7 +193,7 @@ def smooth_path(path, smoothness=100.0):
# the smoothed path and the original path is equal to the smoothness.
# In practical terms, if smoothness is 1mm, then the smoothed path can be
# up to 1mm away from the original path.
- s = num_points * smoothness ** 2
+ s = num_points * (smoothness ** 2)
# .T transposes the array (for some reason splprep expects
# [[x1, x2, ...], [y1, y2, ...]]
@@ -280,6 +285,9 @@ class Point:
def rotate(self, angle):
return self.__class__(self.x * math.cos(angle) - self.y * math.sin(angle), self.y * math.cos(angle) + self.x * math.sin(angle))
+ def scale(self, x_scale, y_scale):
+ return self.__class__(self.x * x_scale, self.y * y_scale)
+
def as_int(self):
return self.__class__(int(round(self.x)), int(round(self.y)))