diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 19:19:06 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 19:19:06 +0200 |
commit | 36b72bfef7b7b8dea94546d11704ec529091bce1 (patch) | |
tree | 4a8cdae81db3ab44aa946046bbfbb87f96c360c5 /src/math.rs | |
parent | 27682d0ab246af8d0375853fdea44c38de2c2db4 (diff) |
Split into smaller portions
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) +} |