From a6b1bbfdcbef0d69640e88216f09a08de7a7e3d8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Tue, 17 Dec 2024 20:39:25 +0100 Subject: [PATCH] Implement `Vector`/`Scalar` multiplication --- experiments/2024-12-09/src/math/vector.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/experiments/2024-12-09/src/math/vector.rs b/experiments/2024-12-09/src/math/vector.rs index 4687721ea..e141e5960 100644 --- a/experiments/2024-12-09/src/math/vector.rs +++ b/experiments/2024-12-09/src/math/vector.rs @@ -39,3 +39,22 @@ where Self { components } } } + +impl ops::Mul for Vector +where + S: Into, +{ + type Output = Self; + + fn mul(self, scalar: S) -> Self::Output { + let scalar = scalar.into(); + + let components = self + .components + .into_iter_fixed() + .map(|v| v * scalar) + .collect(); + + Self { components } + } +}