mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 19:41:36 -05:00
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.
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user