use std::ops::{Add, Sub};
use super::RoomXY;
use crate::constants::Direction;
impl RoomXY {
#[inline]
#[track_caller]
pub fn offset(&mut self, x: i8, y: i8) {
*self = *self + (x, y);
}
}
impl Add<(i8, i8)> for RoomXY {
type Output = RoomXY;
#[inline]
#[track_caller]
fn add(self, (x, y): (i8, i8)) -> Self {
self.checked_add((x, y)).unwrap()
}
}
impl Add<Direction> for RoomXY {
type Output = RoomXY;
#[inline]
#[track_caller]
fn add(self, direction: Direction) -> Self {
self.checked_add_direction(direction).unwrap()
}
}
impl Sub<(i8, i8)> for RoomXY {
type Output = RoomXY;
#[inline]
#[track_caller]
fn sub(self, (x, y): (i8, i8)) -> Self {
self.checked_add((-x, -y)).unwrap()
}
}
impl Sub<Direction> for RoomXY {
type Output = RoomXY;
#[inline]
fn sub(self, direction: Direction) -> Self {
self.checked_add_direction(-direction).unwrap()
}
}
impl Sub<RoomXY> for RoomXY {
type Output = (i8, i8);
#[inline]
fn sub(self, other: RoomXY) -> (i8, i8) {
let dx = self.x.u8() as i8 - other.x.u8() as i8;
let dy = self.y.u8() as i8 - other.y.u8() as i8;
(dx, dy)
}
}