#transformation #graphics

projective

The representation projective transformation

9 unstable releases (3 breaking)

0.3.0 Apr 24, 2022
0.2.5 Mar 28, 2022
0.1.0 Mar 28, 2022
0.0.0 Mar 28, 2022

#1277 in Math

Download history 14/week @ 2023-12-03 12/week @ 2023-12-10 26/week @ 2023-12-17 17/week @ 2023-12-24 1/week @ 2023-12-31 21/week @ 2024-01-07 21/week @ 2024-01-14 9/week @ 2024-01-21 2/week @ 2024-01-28 18/week @ 2024-02-04 29/week @ 2024-02-11 25/week @ 2024-02-18 47/week @ 2024-02-25 30/week @ 2024-03-03 49/week @ 2024-03-10 45/week @ 2024-03-17

172 downloads per month
Used in 15 crates (2 directly)

MPL-2.0 license

13KB
176 lines

Projective Transformations

use projective::Projective;

#[derive(Debug, Copy, Clone, PartialEq)]
pub struct Point(f64, f64);

#[rustfmt::skip]
impl Projective<f64> for Point {
    fn transform(&self, matrix: &[&f64; 9]) -> Self {
        Point(
            matrix[0] * self.0 + matrix[1] * self.1 + matrix[2],
            matrix[3] * self.0 + matrix[4] * self.1 + matrix[5],
        )
    }
}

#[test]
fn test_transform() {
    let p0 = Point(1.0, 2.0);
    assert_eq!(p0.translate(&2.0, &1.0), Point(3.0, 3.0));
    assert_eq!(p0.scale(&2.0, &3.0), Point(2.0, 6.0));
    // floating precision error, implement rotate manually to reduce errors
    assert_eq!(p0.rotate(&std::f64::consts::PI), Point(-0.9999999999999998, -2.0));
}

Dependencies

~155KB