mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 16:55:55 +00:00
Path Precision Tools: tool.setOption checks the Tangent Circle Tool's radius
tool.setOption checks every option with the tool's check_option before it sets any (#7366). The Tangent Circle Tool now accepts `radius` from 0.01 to 1000000 pt and gives an error for a value outside that range, one that is not a number, or any other option. Without the check the tool's options dialog could not set the radius. Part of #7178.
This commit is contained in:
@@ -411,6 +411,14 @@ impl Tool for TangentCircleTool {
|
||||
self.radius = r;
|
||||
}
|
||||
}
|
||||
|
||||
fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
|
||||
use crate::option_check as c;
|
||||
match key {
|
||||
"radius" => c::number(key, v, RADIUS_RANGE.0, RADIUS_RANGE.1),
|
||||
_ => Err(c::unknown(key)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@@ -516,11 +524,17 @@ mod tests {
|
||||
let mut t = TangentCircleTool::default();
|
||||
t.set_option("radius", &json!(10));
|
||||
assert_eq!(t.options()["radius"], json!(10.0));
|
||||
// A value outside 0.01 to 1000000, or not a number, leaves the radius as it is.
|
||||
// `tool.setOption` refuses a value outside 0.01 to 1000000, or one that is not a number,
|
||||
// and any other option; set anyway, such a value leaves the radius as it is.
|
||||
for good in [json!(0.01), json!(36), json!(1e6)] {
|
||||
assert_eq!(t.check_option("radius", &good), Ok(()), "{good}");
|
||||
}
|
||||
for bad in [json!(0), json!(0.005), json!(2e6), json!(-5), json!("12"), Value::Null] {
|
||||
assert_eq!(t.check_option("radius", &bad), Err("`radius` must be a number from 0.01 to 1000000".into()), "{bad}");
|
||||
t.set_option("radius", &bad);
|
||||
assert_eq!(t.options()["radius"], json!(10.0), "{bad}");
|
||||
}
|
||||
assert!(t.check_option("size", &json!(10)).is_err());
|
||||
// The L's two segments: the circle of radius 10 in its corner.
|
||||
t.pointer(&cx, &ev(PointerKind::Down, 150.0, 300.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Up, 150.0, 300.0));
|
||||
|
||||
+2
-2
@@ -13212,8 +13212,8 @@ Tools:
|
||||
nothing and the first segment stays picked; it also stays when drawing the circle fails or the press on the second
|
||||
segment is canceled (a canceled touch). Escape, an edit, Undo or Redo outside the tool, or another document forgets
|
||||
the first segment.
|
||||
Option (`tool.setOption`, or a double-click on the tool): `radius` (pt, 0.01 to 1000000, 36). The value is not
|
||||
checked yet: one outside that range, or not a number, leaves the radius as it is.
|
||||
Option (`tool.setOption`, or a double-click on the tool): `radius` (pt, 0.01 to 1000000, 36). `tool.setOption`
|
||||
gives an error for a value outside that range or one that is not a number, and for any other option.
|
||||
- **Trim at Crossings Tool** (`trimAtCrossings`): removes stretches of paths between the places where they are crossed,
|
||||
on any path that can be edited, selected or not. A click runs `addon.pathtools.trim` with `at`, for the path within 4
|
||||
screen pixels of the pointer. A drag draws a rectangle and runs it with `rect` on release; once the pointer has
|
||||
|
||||
Reference in New Issue
Block a user