diff --git a/src/conf.rs b/src/conf.rs index 1cc1b3e..815211c 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -46,8 +46,9 @@ pub enum TransformConf { #[serde(rename = "flip_vertical")] FlipV(transformer::FlipVertical), #[serde(rename = "grid")] - Grid(transformer::Grid) - + Grid(transformer::Grid), + #[serde(rename = "homography")] + Homography(transformer::Homography) } @@ -70,7 +71,8 @@ impl Conf { TransformConf::Rotate(r) => Box::new(*r), TransformConf::FlipH(r) => Box::new(*r), TransformConf::FlipV(r) => Box::new(*r), - TransformConf::Grid(r) => Box::new(*r) + TransformConf::Grid(r) => Box::new(*r), + TransformConf::Homography(r) => Box::new(*r), }; v.push(t); } diff --git a/src/transformer.rs b/src/transformer.rs index 6132658..aa25291 100644 --- a/src/transformer.rs +++ b/src/transformer.rs @@ -5,6 +5,7 @@ mod rotate; mod flip_horizontal; mod flip_vertical; mod grid; +mod homography; use crate::point::Point; use crate::worldstate::WorldState; @@ -16,6 +17,7 @@ pub use rotate::Rotate; pub use flip_horizontal::FlipHorizontal; pub use flip_vertical::FlipVertical; pub use grid::Grid; +pub use self::homography::Homography; pub trait Transformers { fn apply( diff --git a/src/transformer/homography.rs b/src/transformer/homography.rs new file mode 100644 index 0000000..bda21c3 --- /dev/null +++ b/src/transformer/homography.rs @@ -0,0 +1,36 @@ +use crate::transformer::Transformers; +use crate::point::Point; +use crate::worldstate::WorldState; +use serde::{Serialize,Deserialize}; +use log::info; +use nalgebra::Matrix3; + +/// Homography + +#[derive(Serialize,Deserialize,Debug,Clone,Copy)] +pub struct Homography {} + +impl Transformers for Homography { + fn apply(&self, point_list: &[Point], ws: &WorldState) -> Vec { + let m = ws.edh.matrix; + + point_list.iter() + .map(| point | { + + // THIS IS CERTAINLY ALL WRONG! NEEDS DEBUGING!!! + + let p = Matrix3::new(point.x, point.y, 1.0, + 1.0, 1.0, 1.0, + 1.0, 1.0, 1.0); + let dot = p.tr_dot(&m); + let new_p = Point { x: point.x / dot, y: point.y / dot, + ..*point + }; + + info!("{:?} => {:?}", point, new_p); + + new_p + }) + .collect() + } +}