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