aboutsummaryrefslogtreecommitdiff
path: root/src/math/rect.rs
diff options
context:
space:
mode:
authorArne Dußin2021-01-11 12:10:16 +0100
committerArne Dußin2021-01-11 12:10:16 +0100
commitec071d5bc677101c0168b5fb3065f2d928234ed9 (patch)
tree963ae90a6563c1f08d8e52078afd62db32e182f0 /src/math/rect.rs
parentad1e79a517ce64eda7b06bb1567d3df070813dca (diff)
downloadgraf_karto-ec071d5bc677101c0168b5fb3065f2d928234ed9.tar.gz
graf_karto-ec071d5bc677101c0168b5fb3065f2d928234ed9.zip
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.
Diffstat (limited to 'src/math/rect.rs')
-rw-r--r--src/math/rect.rs17
1 files changed, 17 insertions, 0 deletions
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<T: Scalar + Copy + ToPrimitive> Into<raylib::ffi::Rectangle> for Rect<T> {
}
}
+/* 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<T: Scalar + Copy + ToPrimitive, P: Scalar + Copy> Into<Polygon<P>> for Rect<T>
+where
+ T: Into<P> + Add<Output = T>,
+{
+ fn into(self) -> Polygon<P> {
+ 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::*;