Skip to content

Commit

Permalink
Update the self.cur after each locate()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hugoledoux committed Mar 15, 2024
1 parent 3164f5f commit 38afcc6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,21 +1045,24 @@ 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<Triangle, StartinError> {
pub fn locate(&mut self, px: f64, py: f64) -> Result<Triangle, StartinError> {
if !self.is_init {
return Err(StartinError::EmptyTriangulation);
}
let p: [f64; 3] = [px, py, 0.0];
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<usize, StartinError> {
pub fn closest_point(&mut self, px: f64, py: f64) -> Result<usize, StartinError> {
let re = self.locate(px, py);
if re.is_err() {
return Err(re.err().unwrap());
Expand Down

0 comments on commit 38afcc6

Please sign in to comment.