Tools: the Arc tool keeps its lengths at most 1e6 pt, as tool.setOption takes them

The Arc tool's setter took a length of any size, while its option check
takes a number above 0 and at most 1e6, so a length set past 1e6 was
reported back and then refused. The setter now keeps a length within
that range.

The catalog test also checks what each tool reports after a number
option is set past either end and after a true-or-false option is
flipped. docs/mcp.md gives the range tool.setOption takes for the
Eraser's sizeVariation (0 to 1000).
This commit is contained in:
dotCooCoo
2026-11-15 11:57:06 -08:00
parent 23bdbada81
commit b1f9081feb
3 changed files with 32 additions and 9 deletions
+7 -2
View File
@@ -531,9 +531,10 @@ impl Tool for FamilyTool {
}
}
/// Arc segment length from a dialog or preference value.
/// Arc segment length from a dialog or preference value, at most 1e6 pt (as the option check
/// takes it).
fn arc_length(v: &Value, current: f64) -> f64 {
v.as_f64().filter(|n| n.is_finite()).map_or(current, |n| n.abs().max(1e-9))
v.as_f64().filter(|n| n.is_finite()).map_or(current, |n| n.abs().clamp(1e-9, 1e6))
}
/// A grid's Default Size side from option value `v`: a finite positive length (at most 1e6 pt),
@@ -1030,6 +1031,10 @@ mod tests {
"fillArc": true,
})
);
// A length past 1e6 pt is kept at 1e6, which `tool.setOption` takes back.
t.set_option("lengthX", &json!(-1e9));
assert_eq!(t.options()["lengthX"], json!(1e6));
assert_eq!(t.check_option("lengthX", &t.options()["lengthX"]), Ok(()));
}
/// While an arc is dragged out, C switches it between open and closed, F switches its base
+24 -6
View File
@@ -176,17 +176,35 @@ mod tests {
let read_only = |id: &str, k: &str| READ_ONLY.iter().any(|(ids, keys)| ids.contains(&id) && keys.contains(&k));
let extra = ["place", "dimension"];
let mut refused = Vec::new();
for id in crate::catalog::all_tools().map(|t| t.id).chain(extra) {
let tool = crate::create(id);
let Some(mut options) = tool.options().as_object().cloned() else { continue };
let mut check = |id: &str, tool: &dyn Tool, after: &str| {
let Some(mut options) = tool.options().as_object().cloned() else { return };
options.retain(|k, _| !read_only(id, k));
for (k, v) in &options {
if let Err(e) = tool.check_option(k, v) {
refused.push(format!("tool `{id}`, option `{k}` = {v}: {e}"));
refused.push(format!("tool `{id}`{after}, option `{k}` = {v}: {e}"));
}
}
if let Err(e) = check_values(tool.as_ref(), &options) {
refused.push(e);
if let Err(e) = check_values(tool, &options) {
refused.push(format!("{e}{after}"));
}
};
for id in crate::catalog::all_tools().map(|t| t.id).chain(extra) {
let tool = crate::create(id);
check(id, tool.as_ref(), "");
// A number set past either end, or a true-or-false option flipped, is still taken back
// as the tool then reports it.
let Some(defaults) = tool.options().as_object().cloned() else { continue };
for (k, v) in defaults.iter().filter(|(k, _)| !read_only(id, k)) {
let tries = match v {
Value::Number(_) => vec![json!(-1e9), json!(1e9)],
Value::Bool(b) => vec![json!(!b)],
_ => continue,
};
for value in tries {
let mut changed = crate::create(id);
changed.set_option(k, &value);
check(id, changed.as_ref(), &format!(" after setting `{k}` to {value}"));
}
}
}
assert!(refused.is_empty(), "{}", refused.join("\n"));
+1 -1
View File
@@ -5734,7 +5734,7 @@ drag without that reading, such as a mouse drag, erases at the value itself. One
Tilt, Bearing and Rotation run, and the value itself without a reading are VectorCraft's own rules.
The command refuses another mode, and a variation below 0 or past its range, and erases nothing. In the desktop app
the Eraser's tip outline at the pointer takes the angle, roundness and size the pen gives while it erases.
`tool.setOption {tool: "eraser"}` takes the same keys.
`tool.setOption {tool: "eraser"}` takes the same keys, with `sizeVariation` from 0 to 1000.
These commands refuse a string or another value that is not a number with `` `dy` must be a number, not "10" ``,
naming the key; the document does not change and no undo step is recorded: `t`, `dx` and `dy` in