add point + doc -> readme

This commit is contained in:
2025-07-08 22:37:28 +02:00
parent 26a96fd933
commit 87f1b56eac
4 changed files with 35 additions and 7 deletions

View File

@@ -58,6 +58,7 @@ enum Message {
SetMusicLength,
LengthChange(String),
ChangeDelta(f32),
AddPoint,
}
struct MyApp {
@@ -171,6 +172,9 @@ impl MyApp {
self.update(Message::TogglePaused);
}
}
Message::AddPoint => {
self.music.add_Point(self.current_delta);
}
}
}
@@ -312,7 +316,8 @@ impl MyApp {
delta_to_string(self.current_delta),
delta_to_string(self.music.length)
))
.size(20.0)
.size(20.0),
button("Add Point").on_press(Message::AddPoint)
]
.spacing(20),
column![

View File

@@ -52,10 +52,7 @@ impl Music {
pub fn default() -> Music {
Music {
poly_frame: vec![
(0.0, PolygonFrame::default()),
(10.0, PolygonFrame::default()),
],
poly_frame: vec![(0.0, PolygonFrame::default())],
nb_sec_for_rev: 1.0,
file_name: "Default Name".to_string(),
length: 60.0,
@@ -116,6 +113,15 @@ impl Music {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ADD/REMOVE~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pub fn add_Point(&mut self, delta: f32) {
let pos = self
.poly_frame
.binary_search_by(|(d, _)| d.partial_cmp(&delta).unwrap())
.unwrap_or_else(|e| e);
self.poly_frame
.insert(pos, (delta, self.current_frame(delta).clone()));
}
pub fn add_polygon(&mut self, delta: f32, polygon_name: String) {
let current_frame = self.find_poly_frame(delta);
let poly = string_to_polygon(polygon_name);

View File

@@ -23,7 +23,7 @@ impl RotationExt for Vector {
)
}
}
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Clone)]
pub struct PolygonFrame {
pub teta: f32,
pub polygons: Vec<Polygon>,
@@ -118,7 +118,7 @@ impl<Message> canvas::Program<Message> for PolygonFrame {
}
}
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Polygon {
pub global_teta: f32,
pub points_teta: Vec<f32>,