summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorLex Neva <lexelby@users.noreply.github.com>2023-04-14 12:51:40 -0400
committerGitHub <noreply@github.com>2023-04-14 18:51:40 +0200
commit20829e613310808118fe417036087c38b3c6e2ab (patch)
tree7d31ed3dcfa9fae7405fa1563c65608ae17342f2 /lib/utils
parentd0162a1a0e670090db43d02651f098008e8d2005 (diff)
new way betterer satin algo (#2178)
* significantly faster length calculation * way betterer satin algo
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/geometry.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py
index 8f34c467..7434ae27 100644
--- a/lib/utils/geometry.py
+++ b/lib/utils/geometry.py
@@ -4,7 +4,9 @@
# Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details.
import math
+import typing
+import numpy
from shapely.geometry import LineString, LinearRing, MultiLineString, Polygon, MultiPolygon, MultiPoint, GeometryCollection
from shapely.geometry import Point as ShapelyPoint
@@ -148,9 +150,9 @@ def cut_path(points, length):
class Point:
- def __init__(self, x: float, y: float):
- self.x = x
- self.y = y
+ def __init__(self, x: typing.Union[float, numpy.float64], y: typing.Union[float, numpy.float64]):
+ self.x = float(x)
+ self.y = float(y)
@classmethod
def from_shapely_point(cls, point):
@@ -203,13 +205,14 @@ class Point:
return "%s(%s,%s)" % (type(self), self.x, self.y)
def length(self):
- return math.sqrt(math.pow(self.x, 2.0) + math.pow(self.y, 2.0))
+ return (self.x ** 2 + self.y ** 2) ** 0.5
def distance(self, other):
return (other - self).length()
def unit(self):
- return self.mul(1.0 / self.length())
+ length = self.length()
+ return self.__class__(self.x / length, self.y / length)
def angle(self):
return math.atan2(self.y, self.x)