From 38afcc6a2a2a61af26b9fa077e8770b6ffc7f0ac Mon Sep 17 00:00:00 2001 From: Hugo Ledoux Date: Fri, 15 Mar 2024 15:14:40 +0100 Subject: [PATCH] Update the self.cur after each locate() Before the self.cur was updated only for insertion/deletion, but in practice it makes sense (eg when interpolating at several locations) to update the self.cur, otherwise the walk starts from the same potentially far away point each time. --- src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index dbf0ce0..2c639b6 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -1045,7 +1045,7 @@ impl Triangulation { /// Returns, if it exists, the [`Triangle`] containing `(px, py)`. /// If it is direction on a vertex/edge, then one is randomly chosen. - pub fn locate(&self, px: f64, py: f64) -> Result { + pub fn locate(&mut self, px: f64, py: f64) -> Result { if !self.is_init { return Err(StartinError::EmptyTriangulation); } @@ -1053,13 +1053,16 @@ impl Triangulation { let re = self.walk(&p); match re.is_infinite() { true => Err(StartinError::OutsideConvexHull), - false => Ok(re), + false => { + self.cur = re.v[0]; + return Ok(re); + } } } /// Returns closest point (in 2D) to a query point `(x, y)`. /// if `(px, py)` is outside the convex hull then [`StartinError::OutsideConvexHull`] is raised. - pub fn closest_point(&self, px: f64, py: f64) -> Result { + pub fn closest_point(&mut self, px: f64, py: f64) -> Result { let re = self.locate(px, py); if re.is_err() { return Err(re.err().unwrap());