From cbf9206631fdff0053051b6317d1b6f70618e554 Mon Sep 17 00:00:00 2001 From: Fletcher Porter Date: Tue, 17 Dec 2024 17:15:02 -0800 Subject: [PATCH] Provide feature parity for `Projection` with Godot The only missing feature was indexing, which I did in a type-safe manner. This was a part of the December 2024 Mini Hackathon. --- godot-core/src/builtin/projection.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/godot-core/src/builtin/projection.rs b/godot-core/src/builtin/projection.rs index ace645f0a..46bc74509 100644 --- a/godot-core/src/builtin/projection.rs +++ b/godot-core/src/builtin/projection.rs @@ -447,6 +447,7 @@ impl Projection { /// added to the first and second values of the final column respectively. /// /// _Godot equivalent: `Projection.jitter_offseted()`_ + #[doc(alias = "jitter_offseted")] #[must_use] pub fn jitter_offset(&self, offset: Vector2) -> Self { Self::from_cols( @@ -502,6 +503,19 @@ impl Mul for Projection { } } +impl std::ops::Index for Projection { + type Output = Vector4; + + fn index(&self, index: Vector4Axis) -> &Self::Output { + match index { + Vector4Axis::X => &self.cols[0], + Vector4Axis::Y => &self.cols[1], + Vector4Axis::Z => &self.cols[2], + Vector4Axis::W => &self.cols[3], + } + } +} + impl ApproxEq for Projection { fn approx_eq(&self, other: &Self) -> bool { for i in 0..4 {