Motion analysis review round 4: unwrap only followers within half a turn, found pairs in a set, key values kept in full
This commit is contained in:
1 parent
c34e607f5b
commit
3f81495514
5 files changed
+34
-6
No files matched your search
@@ -221,7 +221,13 @@ pub fn study_tracks(s: &Session, key: &str, id_first: bool) -> Result<(u64, Stri
|
||||
.filter_map(|k| {
|
||||
let joint = s.doc.assembly.joints.iter().position(|j| j.id == k.joint)?;
|
||||
let angle = s.doc.assembly.joints.get(joint)?.kind.is_angle(k.index);
|
||||
let value = |v: f64| if angle { crate::dialogs_assembly::num(v.to_degrees(), "deg") } else { crate::dialogs_assembly::num(v, "mm") };
|
||||
let value = |v: f64| {
|
||||
let (x, unit) = if angle { (v.to_degrees(), "deg") } else { (v, "mm") };
|
||||
// Short where that keeps the value; else all its digits, so OK keeps the key.
|
||||
let short = crate::dialogs_assembly::num(x, unit);
|
||||
let kept = short.split(' ').next().and_then(|n| n.parse::<f64>().ok()).is_some_and(|y| (y - x).abs() <= 1e-9 * x.abs().max(1.0));
|
||||
if kept { short } else { format!("{x} {unit}") }
|
||||
};
|
||||
let points = k.points.iter().map(|(st, v)| (st.round().clamp(0.0, f64::from(m.steps)) as u32, value(*v))).collect();
|
||||
Some(Track { joint, index: k.index, points })
|
||||
})
|
||||
|
||||
@@ -464,6 +464,10 @@ mod tests {
|
||||
// A study keyed between whole steps or off its timeline is not opened (the dialog would move its keys).
|
||||
h.app.run("motion.study", json!({"name": "Fine", "steps": 15, "keys": [{"joint": "Rail", "points": [[0, 10], [7.5, -5]]}]})).unwrap();
|
||||
h.app.run("motion.study", json!({"name": "Off", "steps": 15, "keys": [{"joint": "Rail", "points": [[-1, 10], [15, -5]]}]})).unwrap();
|
||||
// A tiny key keeps its value in the form (OK writes the study back from it).
|
||||
h.app.run("motion.study", json!({"name": "Tiny", "steps": 15, "keys": [{"joint": "Rail", "points": [[0, 0.00004], [15, 3]]}]})).unwrap();
|
||||
let (_, _, _, tiny) = crate::dialogs_motion::study_tracks(&h.app.session, "Tiny", false).unwrap();
|
||||
assert_eq!(tiny[0].points, vec![(0, "0.00004 mm".to_string()), (15, "3 mm".to_string())]);
|
||||
for bad in
|
||||
[json!({"study": "Nope"}), json!({"study": "Push", "step": 3}), json!({"study": [1]}), json!({"study": "Fine"}), json!({"study": "Off"})]
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user