diff options
Diffstat (limited to 'lib/utils/geometry.py')
| -rw-r--r-- | lib/utils/geometry.py | 13 |
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) |
