Merge pull request #583 from Limeth/master

Add conversion functions to Size and Vector
This commit is contained in:
Héctor Ramón 2020-10-29 16:03:10 +01:00 committed by GitHub
commit 820abdc98e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -1,3 +1,4 @@
use crate::Vector;
use std::f32;
/// An amount of space in 2 dimensions.
@ -57,8 +58,23 @@ 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]
}
}
impl From<Size> for Vector<f32> {
fn from(size: Size) -> Self {
Vector::new(size.width, size.height)
}
}

View File

@ -65,3 +65,18 @@ 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]
}
}