FR: Rotate coordinates around other arbitrary coordinates
did:plc:zviscnpwyvj6y32agi5davn5 opened this 18d ago 1 comments
did:plc:zviscnpwyvj6y32agi5davn5 opened 18d ago
This should be available as:
const HexCoord::rotate_around_cw(&self, other: HexCoord, n: usize) -> HexCoordconst HexCoord::rotate_around_ccw(&self, other: HexCoord, n: usize) -> HexCoordconst HexCoord::rotate_cw(&self, n: usize) -> HexCoordconst HexCoord::rotate_ccw(&self, n: usize) -> HexCoord
Rotation around the origin is pretty easy, and just involves transforming the axes of the coordinate being rotated (once per rotation):
CW: (q, r, s) -> (-r, -s, -q)
CCW: (q, r, s) -> (-s, -q, -r)For arbitrary origins (not just (0, 0, 0)) we can center the coordinate before rotation and re-offset it afterwards:
impl HexCoord {
// ...
const fn rotate_around_cw(&self, other: HexCoord, n: usize) -> HexCoord {
(self - other).rotate_cw(n) + other
}
}No activity yet.