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" ron = "0.8.0"
serde = { version = "1.0.163", features = ["derive"] } serde = { version = "1.0.163", features = ["derive"] }
toml = "0.7.4" toml = "0.7.4"
homography = { git = "https://github.com/azazdeaz/homography" }
nalgebra = "0.32.2" nalgebra = "0.32.2"

View File

@ -2,8 +2,6 @@ use crate::transformer::Transformers;
use crate::point::Point; use crate::point::Point;
use crate::worldstate::{WorldState,EDH}; use crate::worldstate::{WorldState,EDH};
use serde::{Serialize,Deserialize}; use serde::{Serialize,Deserialize};
use log::debug;
use nalgebra::Matrix1x3;
/// Homography /// Homography
@ -15,15 +13,7 @@ impl Transformers for Homography {
let edh : &EDH = &ws.edh; let edh : &EDH = &ws.edh;
point_list.iter() point_list.iter()
.map(| point | { .map(| point | edh.apply(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
})
.collect() .collect()
} }
} }

View File

@ -1,6 +1,7 @@
use crate::point::Color; use crate::point::{Point,Color};
use nalgebra::base::Matrix3; use nalgebra::base::{Matrix3,Matrix1x3};
use crate::errors::{LJError,LJResult}; use crate::errors::{LJError,LJResult};
use log::debug;
#[derive(Debug, Default)] #[derive(Debug, Default)]
pub struct EDH { pub struct EDH {
@ -31,6 +32,16 @@ impl EDH {
Ok(EDH { matrix }) 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)] #[derive(Debug, Default)]