From 4c4b57dc24bc36b3091931c9dcc36f6b1894a017 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Fri, 27 Nov 2020 22:55:00 +0100 Subject: Change to f64 as the preferred floating point number --- src/math/rect.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/math/rect.rs') 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 Surface fo } // This is sad, but also sadly necessary :/ -impl + Scalar + Copy> Into for Rect { - 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 + Scalar + Copy> From for Rect { fn from(r: raylib::ffi::Rectangle) -> Self { Self { @@ -167,16 +158,6 @@ impl + Scalar + Copy> From for Rect { } } } -impl + Scalar + Copy> Into for Rect { - 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 + Scalar + Copy> From for Rect { fn from(r: raylib::math::Rectangle) -> Self { Self { @@ -188,6 +169,27 @@ impl + Scalar + Copy> From for Rect { } } +impl Into for Rect { + 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 Into for Rect { + 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::*; -- cgit v1.2.3-70-g09d2