mirror of
https://gitlab.com/pamhyr/pamhyr2.git
synced 2026-10-30 03:20:41 +01:00
geometry: Guidelines computation.
This commit is contained in:
1 parent
8782056b1c
commit
cd69d56c74
4 files changed
+172
-40
No files matched your search
@@ -91,3 +91,13 @@ class Profile(object):
|
||||
@profile_type.setter
|
||||
def profile_type(self, value: str):
|
||||
self._profile_type = value
|
||||
|
||||
|
||||
def named_points(self):
|
||||
"""List of named point
|
||||
|
||||
Returns:
|
||||
The list of named point
|
||||
"""
|
||||
return [point for point in self._points
|
||||
if point.point_is_named()]
|
||||
+103
-3
@@ -7,6 +7,8 @@ from typing import List
|
||||
from copy import deepcopy
|
||||
from operator import itemgetter
|
||||
|
||||
from tools import flatten
|
||||
|
||||
from Model.Geometry.Profile import Profile
|
||||
from Model.Geometry.ProfileXYZ import ProfileXYZ
|
||||
|
||||
@@ -17,6 +19,9 @@ class Reach:
|
||||
self._parent = parent
|
||||
self._profiles: List[Profile] = []
|
||||
|
||||
self._guidelines_is_valid = False
|
||||
self._guidelines = {}
|
||||
|
||||
# Copy/Paste
|
||||
self.__list_copied_profiles = []
|
||||
|
||||
@@ -138,7 +143,16 @@ class Reach:
|
||||
reverse=is_reversed
|
||||
)
|
||||
|
||||
def z_min(self):
|
||||
def get_x(self):
|
||||
return [profile.x() for profile in self.profiles]
|
||||
|
||||
def get_y(self):
|
||||
return [profile.y() for profile in self.profiles]
|
||||
|
||||
def get_z(self):
|
||||
return [profile.z() for profile in self.profiles]
|
||||
|
||||
def get_z_min(self):
|
||||
"""List of z min for each profile
|
||||
|
||||
Returns:
|
||||
@@ -146,7 +160,7 @@ class Reach:
|
||||
"""
|
||||
return [profile.z_min() for profile in self._data.profiles]
|
||||
|
||||
def z_max(self):
|
||||
def get_z_max(self):
|
||||
"""List of z max for each profile
|
||||
|
||||
Returns:
|
||||
@@ -154,7 +168,7 @@ class Reach:
|
||||
"""
|
||||
return [profile.z_max() for profile in self._data.profiles]
|
||||
|
||||
def kp(self):
|
||||
def get_kp(self):
|
||||
"""List of profiles kp
|
||||
|
||||
Returns:
|
||||
@@ -162,6 +176,92 @@ class Reach:
|
||||
"""
|
||||
return [profile.kp for profile in self._data.profiles]
|
||||
|
||||
##############
|
||||
# GUIDELINES #
|
||||
##############
|
||||
|
||||
def _compute_guidelines_cache(self, guide_set, named_points):
|
||||
# Reset guide lines cache
|
||||
self._guidelines = {}
|
||||
|
||||
# Make a list of point for each guideline
|
||||
for guide in guide_set:
|
||||
self._guidelines[guide] = flatten(
|
||||
map(
|
||||
lambda l: list(
|
||||
# Filter point with name (we assume we have
|
||||
# only one point by profile)
|
||||
filter(
|
||||
lambda p: p.name == guide,
|
||||
l
|
||||
)
|
||||
),
|
||||
named_points
|
||||
)
|
||||
)
|
||||
|
||||
def compute_guidelines(self):
|
||||
"""Compute reach guideline and check if is valid for all profiles
|
||||
|
||||
Returns:
|
||||
True if all guide line is valid
|
||||
"""
|
||||
# Get all point contains into a guideline
|
||||
named_points = [profile.named_points() for profile in self._profiles]
|
||||
points_name = list(
|
||||
map(
|
||||
lambda lst: list(map(lambda p: p.name, lst)),
|
||||
named_points
|
||||
)
|
||||
)
|
||||
|
||||
# Get all guide line name
|
||||
guide_set = reduce(
|
||||
lambda acc, x: set(x).union(acc),
|
||||
points_name
|
||||
)
|
||||
|
||||
# All guide line is valid
|
||||
is_ok = reduce(
|
||||
bool.__and__,
|
||||
map(
|
||||
lambda l: len(set(l).symmetric_difference(guide_set)) == 0,
|
||||
points_name
|
||||
)
|
||||
)
|
||||
self._guidelines_is_valid = is_ok
|
||||
|
||||
# Compute guideline and put data in cache
|
||||
self._compute_guidelines_cache(guide_set, named_points)
|
||||
|
||||
return is_ok
|
||||
|
||||
def _map_guidelines_points(self, func):
|
||||
return list(
|
||||
# Map for each guideline
|
||||
map(
|
||||
lambda k: list(
|
||||
# Apply function FUNC on each point of guideline
|
||||
map(
|
||||
func,
|
||||
self._guidelines[k],
|
||||
)
|
||||
),
|
||||
self._guidelines
|
||||
)
|
||||
)
|
||||
|
||||
def get_guidelines_x(self):
|
||||
return self._map_guidelines_points(lambda p: p.x)
|
||||
|
||||
def get_guidelines_y(self):
|
||||
return self._map_guidelines_points(lambda p: p.y)
|
||||
|
||||
def get_guidelines_z(self):
|
||||
return self._map_guidelines_points(lambda p: p.z)
|
||||
|
||||
# Sort
|
||||
|
||||
def sort_ascending(self):
|
||||
"""Sort profiles by increasing KP
|
||||
|
||||
|
||||
Reference in new issue
Block a user