Find the nearest point to a given x-coordinate in the plot.
(&self, series_id: ShapeId, x: f64)
| 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 { |
no test coverage detected