From f79037ada7c10a28a882aca0681f796d5e4b6645 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 25 Mar 2026 18:54:23 +0100 Subject: feat(engine): add impls for conversion between array & Vec2/Vec3 --- engine/src/data_types/vector.rs | 44 ++++++++++++++++++++++++++++++++--------- 1 file 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 From<[Value; 2]> for Vec2 +{ + fn from([x, y]: [Value; 2]) -> Self + { + Self { x, y } + } +} + +impl From> for [Value; 2] +{ + fn from(vec: Vec2) -> Self + { + [vec.x, vec.y] + } +} + impl VecN for Vec2 { fn into_array(self) -> [Value; 2] @@ -356,17 +372,11 @@ where } } -impl From for Vec3 -where - Value: Clone, +impl From for Vec3 { - 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 From> for Vec3 } } +impl From<[Value; 3]> for Vec3 +{ + fn from([x, y, z]: [Value; 3]) -> Self + { + Self { x, y, z } + } +} + +impl From> for [Value; 3] +{ + fn from(vec: Vec3) -> Self + { + [vec.x, vec.y, vec.z] + } +} + impl VecN for Vec3 { fn into_array(self) -> [Value; 3] -- cgit v1.2.3-18-g5258