aboutsummaryrefslogtreecommitdiff
path: root/src/math/rect.rs
diff options
context:
space:
mode:
authorMax Pernklau2020-11-29 21:28:39 +0100
committerGitHub2020-11-29 21:28:39 +0100
commit4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87 (patch)
tree010339f867d90c2c6293ddd16c4151ec220c7b8e /src/math/rect.rs
parent4d3ee44eb4892bd454a1289f7fed308f82ec6a3b (diff)
parent90db142588e1b78250dc9b266bae359cf9e22721 (diff)
downloadgraf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.tar.gz
graf_karto-4f2eab931bed0ec86c6136e365ad3a1b3b8c4e87.zip
Merge branch 'master' into wall-join
Diffstat (limited to 'src/math/rect.rs')
-rw-r--r--src/math/rect.rs42
1 files changed, 22 insertions, 20 deletions
diff --git a/src/math/rect.rs b/src/math/rect.rs
index 5f4e5f5..5603642 100644
--- a/src/math/rect.rs
+++ b/src/math/rect.rs
@@ -2,6 +2,7 @@ use super::{LineSegment, Polygon, Surface, Vec2};
//use alga::general::{Additive, Identity};
use nalgebra::{ClosedAdd, ClosedSub, RealField, Scalar};
use num_traits::identities::Zero;
+use num_traits::{NumCast, ToPrimitive};
use serde::{Deserialize, Serialize};
use std::ops::{Add, AddAssign};
@@ -147,16 +148,6 @@ impl<T: Scalar + Copy + PartialOrd + ClosedAdd + ClosedSub + Zero> Surface<T> fo
}
// This is sad, but also sadly necessary :/
-impl<T: Into<f32> + Scalar + Copy> Into<raylib::ffi::Rectangle> for Rect<T> {
- fn into(self) -> raylib::ffi::Rectangle {
- raylib::ffi::Rectangle {
- x: self.x.into(),
- y: self.y.into(),
- width: self.w.into(),
- height: self.h.into(),
- }
- }
-}
impl<T: From<f32> + Scalar + Copy> From<raylib::ffi::Rectangle> for Rect<T> {
fn from(r: raylib::ffi::Rectangle) -> Self {
Self {
@@ -167,16 +158,6 @@ impl<T: From<f32> + Scalar + Copy> From<raylib::ffi::Rectangle> for Rect<T> {
}
}
}
-impl<T: Into<f32> + Scalar + Copy> Into<raylib::math::Rectangle> for Rect<T> {
- fn into(self) -> raylib::math::Rectangle {
- raylib::math::Rectangle {
- x: self.x.into(),
- y: self.y.into(),
- width: self.w.into(),
- height: self.h.into(),
- }
- }
-}
impl<T: From<f32> + Scalar + Copy> From<raylib::math::Rectangle> for Rect<T> {
fn from(r: raylib::math::Rectangle) -> Self {
Self {
@@ -188,6 +169,27 @@ impl<T: From<f32> + Scalar + Copy> From<raylib::math::Rectangle> for Rect<T> {
}
}
+impl<T: Scalar + Copy + ToPrimitive> Into<raylib::math::Rectangle> for Rect<T> {
+ fn into(self) -> raylib::math::Rectangle {
+ raylib::math::Rectangle {
+ x: NumCast::from(self.x).expect("Unable to cast Rect into raylib Rect"),
+ y: NumCast::from(self.y).expect("Unable to cast Rect into raylib Rect"),
+ width: NumCast::from(self.w).expect("Unable to cast Rect into raylib Rect"),
+ height: NumCast::from(self.h).expect("Unable to cast Rect into raylib Rect"),
+ }
+ }
+}
+impl<T: Scalar + Copy + ToPrimitive> Into<raylib::ffi::Rectangle> for Rect<T> {
+ fn into(self) -> raylib::ffi::Rectangle {
+ raylib::ffi::Rectangle {
+ x: NumCast::from(self.x).expect("Unable to cast Rect into raylib Rect"),
+ y: NumCast::from(self.y).expect("Unable to cast Rect into raylib Rect"),
+ width: NumCast::from(self.w).expect("Unable to cast Rect into raylib Rect"),
+ height: NumCast::from(self.h).expect("Unable to cast Rect into raylib Rect"),
+ }
+ }
+}
+
#[cfg(test)]
mod test {
use super::*;