From 37ea9e9083282845bdce91370aa77f5da58e2abe Mon Sep 17 00:00:00 2001 From: Pierre-Antoine Rouby Date: Thu, 11 Sep 2025 10:01:18 +0200 Subject: [PATCH] Geometry: Reverte purge algorithme to previous version (modified). --- src/Model/Geometry/PointXYZ.py | 4 +-- src/Model/Geometry/ProfileXYZ.py | 62 ++++++++++++++++---------------- 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/src/Model/Geometry/PointXYZ.py b/src/Model/Geometry/PointXYZ.py index d28d8f31..3cff1109 100644 --- a/src/Model/Geometry/PointXYZ.py +++ b/src/Model/Geometry/PointXYZ.py @@ -373,8 +373,8 @@ class PointXYZ(Point): c = PointXYZ.distance(p3, p1) s = float((a + b + c) / 2) - res = ( - s * abs(s - a) * abs(s - b) * abs(s - c) + res = abs( + s * (s - a) * (s - b) * (s - c) ) ** 0.5 return res diff --git a/src/Model/Geometry/ProfileXYZ.py b/src/Model/Geometry/ProfileXYZ.py index 7ce59562..0fd38131 100644 --- a/src/Model/Geometry/ProfileXYZ.py +++ b/src/Model/Geometry/ProfileXYZ.py @@ -1008,49 +1008,47 @@ class ProfileXYZ(Profile, SQLSubModel): """ Remove points to keep at most np_purge points. """ - if (self.nb_points <= np_purge): + if self.nb_points <= np_purge: return - q_area = queue.PriorityQueue() - deleted = [] + nb_named = 0 # we consider the first and last point as named + area = [] - for ind, point in enumerate(self.points): - if (ind == 0) or (ind == self.nb_points - 1): - continue - - if not point.is_named(): - q_area.put(( + for i, p in enumerate(self.points): + if p.is_named() or i == 0 or i == self.nb_points - 1: + area.append((9999999.999, p)) + nb_named += 1 + else: + area.append(( PointXYZ.areatriangle3d( - self.point(ind - 1), - point, - self.point(ind + 1) + self.point(i-1), + p, + self.point(i+1) ), - ind, point + p )) - while self.nb_points > np_purge and not q_area.empty(): - area, ind, point = q_area.get() + while self.nb_points > max(np_purge, nb_named): + ind, (min_area, p) = min( + enumerate(area), + key=lambda t: t[1][0] + ) - self.delete_points([point]) - deleted.append(point) + p.set_as_deleted() + area.pop(ind) - # Recompute point neighbourhood for i in [ind-1, ind]: - if (i <= 0) or (i >= self.nb_points - 1): - continue + p = self.point(i) - point = self.point(i) - if not point.is_named(): - q_area.put(( - PointXYZ.areatriangle3d( - self.point(i-1), - point, - self.point(i+1) - ), i, point - )) - - self.modified() - return deleted + if p.is_named() or i == 0 or i == self.nb_points - 1: + area[i] = (9999999.999, p) + else: + area[i] = ( + PointXYZ.areatriangle3d( + self.point(i-1), p, self.point(i+1) + ), + p + ) def shift(self, x, y, z): for p in self._points: