shape_core/traits/
projection.rs

1use crate::{Ellipse, Line, Polygon, Triangle};
2use num_traits::Float;
3use projective::Projective;
4use std::ops::AddAssign;
5
6impl<T> Projective<T> for Line<T>
7where
8    T: Float,
9{
10    fn transform(&mut self, matrix: &[&T; 9]) {
11        self.s.transform(matrix);
12        self.e.transform(matrix);
13    }
14}
15
16impl<T> Projective<T> for Triangle<T>
17where
18    T: Float,
19{
20    fn transform(&mut self, matrix: &[&T; 9]) {
21        self.a.transform(matrix);
22        self.b.transform(matrix);
23        self.c.transform(matrix);
24    }
25}
26
27impl<T> Projective<T> for Polygon<T>
28where
29    T: Float,
30{
31    fn transform(&mut self, matrix: &[&T; 9]) {
32        for point in self.points_set.points.iter_mut() {
33            point.transform(matrix);
34        }
35    }
36}
37
38impl<T> Projective<T> for Ellipse<T>
39where
40    T: Float + AddAssign,
41{
42    #[track_caller]
43    fn transform(&mut self, _: &[&T; 9]) {
44        panic!("Can't keep the shape after projective transformation");
45    }
46    fn translate(&mut self, x: &T, y: &T) {
47        self.center.x += *x;
48        self.center.y += *y;
49    }
50    fn rotate(&mut self, angle: &T) {
51        self.rotate += *angle;
52    }
53}