Skip to content

Commit

Permalink
matrix multiplication and transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Dec 16, 2024
1 parent bda9a99 commit 2242c8f
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion graphene/src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -236,3 +236,45 @@ mod tests {
);
}
}

impl std::ops::Mul<Matrix> for Matrix {
type Output = Matrix;

fn mul(self, rhs: Matrix) -> Self::Output {
(&self).multiply(&rhs)
}
}

impl std::ops::Mul<Vec4> for Matrix {
type Output = Vec4;

fn mul(self, rhs: Vec4) -> Self::Output {
(&self).transform_vec4(&rhs)
}
}

impl std::ops::Mul<Vec3> for Matrix {
type Output = Vec3;

fn mul(self, rhs: Vec3) -> Self::Output {
(&self).transform_vec3(&rhs)
}
}

impl std::ops::Mul<Point> for Matrix {
type Output = Point;

fn mul(self, rhs: Point) -> Self::Output {
(&self).transform_point(&rhs)
}
}


impl std::ops::Mul<Point3D> for Matrix {
type Output = Point3D;

fn mul(self, rhs: Point3D) -> Self::Output {
(&self).transform_point3d(&rhs)
}
}

0 comments on commit 2242c8f

Please sign in to comment.