diff options
Diffstat (limited to 'src/math')
| -rw-r--r-- | src/math/rect.rs | 2 | ||||
| -rw-r--r-- | src/math/vec2.rs | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/math/rect.rs b/src/math/rect.rs index 50c1cb0..b571644 100644 --- a/src/math/rect.rs +++ b/src/math/rect.rs @@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize}; use std::ops::{Add, AddAssign}; /// Represents a Rectangle with the value type T. -#[derive(Copy, Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] pub struct Rect<T: Scalar + Copy> { /// The x coordinate, or leftmost coordinate of the Rect. pub x: T, diff --git a/src/math/vec2.rs b/src/math/vec2.rs index d591f1d..b9e3215 100644 --- a/src/math/vec2.rs +++ b/src/math/vec2.rs @@ -7,6 +7,7 @@ use std::cmp::Ordering; use std::convert::{From, Into}; use std::ops::{Add, AddAssign, Div, Mul, MulAssign, Neg, Sub, SubAssign}; use std::{fmt, mem}; +use nalgebra::Point2; #[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Eq, Hash)] pub struct Vec2<T: Scalar + Copy> { @@ -45,6 +46,18 @@ impl<T: Scalar + Copy> Vec2<T> { } } +impl<T: Scalar + Copy> Into<Point2<T>> for Vec2<T> { + fn into(self) -> Point2<T> { + Point2::new(self.x, self.y) + } +} + +impl<T: Scalar + Copy> From<Point2<T>> for Vec2<T> { + fn from(v: Point2<T>) -> Self { + Self::new(v.x, v.y) + } +} + // This is sad, but also sadly necessary :/ impl<T> From<raylib::ffi::Vector2> for Vec2<T> where |
