29 lines
575 B
Rust
29 lines
575 B
Rust
use std::ops::Add;
|
|
|
|
pub mod walker;
|
|
pub mod storage;
|
|
pub mod model;
|
|
|
|
pub const DIM: u32 = 2;
|
|
|
|
#[derive(Clone, Debug)]
|
|
pub struct Position(pub i32, pub i32);
|
|
|
|
impl Position {
|
|
pub fn abs(&self) -> f32 {
|
|
((self.0.pow(2) + self.0.pow(2)) as f32).powf(0.5)
|
|
}
|
|
|
|
pub fn in_direction(direction: u32, value: i32) -> Self {
|
|
if direction == 0 { Position(value, 0) } else { Position(0, value) }
|
|
}
|
|
}
|
|
|
|
impl Add for Position {
|
|
type Output = Position;
|
|
|
|
fn add(self, rhs: Self) -> Self::Output {
|
|
Position(self.0 + rhs.0, self.1 + rhs.1)
|
|
}
|
|
}
|