logo
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
use super::*;
use crate::Distance;

impl<T> Distance<T, Self> for Point<T>
where
    T: Clone + Real,
{
    fn distance_to(&self, other: &Self) -> T {
        let dx = self.x.clone() - other.x.clone();
        let dy = self.y.clone() - other.y.clone();
        dx * dx + dy * dy
    }
}

impl<T> Distance<T, Self> for Point3D<T>
where
    T: Clone + Real,
{
    fn distance_to(&self, other: &Self) -> T {
        let dx = self.x.clone() - other.x.clone();
        let dy = self.y.clone() - other.y.clone();
        let dz = self.z.clone() - other.z.clone();
        dx * dx + dy * dy + dz * dz
    }
}

impl<T> Projective<T> for Point<T>
where
    T: Real,
{
    fn transform(&mut self, matrix: &[&T; 9]) {
        self.x = self.x.mul(*matrix[0]) + self.y.mul(*matrix[1]) + *matrix[2];
        self.y = self.x.mul(*matrix[3]) + self.y.mul(*matrix[4]) + *matrix[5];
    }
}