aboutsummaryrefslogtreecommitdiff
path: root/src/math/vec2.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/math/vec2.rs')
-rw-r--r--src/math/vec2.rs47
1 files changed, 20 insertions, 27 deletions
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<T: Scalar + Copy> Vec2<T> {
}
// This is sad, but also sadly necessary :/
-impl<T> Into<raylib::ffi::Vector2> for Vec2<T>
-where
- T: Into<f32> + Scalar + Copy,
-{
- fn into(self) -> raylib::ffi::Vector2 {
- raylib::ffi::Vector2 {
- x: self.x.into(),
- y: self.y.into(),
- }
- }
-}
-
impl<T> From<raylib::ffi::Vector2> for Vec2<T>
where
T: From<f32> + Scalar + Copy,
@@ -69,21 +57,9 @@ where
}
}
}
-impl<T: Scalar + Copy> Into<raylib::math::Vector2> for Vec2<T>
-where
- T: Into<f32>,
-{
- fn into(self) -> raylib::math::Vector2 {
- raylib::math::Vector2 {
- x: self.x.into(),
- y: self.y.into(),
- }
- }
-}
-
-impl<T: Scalar + Copy> From<raylib::math::Vector2> for Vec2<T>
+impl<T> From<raylib::math::Vector2> for Vec2<T>
where
- T: From<f32>,
+ T: From<f32> + Scalar + Copy,
{
fn from(v: raylib::math::Vector2) -> Self {
Self {
@@ -93,6 +69,23 @@ where
}
}
+impl<T: Scalar + Copy + ToPrimitive> Into<raylib::ffi::Vector2> for Vec2<T> {
+ 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<T: Scalar + Copy + ToPrimitive> Into<raylib::math::Vector2> for Vec2<T> {
+ 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