feat: add some point to respect angle position
This commit is contained in:
parent
a006bd87a6
commit
e409071cc1
@ -35,3 +35,7 @@ Until = 48
|
|||||||
[[transformers]]
|
[[transformers]]
|
||||||
[transformers.intensity]
|
[transformers.intensity]
|
||||||
|
|
||||||
|
|
||||||
|
[[transformers]]
|
||||||
|
[transformers.angle_correction]
|
||||||
|
coef = 2000.0
|
||||||
|
@ -3,13 +3,15 @@ use crate::transformer::Transformers;
|
|||||||
use crate::worldstate::WorldState;
|
use crate::worldstate::WorldState;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::f32::consts::PI;
|
use std::f64::consts::PI;
|
||||||
|
//use std::cmp::min;
|
||||||
|
|
||||||
/// Angle Optimisation
|
/// Angle Optimisation
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
#[derive(Serialize, Deserialize, Debug, Clone, Copy)]
|
||||||
pub struct AngleOptimisation {
|
pub struct AngleOptimisation {
|
||||||
coef: f32,
|
coef: f64,
|
||||||
|
//pps: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn color_not_zero(p1: &Point, p2: &Point, p3: &Point) -> bool {
|
fn color_not_zero(p1: &Point, p2: &Point, p3: &Point) -> bool {
|
||||||
@ -29,58 +31,93 @@ fn pos_different(p1: &Point, p2: &Point) -> bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Le temps a attendre a un angle est toujours le meme, peu importe les kpps.
|
||||||
|
* Donc le nombre de point a rajouter est proportionelle a la vitesse du laser.
|
||||||
|
*
|
||||||
|
* kpps /
|
||||||
|
* */
|
||||||
|
|
||||||
|
fn color_same(p1: &Point, p2: &Point) -> bool {
|
||||||
|
if p1.color.r == p2.color.r && p1.color.g == p2.color.g && p1.color.b == p2.color.b {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// quand on rajoute un point, on le rejoute ou et avec quelle couleur
|
||||||
|
// -> j'ai l'impression qu'on le rajoute surtout a l'arriver
|
||||||
|
|
||||||
|
fn get_prev(pl: &[Point], id: usize) -> (Option<&Point>, usize) {
|
||||||
|
for i in (0..id).rev() {
|
||||||
|
if pos_different(&pl[id], &pl[i]) {
|
||||||
|
return (Some(&pl[i]), id - i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(None, id - 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_next(pl: &[Point], id: usize) -> (Option<&Point>, usize) {
|
||||||
|
for i in id..(pl.len() - 1) {
|
||||||
|
if pos_different(&pl[id], &pl[i]) {
|
||||||
|
return (Some(&pl[i]), i - id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
(None, pl.len() - id - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn max(v1: f64, v2: f64) -> f64 {
|
||||||
|
if v1 > v2 {
|
||||||
|
v1
|
||||||
|
} else {
|
||||||
|
v2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Transformers for AngleOptimisation {
|
impl Transformers for AngleOptimisation {
|
||||||
fn apply(&self, point_list: &[Point], _ws: &WorldState) -> Vec<Point> {
|
fn apply(&self, pl: &[Point], _ws: &WorldState) -> Vec<Point> {
|
||||||
let c0 = Color { r: 0, g: 0, b: 0 };
|
let c0 = Color { r: 0, g: 0, b: 0 };
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
|
|
||||||
//println!();
|
let to_add_max = _ws.kpps as f64 / self.coef; // for 180 deg
|
||||||
//println!("====================");
|
let to_add_min = max(to_add_max / 1.5, 2.); // for 180 deg
|
||||||
//println!("= next Frame =");
|
|
||||||
//println!("====================");
|
|
||||||
v.push(point_list[0]);
|
|
||||||
for i in 1..(point_list.len() - 1) {
|
|
||||||
let prev = point_list[i - 1];
|
|
||||||
let node = point_list[i];
|
|
||||||
let next = point_list[i + 1];
|
|
||||||
|
|
||||||
if color_not_zero(&prev, &node, &next)
|
v.push(pl[0]); // push first
|
||||||
&& pos_different(&prev, &node)
|
for i in 1..(pl.len() - 1) {
|
||||||
&& pos_different(&node, &next)
|
let node = &pl[i];
|
||||||
|
if let ((Some(prev), dist_prev), (Some(next), dist_next)) =
|
||||||
|
(get_prev(pl, i), get_next(pl, i))
|
||||||
{
|
{
|
||||||
//println!("=========");
|
// on push plusisieur fois le point que l'on regarde
|
||||||
let mut d1 = Point::diff(&node, &prev);
|
// - on calcul l'angle
|
||||||
let mut d2 = Point::diff(&next, &next);
|
// - on en deduis le ratio de nombre a appliquer
|
||||||
//dbg!(d1);
|
// - on regarde si il y a suffisement de point avant
|
||||||
//dbg!(d2);
|
// - on rajoute les point manquant
|
||||||
d1.normalize();
|
let d1 = Point::diff(node, prev).normalize();
|
||||||
d2.normalize();
|
let d2 = Point::diff(next, node).normalize();
|
||||||
|
let angle = (d1.cross(&d2) as f64).acos();
|
||||||
let cross = d1.cross(&d2);
|
let to_add = ((to_add_max - to_add_min) * (angle / PI) + to_add_min) as usize;
|
||||||
let angle = d1.cross(&d2).acos();
|
println!("\nangle: {}", (angle / PI * 180.));
|
||||||
|
dbg!(to_add);
|
||||||
let deg = angle * 180. / PI;
|
dbg!(to_add_max);
|
||||||
|
for _ in 0..to_add {
|
||||||
//dbg!(prev);
|
v.push(*node);
|
||||||
//dbg!(node);
|
}
|
||||||
//dbg!(next);
|
} else {
|
||||||
//dbg!(d1);
|
v.push(*node);
|
||||||
//dbg!(d2);
|
};
|
||||||
//dbg!(cross);
|
//v.push(*node); // push node
|
||||||
//dbg!(angle);
|
|
||||||
//dbg!(deg);
|
|
||||||
|
|
||||||
//println!("deg: {deg}");
|
|
||||||
|
|
||||||
let nb_add = (self.coef * (1. - angle / PI)) as usize;
|
|
||||||
|
|
||||||
for _ in 0..nb_add {}
|
|
||||||
}
|
|
||||||
|
|
||||||
v.push(node); // push node
|
|
||||||
}
|
}
|
||||||
v.push(point_list[point_list.len() - 1]); // push last
|
v.push(pl[pl.len() - 1]); // push last
|
||||||
|
|
||||||
v
|
v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* |\
|
||||||
|
* | \
|
||||||
|
* | \
|
||||||
|
* | |
|
||||||
|
* */
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use crate::point::{Point, Color};
|
use crate::point::{Color, Point};
|
||||||
use crate::transformer::Transformers;
|
use crate::transformer::Transformers;
|
||||||
use crate::worldstate::WorldState;
|
use crate::worldstate::WorldState;
|
||||||
|
|
||||||
@ -20,8 +20,19 @@ impl Transformers for Replicate {
|
|||||||
match self {
|
match self {
|
||||||
Replicate::Until(n) => {
|
Replicate::Until(n) => {
|
||||||
while point_list2.len() < *n {
|
while point_list2.len() < *n {
|
||||||
if point_list.len() == 0 { // to prevent infinit loop in case of empty frame
|
if point_list.len() == 0 {
|
||||||
point_list2.append(&mut vec![Point{x:0., y:0., color: Color{r:0, g:0, b:0}}; *n].to_vec());
|
// to prevent infinit loop in case of empty frame
|
||||||
|
point_list2.append(
|
||||||
|
&mut vec![
|
||||||
|
Point {
|
||||||
|
x: 0.,
|
||||||
|
y: 0.,
|
||||||
|
color: Color { r: 0, g: 0, b: 0 }
|
||||||
|
};
|
||||||
|
*n
|
||||||
|
]
|
||||||
|
.to_vec(),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
point_list2.append(&mut point_list.to_vec());
|
point_list2.append(&mut point_list.to_vec());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user