diff options
| author | HampusM <hampus@hampusmat.com> | 2026-03-25 18:54:23 +0100 |
|---|---|---|
| committer | HampusM <hampus@hampusmat.com> | 2026-03-25 18:54:23 +0100 |
| commit | f79037ada7c10a28a882aca0681f796d5e4b6645 (patch) | |
| tree | ea67d2dc6c5ccba04e7ec6ac4218d47f000311f0 | |
| parent | 5f37b4dbc86d7b48f446a792189430b7d8e2272f (diff) | |
feat(engine): add impls for conversion between array & Vec2/Vec3
| -rw-r--r-- | engine/src/data_types/vector.rs | 44 |
1 files changed, 35 insertions, 9 deletions
diff --git a/engine/src/data_types/vector.rs b/engine/src/data_types/vector.rs index 1a4e49e..adbdfff 100644 --- a/engine/src/data_types/vector.rs +++ b/engine/src/data_types/vector.rs @@ -103,6 +103,22 @@ where } } +impl<Value> From<[Value; 2]> for Vec2<Value> +{ + fn from([x, y]: [Value; 2]) -> Self + { + Self { x, y } + } +} + +impl<Value> From<Vec2<Value>> for [Value; 2] +{ + fn from(vec: Vec2<Value>) -> Self + { + [vec.x, vec.y] + } +} + impl<Value> VecN<Value, 2> for Vec2<Value> { fn into_array(self) -> [Value; 2] @@ -356,17 +372,11 @@ where } } -impl<Value> From<Value> for Vec3<Value> -where - Value: Clone, +impl From<f32> for Vec3<f32> { - fn from(value: Value) -> Self + fn from(value: f32) -> Self { - Self { - x: value.clone(), - y: value.clone(), - z: value, - } + Self { x: value, y: value, z: value } } } @@ -382,6 +392,22 @@ impl<Value> From<Color<Value>> for Vec3<Value> } } +impl<Value> From<[Value; 3]> for Vec3<Value> +{ + fn from([x, y, z]: [Value; 3]) -> Self + { + Self { x, y, z } + } +} + +impl<Value> From<Vec3<Value>> for [Value; 3] +{ + fn from(vec: Vec3<Value>) -> Self + { + [vec.x, vec.y, vec.z] + } +} + impl<Value> VecN<Value, 3> for Vec3<Value> { fn into_array(self) -> [Value; 3] |
