Review #986: the rect through finite_numbers; rustfmt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-11 01:45:18 +07:00
co-authored by Claude Opus 5.5
parent bfbe9e1eb6
commit 6eeabcd742
2 changed files with 4 additions and 11 deletions
+3 -5
View File
@@ -221,11 +221,9 @@ fn rect_cut(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "path.rectCut";
let rect = match p.get("rect") {
Some(v) => {
// Every component must be present and numeric. Dropping invalid elements would
// silently cut the wrong region when a malformed five-element array is supplied.
let values = v.as_array().filter(|a| a.len() == 4).and_then(|a| a.iter().map(Value::as_f64).collect::<Option<Vec<_>>>());
let Some([x, y, w, h]) = values.as_deref() else { return Err(bad(C, "rect must be [x, y, width, height]")) };
Rect::new(*x, *y, x + w, y + h).abs()
// All four or nothing: a malformed entry dropped would cut a different region.
let [x, y, w, h] = finite_numbers(v).ok_or_else(|| bad(C, "rect must be [x, y, width, height]"))?;
Rect::new(x, y, x + w, y + h).abs()
}
None => Rect::from_points(point_req(p, "from", C)?, point_req(p, "to", C)?),
};