Geometry: Fix width_approximation when rg and rd is missing.

setup.py
Pierre-Antoine Rouby 2024-01-17 11:02:44 +01:00
parent c5df959210
commit 870cba5005
1 changed files with 20 additions and 2 deletions

View File

@ -19,6 +19,7 @@
import logging import logging
import numpy as np import numpy as np
from typing import List from typing import List
from functools import reduce
from tools import timer from tools import timer
@ -324,6 +325,19 @@ class ProfileXYZ(Profile, SQLSubModel):
f"for profile ({self.id}) kp = {self.kp}" f"for profile ({self.id}) kp = {self.kp}"
) )
def has_standard_named_points(self):
l, r = reduce(
lambda acc, n: (
(acc[0] | (n == "rg")),
(acc[1] | (n == "rd"))
),
map(lambda p: p.name.lower().strip(),
self.points),
(False, False)
)
return l & r
def add(self): def add(self):
"""Add a new PointXYZ to profile. """Add a new PointXYZ to profile.
@ -454,8 +468,12 @@ class ProfileXYZ(Profile, SQLSubModel):
return list(map(lambda s: s - constant, station)) return list(map(lambda s: s - constant, station))
def width_approximation(self): def width_approximation(self):
if self.has_standard_named_points():
rg = self.get_point_by_name("rg") rg = self.get_point_by_name("rg")
rd = self.get_point_by_name("rd") rd = self.get_point_by_name("rd")
else:
rg = self.points[0]
rd = self.points[-1]
return abs(rg.dist(rd)) return abs(rg.dist(rd))