mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-20 09:23:10 +01:00
Merge pull request #8749 from storytold/train/carry8727
Image Trace: imageTrace.setView refuses a null split (#8727)
This commit is contained in:
2 files changed
+7
-3
No files matched your search
@@ -58,9 +58,10 @@ fn view_param(cmd: &str, p: &Value) -> Result<Option<TraceView>> {
|
||||
v.as_str().and_then(TraceView::from_id).map(Some).ok_or_else(|| bad(cmd, format!("view must be one of {}", ids())))
|
||||
}
|
||||
|
||||
/// The `split` param (the Split view's divider, 0 to 1), if given.
|
||||
/// The `split` param (the Split view's divider, 0 to 1), if given. A null divider is an error, as
|
||||
/// any other value that is not such a number is; only an omitted one keeps the divider.
|
||||
fn split_param(cmd: &str, p: &Value) -> Result<Option<f64>> {
|
||||
let Some(v) = p.get("split").filter(|v| !v.is_null()) else { return Ok(None) };
|
||||
let Some(v) = p.get("split") else { return Ok(None) };
|
||||
v.as_f64().filter(|f| (0.0..=1.0).contains(f)).map(Some).ok_or_else(|| bad(cmd, "split must be a number from 0 to 1"))
|
||||
}
|
||||
|
||||
|
||||
@@ -9491,9 +9491,12 @@ fn image_trace_split_view_keeps_and_validates_its_divider() {
|
||||
assert_eq!((back.node(g).unwrap().trace_view(), back.node(g).unwrap().trace_split()), (vectorcraft_doc::TraceView::Split, 0.25));
|
||||
// Bad dividers are refused and change nothing.
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
for bad in [json!(-0.1), json!(1.01), json!("0.5"), json!(true), json!([0.5])] {
|
||||
for bad in [json!(-0.1), json!(1.01), json!("0.5"), json!(true), json!([0.5]), json!(null)] {
|
||||
assert!(s.execute("imageTrace.setView", &json!({"view": "split", "split": bad})).is_err(), "{bad}");
|
||||
}
|
||||
// A null divider with another view is refused too, and the view stays.
|
||||
assert!(s.execute("imageTrace.setView", &json!({"view": "outlines", "split": null})).is_err());
|
||||
assert_eq!(node(&s, g).trace_view(), vectorcraft_doc::TraceView::Split);
|
||||
assert_eq!((s.doc().unwrap().history.undo.len(), node(&s, g).trace_split()), (steps, 0.25));
|
||||
for edge in [0.0, 1.0] {
|
||||
s.execute("imageTrace.setView", &json!({"view": "split", "split": edge})).unwrap();
|
||||
|
||||
Reference in new issue
Block a user