Files
vectorcraft/crates/engine/src/tests/widthtool.rs
T
dotCooCoo bbf11feac3 Stroke: Delete and Escape skip width points hidden on a brushed stroke
Width points selected before their stroke took a brush show no handles,
but the Width tool still took Delete, Backspace and Escape for them. The
tool now leaves those keys to the app, as it does with no width points
selected.

- The Profile list shows its hover border whenever a click opens it,
  including on a brushed stroke with a profile, where it lists Uniform.
- A test checks that the list's hover text and the Width tool's status
  message are the same string, so the two share their catalog rows.
- An engine test checks that a press or a double-click on a brushed
  compound path puts the message in the status bar and runs no command.
- The doc comment of Session::brushed_strokes_profiled says when type
  counts, and the progress-doc line names the double-click and says that
  art and pattern brushes do not follow a width profile yet.
2026-11-17 10:45:44 -08:00

71 lines
3.6 KiB
Rust

//! The Width tool on compound paths: the stroke is the compound's, so its members are edited
//! through it, by the tool and by the width point commands given a member.
use serde_json::json;
use vectorcraft_tools::{PointerEvent, PointerKind};
use crate::*;
/// Two 200 pt lines made into a compound path with a 10 pt stroke → (compound, members).
fn compound() -> (Session, NodeId, Vec<NodeId>) {
let mut s = Session::new();
s.execute("file.new", &json!({"width": 500, "height": 500})).unwrap();
let members: Vec<NodeId> = [200, 300]
.iter()
.map(|y| NodeId(s.execute("shape.line", &json!({"x1": 100, "y1": y, "x2": 300, "y2": y})).unwrap()["id"].as_u64().unwrap()))
.collect();
s.execute("select.set", &json!({"ids": [members[0].0, members[1].0]})).unwrap();
let c = NodeId(s.execute("object.compoundPath.make", &json!({})).unwrap()["id"].as_u64().unwrap());
s.execute("select.set", &json!({"ids": [c.0]})).unwrap();
s.execute("stroke.set", &json!({"weight": 10})).unwrap();
(s, c, members)
}
fn profile(s: &Session, id: NodeId) -> Option<Vec<(f64, f64, f64)>> {
s.doc().unwrap().doc.node(id).unwrap().appearance.stroke().and_then(|st| st.profile.as_ref().map(|p| p.points.clone()))
}
#[test]
fn the_width_tool_edits_a_compound_paths_stroke() {
let (mut s, c, members) = compound();
assert!(s.doc().unwrap().doc.node(members[1]).is_some(), "members keep their ids");
let v = ViewInfo::default();
s.select_tool("width", v).unwrap();
// Drag out from the second member's middle: 20 pt either side.
for (k, y) in [(PointerKind::Down, 301.0), (PointerKind::Drag, 310.0), (PointerKind::Drag, 320.0), (PointerKind::Up, 320.0)] {
s.pointer(&PointerEvent::new(k, 200.0, y), v).unwrap();
}
let p = profile(&s, c).expect("the compound's stroke has the width point");
assert!(p.iter().any(|q| (q.0 - 0.5).abs() < 1e-3 && (q.1 - 4.0).abs() < 1e-6), "{p:?}");
assert_eq!(s.journal.last().unwrap().1["id"], json!(c.0));
}
/// A compound path whose stroke draws with a brush: a press or a double-click on a member puts the
/// tool's reason in the status bar and leaves the stroke and the undo history as they were.
#[test]
fn the_width_tool_says_why_it_leaves_a_brushed_compound_path_alone() {
let (mut s, c, _) = compound();
s.execute("brush.apply", &json!({"ids": [c.0], "name": "3 pt. Round"})).unwrap();
let steps = s.journal.len();
let v = ViewInfo::default();
s.select_tool("width", v).unwrap();
for (kind, reason) in [(PointerKind::Down, true), (PointerKind::Drag, false), (PointerKind::Up, false), (PointerKind::DoubleClick, true)] {
let ui = s.pointer(&PointerEvent::new(kind, 200.0, 301.0), v).unwrap();
let said = ui.iter().any(|r| matches!(r, UiRequest::Status(m) if m == vectorcraft_tools::distort::KEEPS_SIZE));
assert_eq!(said, reason, "{kind:?}: {ui:?}");
}
assert_eq!(profile(&s, c), None);
assert_eq!(s.journal.len(), steps, "no command ran");
}
#[test]
fn width_point_commands_given_a_member_edit_the_compound() {
let (mut s, c, members) = compound();
s.execute("stroke.widthPoint.set", &json!({"id": members[0].0, "t": 0.25, "left": 10, "right": 10})).unwrap();
assert_eq!(profile(&s, c).unwrap().len(), 3);
s.execute("stroke.widthPoint.remove", &json!({"id": members[1].0, "index": 1})).unwrap();
assert_eq!(profile(&s, c).unwrap().len(), 2);
s.execute("stroke.widthProfile.set", &json!({"ids": [members[0].0, members[1].0], "points": [[0, 0, 0], [1, 2, 2]]})).unwrap();
assert_eq!(profile(&s, c).unwrap(), vec![(0.0, 0.0, 0.0), (1.0, 2.0, 2.0)]);
}