aboutsummaryrefslogtreecommitdiff
path: root/src/math/rect.rs
diff options
context:
space:
mode:
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::*;