1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2023, 2025 lacklustr@protonmail.com https://github.com/eadf
// This file is part of vector-traits.
use crate::prelude::*;
use std::{fmt::Debug, ops::Mul};
/// A simple trait wrapper of a Matrix3
pub trait Affine2D: Sync + Send + Clone + Debug + Sized + Mul<Output = Self> {
type Vector2: GenericVector2;
/// Transform a 2D vector as a point (applies translation)
#[must_use]
fn transform_point2(&self, point: Self::Vector2) -> Self::Vector2;
/// Transform a 2D vector as a vector (ignores translation)
#[must_use]
fn transform_vector2(&self, vec: Self::Vector2) -> Self::Vector2;
/// Create a matrix from a column major array
#[must_use]
fn from_cols_array(array: &[<Self::Vector2 as HasXY>::Scalar; 9]) -> Self;
/// Create an identity matrix
#[must_use]
fn identity() -> Self;
/// Safely get inverse or None if not invertible
#[must_use]
fn try_inverse(&self) -> Option<Self>;
}
/// A simple trait wrapper of a Matrix4
pub trait Affine3D: Sync + Send + Clone + Debug + Sized + Mul<Output = Self> {
type Vector3: GenericVector3;
/// Transform a 3D vector as a point (applies translation)
#[must_use]
fn transform_point3(&self, point: Self::Vector3) -> Self::Vector3;
/// Transform a 3D vector as a vector (ignores translation)
#[must_use]
fn transform_vector3(&self, vec: Self::Vector3) -> Self::Vector3;
/// Create a matrix from a column major array
#[must_use]
fn from_cols_array(array: &[<Self::Vector3 as HasXY>::Scalar; 16]) -> Self;
/// Create an identity matrix
#[must_use]
fn identity() -> Self;
/// Creates a transform that transforms coordinates from the specified source plane
/// to the XY plane (where Z = 0).
///
/// This is useful when you have 2D data stored in an arbitrary plane and want to
/// work with it in standard XY coordinates.
///
/// # Arguments
///
/// * `source_plane` - The plane in which the original 2D coordinates are defined.
/// - XY: Leaves coordinates unchanged (identity matrix)
/// - XZ: Swaps Y and Z axes (maps XZ plane to XY plane)
/// - YZ: Swaps X and Z axes (maps YZ plane to XY plane)
///
/// # Returns
///
/// The transform that will convert points from the source plane to XY.
///
fn from_plane_to_xy(source_plane: Plane) -> Self;
fn from_scale(scale: Self::Vector3) -> Self;
fn from_translation(translation: Self::Vector3) -> Self;
/// Safely get inverse or None if not invertible
#[must_use]
fn try_inverse(&self) -> Option<Self>;
}