summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/src/size.rs10
-rw-r--r--core/src/vector.rs23
2 files changed, 33 insertions, 0 deletions
diff --git a/core/src/size.rs b/core/src/size.rs
index 7c481935..060f8fa5 100644
--- a/core/src/size.rs
+++ b/core/src/size.rs
@@ -1,3 +1,4 @@
+use super::vector::Vector;
use std::f32;
/// An amount of space in 2 dimensions.
@@ -57,6 +58,15 @@ impl From<[u16; 2]> for Size {
}
}
+impl From<Vector<f32>> for Size {
+ fn from(vector: Vector<f32>) -> Self {
+ Size {
+ width: vector.x,
+ height: vector.y,
+ }
+ }
+}
+
impl From<Size> for [f32; 2] {
fn from(size: Size) -> [f32; 2] {
[size.width, size.height]
diff --git a/core/src/vector.rs b/core/src/vector.rs
index def3f8c0..fd00b5ba 100644
--- a/core/src/vector.rs
+++ b/core/src/vector.rs
@@ -1,3 +1,5 @@
+use super::size::Size;
+
/// A 2D vector.
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Vector<T = f32> {
@@ -65,3 +67,24 @@ where
}
}
}
+
+impl<T> From<[T; 2]> for Vector<T> {
+ fn from([x, y]: [T; 2]) -> Self {
+ Self::new(x, y)
+ }
+}
+
+impl<T> From<Vector<T>> for [T; 2]
+where
+ T: Copy,
+{
+ fn from(other: Vector<T>) -> Self {
+ [other.x, other.y]
+ }
+}
+
+impl From<Size> for Vector<f32> {
+ fn from(size: Size) -> Self {
+ Vector::new(size.width, size.height)
+ }
+}