diff options
author | seancarroll <seanc28@gmail.com> | 2021-01-06 21:11:57 -0600 |
---|---|---|
committer | seancarroll <seanc28@gmail.com> | 2021-01-06 21:11:57 -0600 |
commit | c95ff86e2c8fbdd8e0cf6550aadc7ffc676dcc16 (patch) | |
tree | cfc0db9248e14f2ea675cf3b6dc67bf7243d1701 /src/attributes/rectangle.rs | |
parent | 0c8eb45449e578cae1f27e93df3f9cc92ba68219 (diff) | |
download | dotavious-c95ff86e2c8fbdd8e0cf6550aadc7ffc676dcc16.zip |
trying to organize files and use declarations
Diffstat (limited to 'src/attributes/rectangle.rs')
-rw-r--r-- | src/attributes/rectangle.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/attributes/rectangle.rs b/src/attributes/rectangle.rs new file mode 100644 index 0000000..9b36ee2 --- /dev/null +++ b/src/attributes/rectangle.rs @@ -0,0 +1,33 @@ +use crate::attributes::point::Point; +use crate::dot::DotString; +use std::borrow::Cow; + +pub struct Rectangle { + lower_left: Point, + upper_right: Point, +} + +impl<'a> DotString<'a> for Rectangle { + fn dot_string(&self) -> Cow<'a, str> { + format!( + "{:.1},{:.1},{:.1},{:.1}", + self.lower_left.x, self.lower_left.y, self.upper_right.x, self.upper_right.y + ) + .into() + } +} + +#[cfg(test)] +mod test { + use crate::attributes::{Rectangle, Point}; + use crate::DotString; + + #[test] + fn dot_string() { + assert_eq!("0.0,0.0,1.0,1.0", Rectangle { + lower_left: Point::new_2d(0.0, 0.0), + upper_right: Point::new_2d(1.0, 1.0) + }.dot_string()); + } + +}
\ No newline at end of file |