From 2242c8f63293ead4b5fe0f299f9937837247bf4b Mon Sep 17 00:00:00 2001 From: jgcodes2020 Date: Mon, 16 Dec 2024 14:29:08 -0500 Subject: [PATCH] matrix multiplication and transforms --- graphene/src/matrix.rs | 44 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/graphene/src/matrix.rs b/graphene/src/matrix.rs index 23677da58b67..1ca9eba5f77e 100644 --- a/graphene/src/matrix.rs +++ b/graphene/src/matrix.rs @@ -4,7 +4,7 @@ use std::fmt; use glib::translate::*; -use crate::{ffi, Matrix, Point3D, Vec3, Vec4}; +use crate::{ffi, Matrix, Point, Point3D, Vec3, Vec4}; impl Matrix { #[doc(alias = "graphene_matrix_init_from_2d")] @@ -236,3 +236,45 @@ mod tests { ); } } + +impl std::ops::Mul for Matrix { + type Output = Matrix; + + fn mul(self, rhs: Matrix) -> Self::Output { + (&self).multiply(&rhs) + } +} + +impl std::ops::Mul for Matrix { + type Output = Vec4; + + fn mul(self, rhs: Vec4) -> Self::Output { + (&self).transform_vec4(&rhs) + } +} + +impl std::ops::Mul for Matrix { + type Output = Vec3; + + fn mul(self, rhs: Vec3) -> Self::Output { + (&self).transform_vec3(&rhs) + } +} + +impl std::ops::Mul for Matrix { + type Output = Point; + + fn mul(self, rhs: Point) -> Self::Output { + (&self).transform_point(&rhs) + } +} + + +impl std::ops::Mul for Matrix { + type Output = Point3D; + + fn mul(self, rhs: Point3D) -> Self::Output { + (&self).transform_point3d(&rhs) + } +} +