This commit is contained in:
Marc Planard 2023-07-01 17:42:31 +02:00
parent 1d61235e51
commit 2b0a2ce06d
3 changed files with 14 additions and 14 deletions

View File

@ -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"

View File

@ -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()
}
}

View File

@ -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)]