Last active
October 19, 2023 18:09
-
-
Save MikuroXina/d41df91a17c319e9f42064f8aef32b1e to your computer and use it in GitHub Desktop.
The chebyshev point implementation for calculating manhattan distance quickly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[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