Commit 878c1403 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

geometry: Factorize points definition.

Showing with 77 additions and 43 deletions
+77 -43
# -*- 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() == ""
# -*- 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
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
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)
@x.setter
def x(self, value):
self._x = float(value)
self._z = float(z)
@property
def y(self):
return self._y
@y.setter
def y(self, value):
self._y = float(value)
# self.points[1] = self._y
def __repr__(self):
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()))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment