add remove point

This commit is contained in:
2025-07-09 09:33:26 +02:00
parent 9b1571b2b1
commit 0ede0749f8
2 changed files with 23 additions and 1 deletions

View File

@@ -35,6 +35,17 @@ impl Music {
&mut self.poly_frame.last_mut().unwrap().1
}
}
fn find_index_frame(&mut self, delta: f32) -> usize {
if let Some(i) = self
.poly_frame
.windows(2)
.position(|w| w[0].0 <= delta && delta < w[1].0)
{
i
} else {
self.poly_frame.len() - 1
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~PUBLIC~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pub fn current_frame(&self, delta: f32) -> &PolygonFrame {
if let Some(i) = self
@@ -121,6 +132,12 @@ impl Music {
self.poly_frame
.insert(pos, (delta, self.current_frame(delta).clone()));
}
pub fn remove_point(&mut self, delta: f32) {
let i = self.find_index_frame(delta);
if i != 0 {
self.poly_frame.remove(i);
}
}
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
let current_frame = self.find_poly_frame(delta);