From 7d159087b354c6ab25f37639a00b22425e0c8f16 Mon Sep 17 00:00:00 2001 From: Lapin Raving Date: Fri, 25 Aug 2023 00:30:29 +0200 Subject: [PATCH] fix: angle correction add some point at begin and endm beacause angles wasn't calculate --- src/transformer/angle_optimisation.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/transformer/angle_optimisation.rs b/src/transformer/angle_optimisation.rs index 64545f7..2525696 100644 --- a/src/transformer/angle_optimisation.rs +++ b/src/transformer/angle_optimisation.rs @@ -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 }