Skip to content

Commit

Permalink
Added From implementations for arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob2309 committed Aug 18, 2021
1 parent 3efbab1 commit c2834e7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gfx-maths"
version = "0.2.2"
version = "0.2.3"
authors = [ "Robin Quint" ]
edition = "2018"
description = "Implementations for the most essential Graphics Math operations"
Expand Down
17 changes: 17 additions & 0 deletions src/mat4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,20 @@ impl_op_ex!(* |a: &Mat4, b: &Vec3| -> Vec3 {
z: a.values[cr(0, 2)] * b.x + a.values[cr(1, 2)] * b.y + a.values[cr(2, 2)] * b.z,
}
});

impl From<[f32; 16]> for Mat4 {
fn from(d: [f32; 16]) -> Self {
Self{values: d}
}
}

impl From<[[f32; 4]; 4]> for Mat4 {
fn from(d: [[f32; 4]; 4]) -> Self {
Self{values: [
d[0][0], d[0][1], d[0][2], d[0][3],
d[1][0], d[1][1], d[1][2], d[1][3],
d[2][0], d[2][1], d[2][2], d[2][3],
d[3][0], d[3][1], d[3][2], d[3][3],
]}
}
}
6 changes: 6 additions & 0 deletions src/quaternion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,9 @@ impl_op_ex!(- |a: &Quaternion| -> Quaternion {
w: a.w,
}
});

impl From<[f32; 4]> for Quaternion {
fn from(d: [f32; 4]) -> Self {
Self{x: d[0], y: d[1], z: d[2], w: d[3]}
}
}
6 changes: 6 additions & 0 deletions src/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ impl Neg for Vec2 {
}
}

impl From<[f32; 2]> for Vec2 {
fn from(d: [f32; 2]) -> Self {
Self{x: d[0], y: d[1]}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 6 additions & 0 deletions src/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ impl Neg for Vec3 {
}
}

impl From<[f32; 3]> for Vec3 {
fn from(d: [f32; 3]) -> Self {
Self{x: d[0], y: d[1], z: d[2]}
}
}


#[cfg(test)]
mod tests {
Expand Down
6 changes: 6 additions & 0 deletions src/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ impl Neg for Vec4 {
}
}

impl From<[f32; 4]> for Vec4 {
fn from(d: [f32; 4]) -> Self {
Self{x: d[0], y: d[1], z: d[2], w: d[3]}
}
}


#[cfg(test)]
mod tests {
Expand Down

0 comments on commit c2834e7

Please sign in to comment.