mirror of https://gitlab.com/pamhyr/pamhyr2
geometry: Factorize points definition.
parent
2a00593332
commit
878c1403b6
|
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
class Point(object):
|
||||
def __init__(self, name:str = ""):
|
||||
super(Point, self).__init__()
|
||||
|
||||
self._name = name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, name):
|
||||
self._name = name
|
||||
|
||||
def point_is_named(self):
|
||||
"""
|
||||
Returns:
|
||||
True if the point is named.
|
||||
"""
|
||||
return self._name.strip() == ""
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from math import dist
|
||||
|
||||
from Model.Geometry.Point import Point
|
||||
|
||||
class PointXY(Point):
|
||||
def __init__(self, x:float = 0.0, y:float = 0.0,
|
||||
name: str = ""):
|
||||
super(PointXY, self).__init__(name = name)
|
||||
|
||||
self._x = float(x)
|
||||
self._y = float(y)
|
||||
|
||||
def __repr__(self):
|
||||
return f"[{self._x}, {self._y}, {self._name}]"
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self._x
|
||||
|
||||
@x.setter
|
||||
def x(self, value):
|
||||
self._x = float(value)
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self._y
|
||||
|
||||
@y.setter
|
||||
def y(self, value):
|
||||
self._y = float(value)
|
||||
|
||||
@staticmethod
|
||||
def distance(p1, p2):
|
||||
"""Euclidean distance between p1 and p2.
|
||||
|
||||
Args:
|
||||
p1: A XY Point
|
||||
p2: A XY Point
|
||||
|
||||
Returns:
|
||||
Euclidean distance between the two points
|
||||
"""
|
||||
return dist((p1.x(), p1.y()), (p2.x(), p2.y()))
|
||||
|
|
@ -3,35 +3,17 @@
|
|||
from math import dist
|
||||
from pandas import isna as pd_is_na
|
||||
|
||||
class PointXYZ:
|
||||
def __init__(self, x: float, y: float, z: float, point_name: str = ""):
|
||||
self.x = float(x)
|
||||
self.y = float(y)
|
||||
self.z = float(z)
|
||||
self.name = point_name
|
||||
self.points = [self.x, self.y, self.z, self.name]
|
||||
from Model.Geometry.PointXY import PointXY
|
||||
|
||||
class PointXYZ(PointXY):
|
||||
def __init__(self, x:float = 0.0, y:float = 0.0, z:float = 0.0,
|
||||
name:str = ""):
|
||||
super(PointXYZ, self).__init__(x=x, y=y, name=name)
|
||||
|
||||
self._z = float(z)
|
||||
|
||||
def __repr__(self):
|
||||
point_xyz_name = f"({self.x}, {self.y},{self.z}, {self.name})"
|
||||
return point_xyz_name
|
||||
|
||||
@property
|
||||
def x(self):
|
||||
return self._x
|
||||
|
||||
@x.setter
|
||||
def x(self, value):
|
||||
self._x = float(value)
|
||||
|
||||
@property
|
||||
def y(self):
|
||||
return self._y
|
||||
|
||||
@y.setter
|
||||
def y(self, value):
|
||||
self._y = float(value)
|
||||
|
||||
# self.points[1] = self._y
|
||||
return f"({self._x}, {self._y}, {self._z}, {self._name})"
|
||||
|
||||
@property
|
||||
def z(self):
|
||||
|
|
@ -41,28 +23,13 @@ class PointXYZ:
|
|||
def z(self, value):
|
||||
self._z = float(value)
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self._name
|
||||
|
||||
@name.setter
|
||||
def name(self, point_name):
|
||||
self._name = point_name
|
||||
|
||||
def point_is_named(self):
|
||||
"""
|
||||
Returns:
|
||||
True if the point is named.
|
||||
"""
|
||||
return len(self.name.strip()) != 0
|
||||
|
||||
@property
|
||||
def is_nan(self):
|
||||
"""
|
||||
Returns:
|
||||
True if at least one coordinate is as np.nan
|
||||
"""
|
||||
return pd_is_na(self.x) or pd_is_na(self.y) or pd_is_na(self.z)
|
||||
return pd_is_na(self.x()) or pd_is_na(self.y()) or pd_is_na(self.z())
|
||||
|
||||
@staticmethod
|
||||
def distance(p1, p2):
|
||||
|
|
@ -75,4 +42,4 @@ class PointXYZ:
|
|||
Returns:
|
||||
Euclidean distance between the two points
|
||||
"""
|
||||
return dist((p1.x, p1.y, p1.z), (p2.x, p2.y, p2.z))
|
||||
return dist((p1.x(), p1.y(), p1.z()), (p2.x(), p2.y(), p2.z()))
|
||||
|
|
|
|||
Loading…
Reference in New Issue