From db1d346bc4dffac3407c9299fd4e6661c72e7223 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 3 Dec 2026 09:56:28 -0800 Subject: [PATCH] Tests: Divide refuses cutting lines past the segment cap A square and an unfilled zigzag with one segment more than the planar map's cap: Divide returns the "select fewer paths" error and leaves the document and the undo history unchanged. With the check replaced by the unchecked Divide, the test fails because Divide returns the square uncut. --- crates/engine/src/tests/pathops.rs | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/crates/engine/src/tests/pathops.rs b/crates/engine/src/tests/pathops.rs index a5a082058e..d1b5197012 100644 --- a/crates/engine/src/tests/pathops.rs +++ b/crates/engine/src/tests/pathops.rs @@ -171,6 +171,38 @@ fn pathfinder_refuses_a_selection_without_paths_and_invalid_coordinates() { assert_eq!(s.doc().unwrap().history.undo.len(), undo_len); } +/// Divide refuses a cutting line with more segments than its planar map takes, instead of +/// dividing the square without the line, and leaves the document and the undo history as they were. +#[test] +fn divide_refuses_cutting_lines_past_the_segment_cap() { + let mut s = session(); + let base = rect(&mut s, 0.0, 0.0, 100.0, 100.0); + let cutter = NodeId(s.execute("path.create", &json!({"anchors": [{"x": -10, "y": 50}, {"x": 110, "y": 50}]})).unwrap()["id"].as_u64().unwrap()); + // A zigzag across the square with one segment more than the cap, the square's four sides aside. + let segments = vectorcraft_pathops::SHAPE_BUILDER_MAX_SEGMENTS - 3; + s.edit("zigzag", |d, sel| { + let mut bp = vectorcraft_geom::BezPath::new(); + bp.move_to((-10.0, 40.0)); + for i in 1..=segments { + let x = -10.0 + 120.0 * i as f64 / segments as f64; + bp.line_to((x, if i % 2 == 0 { 40.0 } else { 60.0 })); + } + // Unfilled, so the zigzag stays open and cuts. + let n = d.node_mut(cutter).unwrap(); + n.appearance = Appearance::basic(Paint::None, Paint::solid(Color::BLACK), 1.0).into(); + n.kind = NodeKind::Path { path: PathData::from_bezpath(&bp), rule: FillRule::NonZero, live: None, clipping: false, guide: false }; + sel.set([cutter, base]); + Ok(()) + }) + .unwrap(); + let before = s.doc().unwrap().doc.clone(); + let undo_len = s.doc().unwrap().history.undo.len(); + let e = s.execute("object.pathfinder.divide", &json!({})).unwrap_err().to_string(); + assert!(e.contains("select fewer paths"), "{e}"); + assert!(s.doc().unwrap().doc == before); + assert_eq!(s.doc().unwrap().history.undo.len(), undo_len); +} + #[test] fn exclude_makes_compound() { let mut s = session();