first draft for transformers
This commit is contained in:
parent
d9450e903f
commit
de26c1c793
25
src/main.rs
25
src/main.rs
@ -6,6 +6,7 @@ mod redis_ctrl;
|
|||||||
mod conf;
|
mod conf;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod point;
|
mod point;
|
||||||
|
mod modifier;
|
||||||
|
|
||||||
use helios_dac::{
|
use helios_dac::{
|
||||||
self,
|
self,
|
||||||
@ -20,8 +21,9 @@ use redis_ctrl::{RedisCtrl,Order};
|
|||||||
use conf::Conf;
|
use conf::Conf;
|
||||||
use errors::{LJError,LJResult};
|
use errors::{LJError,LJResult};
|
||||||
use point::Point;
|
use point::Point;
|
||||||
|
use modifier::{Transformers,Translate};
|
||||||
|
|
||||||
const CENTER : (u16,u16) = (2000, 2000);
|
const CENTER : (f32,f32) = (2000.0, 2000.0);
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
match run_all() {
|
match run_all() {
|
||||||
@ -84,8 +86,9 @@ fn get_next_frame(
|
|||||||
) -> LJResult<Frame> {
|
) -> LJResult<Frame> {
|
||||||
|
|
||||||
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
let line = rs.get(&format!("/pl/{}/0", config.laser_id))?;
|
||||||
let line: Vec<helios_dac::Point> = line.iter().map(tuple_to_point).collect();
|
let line: Vec<Point> = line.into_iter().map(| tpl | tpl.into()).collect();
|
||||||
|
let line = Translate::new(CENTER.0, CENTER.1).apply(&line);
|
||||||
|
|
||||||
let mut line2 = vec![];
|
let mut line2 = vec![];
|
||||||
while line2.len() < 48 {
|
while line2.len() < 48 {
|
||||||
for p in &line {
|
for p in &line {
|
||||||
@ -94,19 +97,7 @@ fn get_next_frame(
|
|||||||
}
|
}
|
||||||
|
|
||||||
println!("{:?}", line2);
|
println!("{:?}", line2);
|
||||||
|
|
||||||
|
let line2 : Vec<helios_dac::Point> = line2.into_iter().map(| p | p.into()).collect();
|
||||||
Ok(Frame::new(speed, line2))
|
Ok(Frame::new(speed, line2))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tuple_to_point(tpl: &(f32, f32, u32)) -> helios_dac::Point {
|
|
||||||
let mut point : Point = (*tpl).into();
|
|
||||||
|
|
||||||
point.x = (CENTER.0 + point.x as u16 * 2).into();
|
|
||||||
point.y = (CENTER.1 + point.y as u16 * 2).into();
|
|
||||||
|
|
||||||
if point.x >= 4096.0 || point.y >= 4096.0 {
|
|
||||||
println!("WARN: coordinate out of range: {:?}", point);
|
|
||||||
}
|
|
||||||
|
|
||||||
point.into()
|
|
||||||
}
|
|
||||||
|
29
src/modifier.rs
Normal file
29
src/modifier.rs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
use crate::point::Point;
|
||||||
|
|
||||||
|
pub trait Transformers {
|
||||||
|
fn apply(&self, point_list: &Vec<Point>) -> Vec<Point>;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug,Clone,Copy)]
|
||||||
|
pub struct Translate {
|
||||||
|
x: f32,
|
||||||
|
y: f32
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Translate {
|
||||||
|
pub fn new(x: f32, y: f32) -> Self {
|
||||||
|
Self { x, y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Transformers for Translate {
|
||||||
|
fn apply(&self, point_list: &Vec<Point>) -> Vec<Point> {
|
||||||
|
point_list.iter()
|
||||||
|
.map(| pt | {
|
||||||
|
Point { x: pt.x + self.x,
|
||||||
|
y: pt.y + self.y,
|
||||||
|
..*pt
|
||||||
|
}
|
||||||
|
}).collect()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user