screeps/local/position/
pair_utils.rs1use super::Position;
3use crate::local::RoomXY;
4
5macro_rules! int_pair_from_position {
6 ($($num_type:ty),+) => {$(
7 impl From<Position> for ($num_type, $num_type) {
8 #[inline]
9 fn from(pos: Position) -> Self {
10 (u8::from(pos.x()) as $num_type, u8::from(pos.y()) as $num_type)
11 }
12 }
13 )+}
14}
15
16int_pair_from_position!(u8, u16, u32, u64, i8, i16, i32, i64);
17
18impl Position {
19 #[inline]
22 pub fn coords(&self) -> (u8, u8) {
23 (self.x().into(), self.y().into())
24 }
25
26 #[inline]
29 pub fn coords_signed(&self) -> (i8, i8) {
30 (u8::from(self.x()) as i8, u8::from(self.y()) as i8)
31 }
32}
33
34impl From<Position> for RoomXY {
35 #[inline]
36 fn from(pos: Position) -> RoomXY {
37 RoomXY {
38 x: pos.x(),
39 y: pos.y(),
40 }
41 }
42}