shape-convex 0.0.1

The representation projective transformation
Documentation
  • Coverage
  • 100%
    3 out of 3 items documented1 out of 1 items with examples
  • Size
  • Source code size: 18.58 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.82 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • oovm/shape-rs
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • oovm

Projective Transformations

use projective::Projective;

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

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

#[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));
}