Skip to main content

lib_jsl_geometry/
transformation_traits.rs

1//! Traits describing in-place geometric transformations.
2
3use crate::common::{GeometricPrimitive, GeometryMeasure, IsPlane, IsUnitVector};
4use crate::one_d::IsLine;
5use crate::zero_d::IsPoint;
6
7/// Translates a primitive along a line-defined direction.
8pub trait CanTranslate: GeometricPrimitive + Sized {
9    /// Point type used by the translation line.
10    type Point: IsPoint;
11
12    /// Mutates `self` by applying the translation vector.
13    fn translate<'a, L>(&mut self, translation_vector: &L)
14    where
15        L: IsLine<'a, Self::Point>;
16}
17
18/// Rotates a primitive around a line by an angle in radians.
19pub trait CanRotate: GeometricPrimitive + Sized {
20    /// Point type used by the rotation axis.
21    type Point: IsPoint;
22
23    /// Mutates `self` by rotating about `axis`.
24    fn rotate<'a, L>(&mut self, axis: &L, angle_radians: GeometryMeasure)
25    where
26        L: IsLine<'a, Self::Point>;
27}
28
29/// Shears a primitive parallel to the x axis: every vertex moves by `x ← x + k·y`, where the shear
30/// factor `k` is the length of the supplied line. The line's position and direction are ignored.
31pub trait CanShear: GeometricPrimitive + Sized {
32    /// Point type used by the shear line.
33    type Point: IsPoint;
34
35    /// Mutates `self` by the shear `x ← x + k·y`, with `k = shear_line.length()`.
36    fn shear<'a, L>(&mut self, shear_line: &L)
37    where
38        L: IsLine<'a, Self::Point>;
39}
40
41/// Mirrors a primitive across a compatible plane.
42pub trait CanMirror: GeometricPrimitive + Sized {
43    /// Point type used by the mirror plane.
44    type Point: IsPoint;
45    /// Unit normal type used by the mirror plane.
46    type Normal: IsUnitVector;
47
48    /// Reflects `self` across `mirror_plane`.
49    fn mirror<P>(&mut self, mirror_plane: &P)
50    where
51        P: IsPlane<Point = Self::Point, Normal = Self::Normal>;
52}