MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / nearest_point_vertical

Method nearest_point_vertical

src/plot_widget.rs:467–482  ·  view source on GitHub ↗

Find the nearest point to a given y-coordinate in the plot.

(&self, series_id: ShapeId, y: f64)

Source from the content-addressed store, hash-verified

465 for (i, position) in series.positions.iter().enumerate() {
466 let distance = (position[0] - x).powi(2) + (position[1] - y).powi(2);
467 if distance < min_distance {
468 min_distance = distance;
469 nearest_point = Some(PointId {
470 series_id,
471 point_index: i,
472 });
473 }
474 }
475 nearest_point
476 }
477
478 /// Find the nearest point to a given x-coordinate in the plot.
479 pub fn nearest_point_horizontal(&self, series_id: ShapeId, x: f64) -> Option<PointId> {
480 let series = self.series.get(&series_id)?;
481 let mut min_distance = f64::INFINITY;
482 let mut nearest_point = None;
483 for (i, position) in series.positions.iter().enumerate() {
484 let distance = (position[0] - x).abs();
485 if distance < min_distance {

Callers

nothing calls this directly

Calls 1

getMethod · 0.80

Tested by

no test coverage detected