diff --git a/Cargo.toml b/Cargo.toml index 65d03bf..61520a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,5 +17,4 @@ redis = "0.23.0" ron = "0.8.0" serde = { version = "1.0.163", features = ["derive"] } toml = "0.7.4" -homography = { git = "https://github.com/azazdeaz/homography" } nalgebra = "0.32.2" diff --git a/src/transformer/homography.rs b/src/transformer/homography.rs index 3fe1f95..8f1091f 100644 --- a/src/transformer/homography.rs +++ b/src/transformer/homography.rs @@ -2,8 +2,6 @@ use crate::transformer::Transformers; use crate::point::Point; use crate::worldstate::{WorldState,EDH}; use serde::{Serialize,Deserialize}; -use log::debug; -use nalgebra::Matrix1x3; /// Homography @@ -15,15 +13,7 @@ impl Transformers for Homography { let edh : &EDH = &ws.edh; point_list.iter() - .map(| point | { - let p = Matrix1x3::new(point.x, point.y, 1.0); - let p = p * edh.matrix; - let new_p = Point { x: p[0] / p[2], y: p[1] / p[2], ..*point }; - - debug!("{:?} => {:?}", point, new_p); - - new_p - }) + .map(| point | edh.apply(point)) .collect() } } diff --git a/src/worldstate.rs b/src/worldstate.rs index 8377212..426dc1c 100644 --- a/src/worldstate.rs +++ b/src/worldstate.rs @@ -1,6 +1,7 @@ -use crate::point::Color; -use nalgebra::base::Matrix3; +use crate::point::{Point,Color}; +use nalgebra::base::{Matrix3,Matrix1x3}; use crate::errors::{LJError,LJResult}; +use log::debug; #[derive(Debug, Default)] pub struct EDH { @@ -31,6 +32,16 @@ impl EDH { Ok(EDH { matrix }) } + + pub fn apply(&self, point: &Point) -> Point { + let p = Matrix1x3::new(point.x, point.y, 1.0); + let p = p * self.matrix; + let new_p = Point { x: p[0] / p[2], y: p[1] / p[2], ..*point }; + + debug!("{:?} => {:?}", point, new_p); + + new_p + } } #[derive(Debug, Default)]