Skip to content

Instantly share code, notes, and snippets.

@MikuroXina
Last active October 19, 2023 18:09
Show Gist options
  • Select an option

  • Save MikuroXina/d41df91a17c319e9f42064f8aef32b1e to your computer and use it in GitHub Desktop.

Select an option

Save MikuroXina/d41df91a17c319e9f42064f8aef32b1e to your computer and use it in GitHub Desktop.
The chebyshev point implementation for calculating manhattan distance quickly.
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
struct ChebyshevPoint(i64, i64);
impl ChebyshevPoint {
fn from_manhattan(x: i64, y: i64) -> Self {
Self(x - y, x + y)
}
fn manhattan_dist(self, other: Self) -> u64 {
self.0.abs_diff(other.0).max(self.1.abs_diff(other.1))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment