microcad_lang/value/
matrix.rs

1// Copyright © 2025 The µcad authors <info@ucad.xyz>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4//! Matrix value type
5
6use crate::ty::*;
7
8/// Matrix type
9#[derive(Debug, Clone, PartialEq)]
10pub enum Matrix {
11    /// 2x2 matrix.
12    Matrix2(microcad_core::Mat2),
13    /// 3x3 matrix.
14    Matrix3(microcad_core::Mat3),
15    /// 4x4 matrix.
16    Matrix4(microcad_core::Mat4),
17}
18
19impl Ty for Matrix {
20    fn ty(&self) -> Type {
21        match self {
22            Matrix::Matrix2(_) => Type::Matrix(MatrixType::new(2, 2)),
23            Matrix::Matrix3(_) => Type::Matrix(MatrixType::new(3, 3)),
24            Matrix::Matrix4(_) => Type::Matrix(MatrixType::new(4, 4)),
25        }
26    }
27}
28
29impl std::fmt::Display for Matrix {
30    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
31        match self {
32            Matrix::Matrix2(matrix2) => write!(f, "{matrix2:?}"),
33            Matrix::Matrix3(matrix3) => write!(f, "{matrix3:?}"),
34            Matrix::Matrix4(matrix4) => write!(f, "{matrix4:?}"),
35        }
36    }
37}