1use std::cmp::Ordering;
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct GridPoint {
5 pub x: f64,
7 pub y: f64,
9}
10
11impl GridPoint {
12 pub const fn new(x: f64, y: f64) -> Self {
14 Self { x, y }
15 }
16
17 pub const fn into_xy(self) -> (f64, f64) {
19 (self.x, self.y)
20 }
21}
22
23impl PartialOrd for GridPoint {
24 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
25 match self.y.partial_cmp(&other.y) {
26 None => self.x.partial_cmp(&other.x),
27 Some(ordering) => Some(ordering),
28 }
29 }
30}
31
32impl From<(f64, f64)> for GridPoint {
33 fn from(value: (f64, f64)) -> Self {
34 Self::new(value.0, value.1)
35 }
36}
37
38impl From<GridPoint> for (f64, f64) {
39 fn from(value: GridPoint) -> Self {
40 value.into_xy()
41 }
42}