From ec071d5bc677101c0168b5fb3065f2d928234ed9 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Mon, 11 Jan 2021 12:10:16 +0100 Subject: Rect rooms are now normal polygon rooms in data Before there was an extra data type for rectangular rooms. This is now changed, with the rectangle tool remaining, to create these often required rooms faster, but the data type is just a normal polygon that is generated from a rect to reduce redundancy. --- src/math/rect.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/math/rect.rs') diff --git a/src/math/rect.rs b/src/math/rect.rs index b019ad5..adb608b 100644 --- a/src/math/rect.rs +++ b/src/math/rect.rs @@ -229,6 +229,23 @@ impl Into for Rect { } } +/* Convert the rectangle into a polygon. This is the same as creating a convex hull from the corner + * points, but is a specific case. + */ +impl Into> for Rect +where + T: Into

+ Add, +{ + fn into(self) -> Polygon

{ + Polygon::from_vertices(vec![ + Vec2::new(self.x.into(), self.y.into()), + Vec2::new(self.x.into(), (self.y + self.h).into()), + Vec2::new((self.x + self.w).into(), (self.y + self.h).into()), + Vec2::new((self.x + self.w).into(), self.y.into()), + ]) + } +} + #[cfg(test)] mod test { use super::*; -- cgit v1.2.3-70-g09d2