Add conversion functions to Size and Vector
This commit is contained in:
parent
d3b04bf892
commit
9090fa6a22
2 changed files with 33 additions and 0 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue