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/vec2.rs | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'src/math/vec2.rs') diff --git a/src/math/vec2.rs b/src/math/vec2.rs index cd38889..d591f1d 100644 --- a/src/math/vec2.rs +++ b/src/math/vec2.rs @@ -1,7 +1,7 @@ use crate::math::Rect; use alga::general::{ClosedAdd, ClosedSub}; use nalgebra::{RealField, Scalar}; -use num_traits::One; +use num_traits::{NumCast, One, ToPrimitive}; use serde::{Deserialize, Serialize}; use std::cmp::Ordering; use std::convert::{From, Into}; @@ -46,18 +46,6 @@ impl Vec2 { } // This is sad, but also sadly necessary :/ -impl Into for Vec2 -where - T: Into + Scalar + Copy, -{ - fn into(self) -> raylib::ffi::Vector2 { - raylib::ffi::Vector2 { - x: self.x.into(), - y: self.y.into(), - } - } -} - impl From for Vec2 where T: From + Scalar + Copy, @@ -69,21 +57,9 @@ where } } } -impl Into for Vec2 -where - T: Into, -{ - fn into(self) -> raylib::math::Vector2 { - raylib::math::Vector2 { - x: self.x.into(), - y: self.y.into(), - } - } -} - -impl From for Vec2 +impl From for Vec2 where - T: From, + T: From + Scalar + Copy, { fn from(v: raylib::math::Vector2) -> Self { Self { @@ -93,6 +69,23 @@ where } } +impl Into for Vec2 { + fn into(self) -> raylib::ffi::Vector2 { + raylib::ffi::Vector2 { + x: NumCast::from(self.x).expect("Unable to cast Vec2 into raylib Vector"), + y: NumCast::from(self.y).expect("Unable to cast Vec2 into raylib Vector"), + } + } +} +impl Into for Vec2 { + fn into(self) -> raylib::math::Vector2 { + raylib::math::Vector2 { + x: NumCast::from(self.x).expect("Unable to cast Vec2 into raylib Vector"), + y: NumCast::from(self.y).expect("Unable to cast Vec2 into raylib Vector"), + } + } +} + // Begin mathematical operators ----------------------------------------------- // Addition -- cgit v1.2.3-70-g09d2