diff options
Diffstat (limited to 'src/math.rs')
-rw-r--r-- | src/math.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/math.rs b/src/math.rs new file mode 100644 index 0000000..665d4d0 --- /dev/null +++ b/src/math.rs @@ -0,0 +1,49 @@ +use std::fmt; +use rand; +use rand::distributions::{IndependentSample, Range}; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Orientation { + North, + East, + South, + West, +} + +impl fmt::Display for Orientation { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Orientation::*; + + f.write_str( + match self { + &North => "North", + &East => "East", + &South => "South", + &West => "West" + } + ) + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub struct Point { + pub x: u16, + pub y: u16 +} + +impl Point { + pub fn new(x: u16, y: u16) -> Point { + Point { + x: x, + y: y + } + } +} + +pub fn random_point(map_dimension: u16) -> Point { + let mut rng = rand::thread_rng(); + let between = Range::new(0, map_dimension); + let x = between.ind_sample(&mut rng); + let y = between.ind_sample(&mut rng); + Point::new(x, y) +} |