geometry: Continue to adapt to new model scheme.

This commit is contained in:
Pierre-Antoine Rouby committed 2023-04-14 15:10:41 +02:00
1 parent af4832a134
commit 2708e81ebb
7 files changed
+228 -152

No files matched your search

+4 -3
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from math import dist
from pandas import isna as pd_is_na
from pandas import isna
from Model.Geometry.Point import Point
@@ -41,13 +41,14 @@ class PointXYZ(Point):
def z(self, value):
self._z = float(value)
@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 (isna(self.x) or
isna(self.y) or
isna(self.z))
@staticmethod
def distance(p1, p2):
+109 -20
View File
@@ -48,6 +48,36 @@ class ProfileXYZ(Profile):
self.nb_points(), self._kp, self._name]
)
def x(self):
return [point.x for point in self._points]
def y(self):
return [point.y for point in self._points]
def z(self):
return [point.z for point in self._points]
def names(self):
return [point.name for point in self._points]
def x_max(self):
return max(self.filter_isnan(self.x))
def x_min(self):
return min(self.filter_isnan(self.x))
def y_max(self):
return max(self.filter_isnan(self.y))
def y_min(self):
return min(self.filter_isnan(self.y))
def z_max(self):
return max(self.filter_isnan(self.z))
def z_min(self):
return min(self.filter_isnan(self.z))
def import_points(self, list_points: list):
"""Import a list of points to profile
@@ -148,32 +178,91 @@ class ProfileXYZ(Profile):
"""
return [x for x in lst if not np.isnan(x)]
def x(self):
return [point.x for point in self._points]
def get_station(self) -> np.ndarray:
"""Projection of the points of the profile on a plane.
def y(self):
return [point.y for point in self._points]
Args:
profile: The profile
def z(self):
return [point.z for point in self._points]
Returns:
Projection of the points of the profile on a plane.
"""
if self.nb_points >= 3:
first_named_point = None
index_first_named_point = None
last_named_point = None
def names(self):
return [point.name for point in self._points]
for index, point in enumerate(self.points):
if point.point_is_named():
index_first_named_point = index
first_named_point = point
break
def x_max(self):
return max(self.filter_isnan(self.x))
for point in self._points[::-1]:
if point.point_is_named():
last_named_point = point
break
def x_min(self):
return min(self.filter_isnan(self.x))
station = []
constant = 0.0
def y_max(self):
return max(self.filter_isnan(self.y))
if ((first_named_point is not None) and
(last_named_point is not None)):
if (first_named_point != last_named_point and
first_named_point.x != last_named_point.x):
vector = Vector1d(first_named_point, last_named_point)
normalized_direction_vec = vector.normalized_direction_vector()
else:
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
def y_min(self):
return min(self.filter_isnan(self.y))
for point in self._points:
xi = point.x - first_named_point.x
yi = point.y - first_named_point.y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
def z_max(self):
return max(self.filter_isnan(self.z))
station = np.array(station)
def z_min(self):
return min(self.filter_isnan(self.z))
constant = station[index_first_named_point]
elif first_named_point is None:
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
for point in self._points:
xi = point.x - _first_point_not_nan(profile).x
yi = point.y - _first_point_not_nan(profile).y
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
station = np.array(station)
index_profile_z_min = np.where(np.array(self.z) == self.z_min)[0][0]
constant = station[index_profile_z_min]
return (station - constant)
else:
return np.array(np.nan)
def _first_point_not_nan(self):
first_point = self._points[0]
for point in self.points:
if not point.is_nan():
first_point = point
break
return first_point_not_nan
def _last_point_not_nan(self):
last_point = self._points[-1]
for point in self._points[::-1]:
if not point.is_nan():
last_point = point
break
return last_point
+2 -2
View File
@@ -123,10 +123,10 @@ class Reach:
else:
raise TypeError(f"{list_index} is instance of unexpected type '{type(list_index)}'")
def _sort(self, is_reversed: bool = False):
def sort(self, is_reversed: bool = False):
self._profiles = sorted(
self._profiles,
key=lambda profile: profile.kp(),
key=lambda profile: profile.kp,
reverse=is_reversed
)
+19 -18
View File
@@ -44,54 +44,55 @@ def get_station(profile: ProfileXYZ) -> np.ndarray:
last_named_point = point
break
station = [] # abscisse en travers
constant = 0.0 # constante pour décaler l'origine de l'ascisse en travers caluculée.
station = []
constant = 0.0
if (first_named_point is not None) and (last_named_point is not None):
if first_named_point != last_named_point and first_named_point.x != last_named_point.x:
if ((first_named_point is not None) and
(last_named_point is not None)):
if (first_named_point != last_named_point and
first_named_point.x != last_named_point.x):
vector = Vector1d(first_named_point, last_named_point)
normalized_direction_vec = vector.normalized_direction_vector()
else:
vector = Vector1d(_first_point_not_nan(profile), _last_point_not_nan(profile))
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
for point in profile.points:
xi = point.x - first_named_point.x
yi = point.y - first_named_point.y
station_i = normalized_direction_vec[0] * xi + normalized_direction_vec[1] * yi
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
station = np.array(station)
constant = station[index_first_named_point] # pour placer l'origine au premier point nomme.
constant = station[index_first_named_point]
elif first_named_point is None:
vector = Vector1d(_first_point_not_nan(profile), _last_point_not_nan(profile))
vector = Vector1d(_first_point_not_nan(profile),
_last_point_not_nan(profile))
normalized_direction_vec = vector.normalized_direction_vector()
for point in profile.points:
xi = point.x - _first_point_not_nan(profile).x
yi = point.y - _first_point_not_nan(profile).y
station_i = normalized_direction_vec[0] * xi + normalized_direction_vec[1] * yi
station_i = (normalized_direction_vec[0] * xi +
normalized_direction_vec[1] * yi)
station.append(station_i)
station = np.array(station)
index_profile_z_min = np.where(np.array(profile.z) == profile.z_min)[0][0]
constant = station[index_profile_z_min] # pour placer l'origine au fond ie à la cote minimale
# z_min du profil.
station = station - constant
constant = station[index_profile_z_min]
return station
return (station - constant)
else:
return np.array(np.nan)
def _point_is_nan(point: PointXYZ):
return pd.isna(point.x) or pd.isna(point.y) or pd.isna(point.z)
def _first_point_not_nan(profile: ProfileXYZ):
first_point_not_nan = profile.points[0]
for point in profile.points:
if not _point_is_nan(point):
if not point.is_nan():
first_point_not_nan = point
break
@@ -101,7 +102,7 @@ def _last_point_not_nan(profile: ProfileXYZ):
last_point = profile.points[-1]
for point in profile.points[::-1]:
if not _point_is_nan(point):
if not point.is_nan():
last_point = point
break