aboutsummaryrefslogtreecommitdiff
path: root/src/math/vec2.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/vec2.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/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