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

Method nearest_point_horizontal

src/plot_widget.rs:449–464  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

447 /// Get an iterator over the series ids in the plot.
448 pub fn series_ids(&self) -> Vec<ShapeId> {
449 self.series.keys().copied().collect()
450 }
451 /// Get the position of a point in the plot.
452 pub fn point_position(&self, point_id: PointId) -> Option<[f64; 2]> {
453 self.series
454 .get(&point_id.series_id)?
455 .positions
456 .get(point_id.point_index)
457 .copied()
458 }
459
460 /// Find the nearest point to a given position in the plot.
461 pub fn nearest_point(&self, series_id: ShapeId, x: f64, y: f64) -> Option<PointId> {
462 let series = self.series.get(&series_id)?;
463 let mut min_distance = f64::INFINITY;
464 let mut nearest_point = None;
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 {

Callers 3

update_plotFunction · 0.80
updateMethod · 0.80
updateFunction · 0.80

Calls 1

getMethod · 0.80

Tested by

no test coverage detected