use std::fmt::Display;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Point {
pub x: isize,
pub y: isize,
}
impl Point {
pub const fn new_point(x: isize, y: isize) -> Point {
Point { x, y }
}
}
impl Ord for Point {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.y
.cmp(&other.y)
.then_with(|| self.x.cmp(&other.x))
.reverse()
}
}
impl PartialOrd for Point {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl From<(isize, isize)> for Point {
fn from(p: (isize, isize)) -> Self {
Point { x: p.0, y: p.1 }
}
}
impl Display for Point {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "({}, {})", self.x, self.y)
}
}