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
use crate::{Ellipse, Line, Polygon, Triangle};
use num_traits::Float;
use projective::Projective;
use std::ops::AddAssign;

impl<T> Projective<T> for Line<T>
where
    T: Float,
{
    fn transform(&mut self, matrix: &[&T; 9]) {
        self.s.transform(matrix);
        self.e.transform(matrix);
    }
}

impl<T> Projective<T> for Triangle<T>
where
    T: Float,
{
    fn transform(&mut self, matrix: &[&T; 9]) {
        self.a.transform(matrix);
        self.b.transform(matrix);
        self.c.transform(matrix);
    }
}

impl<T> Projective<T> for Polygon<T>
where
    T: Float,
{
    fn transform(&mut self, matrix: &[&T; 9]) {
        for point in self.points_set.points.iter_mut() {
            point.transform(matrix);
        }
    }
}

impl<T> Projective<T> for Ellipse<T>
where
    T: Float + AddAssign,
{
    #[track_caller]
    fn transform(&mut self, _: &[&T; 9]) {
        panic!("Can't keep the shape after projective transformation");
    }
    fn translate(&mut self, x: &T, y: &T) {
        self.center.x += *x;
        self.center.y += *y;
    }
    fn rotate(&mut self, angle: &T) {
        self.rotate += *angle;
    }
}