fix: angle correction

add some point at begin and endm beacause angles wasn't calculate
This commit is contained in:
Lapin Raving 2023-08-25 00:30:29 +02:00
parent e409071cc1
commit 7d159087b3

View File

@ -83,17 +83,17 @@ impl Transformers for AngleOptimisation {
let to_add_max = _ws.kpps as f64 / self.coef; // for 180 deg
let to_add_min = max(to_add_max / 1.5, 2.); // for 180 deg
v.push(pl[0]); // push first
let mut first_blanc = pl[0].clone();
first_blanc.color = Color{r:0, g:0, b:0};
for _ in 0..(to_add_max as u32) {
v.push(first_blanc); // push first
}
v.push(pl[0]);
for i in 1..(pl.len() - 1) {
let node = &pl[i];
if let ((Some(prev), dist_prev), (Some(next), dist_next)) =
(get_prev(pl, i), get_next(pl, i))
{
// on push plusisieur fois le point que l'on regarde
// - on calcul l'angle
// - on en deduis le ratio de nombre a appliquer
// - on regarde si il y a suffisement de point avant
// - on rajoute les point manquant
let d1 = Point::diff(node, prev).normalize();
let d2 = Point::diff(next, node).normalize();
let angle = (d1.cross(&d2) as f64).acos();
@ -109,7 +109,13 @@ impl Transformers for AngleOptimisation {
};
//v.push(*node); // push node
}
v.push(pl[pl.len() - 1]); // push last
for _ in 0..(to_add_max as u32) {
v.push(pl[pl.len() - 2]); // push last
}
for _ in 0..(to_add_max as u32) {
v.push(pl[pl.len() - 1]); // push last
}
println!("\tbefore: {}\tafter: {}", pl.len(), v.len());
v
}