Motion analysis review round 2: a number names a study by id first, the dialog analyses the study it made on the scratch copy, duration 0.001 s or more, volumes by the innermost member

This commit is contained in:
MateuszSychXpl committed 2026-10-16 17:52:39 +02:00
1 parent b25e9c75aa
commit 3128762014
5 files changed
+49 -23

No files matched your search

+10 -4
View File
@@ -264,8 +264,9 @@ pub fn study_params(s: &Session, name: &str, study: Option<&str>, steps: &str, t
return Err("add a key for a joint first".into());
}
let mut p = json!({"name": name, "steps": steps, "keys": keys});
// The id as a number: a study may be named like another's id.
if let Some(st) = study {
p["study"] = json!(st);
p["study"] = st.parse::<u64>().map_or_else(|_| json!(st), |id| json!(id));
}
Ok(p)
}
@@ -376,9 +377,8 @@ fn moved(before: &Session, after: &Session) -> BTreeMap<u64, Mat> {
/// The study's pose at `step`, computed on a scratch copy.
fn study_pose(app: &SolveApp, params: &Value, step: u32) -> Result<BTreeMap<u64, Mat>, String> {
let mut sc = app.session.scratch();
let name = params["study"].as_str().or(params["name"].as_str()).unwrap_or_default().to_string();
sc.execute("motion.study", params).map_err(|e| e.to_string())?;
sc.execute("motion.play", &json!({"study": name, "step": step})).map_err(|e| e.to_string())?;
let id = scratch_study(&mut sc, params)?;
sc.execute("motion.play", &json!({"study": id, "step": step})).map_err(|e| e.to_string())?;
Ok(moved(&app.session, &sc))
}
@@ -410,6 +410,12 @@ fn export_animation(app: &mut SolveApp, params: Value, name: &str) {
});
}
/// Makes (or edits) the study on a scratch copy, as OK would: its id there (a name may be
/// another study's too).
pub fn scratch_study(sc: &mut Session, params: &Value) -> Result<Value, String> {
Ok(sc.execute("motion.study", params).map_err(|e| e.to_string())?["study"].clone())
}
/// The explosion at `scale`, computed on a scratch copy.
fn explode_pose(app: &SolveApp, scale: f64) -> Result<BTreeMap<u64, Mat>, String> {
let mut sc = app.session.scratch();
+11 -9
View File
@@ -79,7 +79,7 @@ pub fn plot_params(s: &Session, what: Plotted, study: &Value, duration: &str, in
}
let d = duration.trim();
if !d.is_empty() {
let seconds = d.parse::<f64>().ok().filter(|x| x.is_finite() && *x > 0.0).ok_or("the duration must be a number of seconds, more than 0")?;
let seconds = d.parse::<f64>().ok().filter(|x| (1e-3..=1e9).contains(x)).ok_or("the duration must be a number of seconds, 0.001 or more")?;
p["duration"] = json!(seconds);
}
Ok(p)
@@ -276,8 +276,10 @@ fn collision_rows(
&& let Some((st, mut p)) = check
{
let mut sc = app.session.scratch();
p["study"] = st.get("study").or_else(|| st.get("name")).cloned().unwrap_or(Value::Null);
let r = sc.execute("motion.study", &st).and_then(|_| sc.execute("motion.interference", &p)).map_err(|e| e.to_string());
let r = super::scratch_study(&mut sc, &st).and_then(|id| {
p["study"] = id;
sc.execute("motion.interference", &p).map_err(|e| e.to_string())
});
a.collisions = Some((key, r));
}
});
@@ -369,9 +371,9 @@ fn plot_rows(
let params = study.clone().and_then(|st| plot_params(s, what, &st, &a.duration, inputs).map(|p| (st, p)));
let key = key_of(&params);
if a.plot.as_ref().is_none_or(|(k, _)| *k != key) {
let r = params.and_then(|(st, p)| {
let r = params.and_then(|(st, mut p)| {
let mut sc = s.scratch();
sc.execute("motion.study", &st).map_err(|e| e.to_string())?;
p["study"] = super::scratch_study(&mut sc, &st)?;
sc.execute("motion.plot", &p).map_err(|e| e.to_string())
});
a.plot = Some((key, r));
@@ -380,10 +382,10 @@ fn plot_rows(
match a.plot.as_ref().map(|(_, r)| r) {
Some(Ok(v)) => {
ui.vertical(|ui| {
if let Some((xs, ys, unit)) = line(v, what, a.quantity) {
if let Some(to) = chart(ui, &xs, &ys, &unit, total, *step, &bands, t) {
(*step, *playing) = (to, false);
}
if let Some((xs, ys, unit)) = line(v, what, a.quantity)
&& let Some(to) = chart(ui, &xs, &ys, &unit, total, *step, &bands, t)
{
(*step, *playing) = (to, false);
}
if let Some(why) = stop_text(v) {
ui.add(egui::Label::new(RichText::new(why).color(t.warning)).wrap());