Commit 870cba50 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

Geometry: Fix width_approximation when rg and rd is missing.

Showing with 20 additions and 2 deletions
+20 -2
......@@ -19,6 +19,7 @@
import logging
import numpy as np
from typing import List
from functools import reduce
from tools import timer
......@@ -324,6 +325,19 @@ class ProfileXYZ(Profile, SQLSubModel):
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):
"""Add a new PointXYZ to profile.
......@@ -454,8 +468,12 @@ class ProfileXYZ(Profile, SQLSubModel):
return list(map(lambda s: s - constant, station))
def width_approximation(self):
rg = self.get_point_by_name("rg")
rd = self.get_point_by_name("rd")
if self.has_standard_named_points():
rg = self.get_point_by_name("rg")
rd = self.get_point_by_name("rd")
else:
rg = self.points[0]
rd = self.points[-1]
return abs(rg.dist(rd))
......
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