From a4214b7f5c8e784f4fc17660f9573a01803b13e0 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 06:24:45 -0800 Subject: [PATCH 1/7] Dimension tool: only a linear dimension reads the dimension lines Placing an angular, radius or diameter dimension no longer reads the lines of the dimensions in the document, which only a linear dimension can line up with. A linear dimension still reads them with Smart Guides off, so it lines up when Smart Guides are turned on while it is placed. docs/dimensions.md no longer says the level can come from a dimension anywhere in the document: the tool reads at most 20,000 objects. --- crates/tools/src/dimension.rs | 41 ++++++++++++++++++++++++++++++++--- docs/dimensions.md | 5 ++--- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/crates/tools/src/dimension.rs b/crates/tools/src/dimension.rs index e397b1f9ed..5d96908e7d 100644 --- a/crates/tools/src/dimension.rs +++ b/crates/tools/src/dimension.rs @@ -79,8 +79,9 @@ pub struct DimensionTool { /// While a Linear dimension is placed with its line on the level of another dimension's line: /// the ends of that other line. A Smart Guide runs along the level across both lines. level_guide: Option<(Point, Point)>, - /// While a dimension is placed: the lines of the visible, unlocked linear dimensions in the - /// document before its first preview ([`dimension_lines`]), which its line can line up with. + /// While a linear dimension is placed: the lines of the visible, unlocked linear dimensions in + /// the document before its first preview ([`dimension_lines`]), which its line can line up with + /// while Smart Guides are on. levels: Vec, } @@ -524,7 +525,7 @@ impl DimensionTool { // With Smart Guides on, a linear dimension's line lands on the level of a parallel // dimension line already drawn within the Smart Guides snapping tolerance. The lines are // read before the first preview, so the preview of this dimension is not one of them. - if !self.began { + if !self.began && d.mode == DimensionMode::Linear { self.levels = dimension_lines(cx); } let level = if cx.smart_guides { line_level(&self.levels, d, p, cx.snap_tol()) } else { None }; @@ -878,6 +879,40 @@ mod tests { } } + /// The lines of the dimensions in the document are read only for a linear dimension. They are + /// read with Smart Guides off too, so a line placed after Smart Guides are turned on lines up. + #[test] + fn dimension_lines_are_read_only_for_a_linear_dimension() { + use vectorcraft_doc::{Node, NodeKind}; + let (mut d, _) = doc_with_rect(); + let id = d.alloc_id(); + let mut drawn = Node::new(id, NodeKind::Group { children: vec![], clip: false }); + let pt = Point::new; + drawn.extras_mut().dimension = + Some(Box::new(DimensionTool::default().recipe(DimensionMode::Linear, pt(300.0, 300.0), pt(400.0, 300.0), pt(350.0, 300.0), None))); + let l = d.layers[0].id; + d.insert(Some(l), usize::MAX, drawn).unwrap(); + let (s, p) = (Selection::default(), paint()); + let ev = |kind, x: f64, y: f64| PointerEvent::new(kind, x, y); + let c = cx(&d, &s, &p); + let off = ToolContext { smart_guides: false, ..cx(&d, &s, &p) }; + let mut t = DimensionTool::default(); + for (x, y) in [(400.0, 400.0), (450.0, 400.0)] { + t.pointer(&off, &ev(PointerKind::Down, x, y)); + t.pointer(&off, &ev(PointerKind::Up, x, y)); + } + assert!(matches!(t.pointer(&off, &ev(PointerKind::Move, 420.0, 450.0)).first(), Some(Action::Begin(_)))); + assert_eq!(t.levels.len(), 1); + let acts = t.pointer(&c, &ev(PointerKind::Move, 420.0, 302.0)); + let Some(Action::Preview(_, params)) = acts.last() else { panic!("{acts:?}") }; + assert_eq!(params["offset"], json!(-100.0), "on the level of the line drawn at y = 300"); + let mut t = DimensionTool::default(); + t.set_option("mode", &json!("angular")); + t.pointer(&c, &ev(PointerKind::Down, 100.0, 100.0)); + assert!(matches!(t.pointer(&c, &ev(PointerKind::Drag, 130.0, 140.0)).first(), Some(Action::Begin(_)))); + assert!(t.levels.is_empty(), "an angular dimension reads no lines"); + } + #[test] fn a_dropped_placement_press_does_not_commit_the_dimension() { let (d, _) = doc_with_rect(); diff --git a/docs/dimensions.md b/docs/dimensions.md index 762575379b..128b9246af 100644 --- a/docs/dimensions.md +++ b/docs/dimensions.md @@ -53,9 +53,8 @@ The **Dimension Tool** is in the Modify section of the toolbar. Its strip offers far past the outermost point as before. With Smart Guides on, a linear dimension placed with its line within the Smart Guides snapping tolerance of the level of a parallel line of a visible, unlocked linear dimension already drawn - anywhere in the document has its line on that level. This is VectorCraft's own rule. With - Alignment Guides on, a guide runs along the level across both lines while the dimension is - placed. + has its line on that level. This is VectorCraft's own rule. With Alignment Guides on, a guide + runs along the level across both lines while the dimension is placed. - **Angular:** hover a corner where two straight segments meet and drag outwards. Or click two straight lines that meet (or would, extended), then click to place. - **Radial:** hover a circle, or a segment that is a perfect arc, and drag: outwards gives its From 2e0a856fb62c83399067baca4c7012c5bca864bd Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 06:55:39 -0800 Subject: [PATCH 2/7] Dimension tool: docs say which dimension lines a linear dimension lines up with docs/dimensions.md now says that the other dimension, and every layer and group it is in, must be visible and unlocked, and that the tool reads at most 20,000 visible, unlocked objects, from the frontmost back. --- docs/dimensions.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/dimensions.md b/docs/dimensions.md index 128b9246af..b3d859f33c 100644 --- a/docs/dimensions.md +++ b/docs/dimensions.md @@ -52,9 +52,12 @@ The **Dimension Tool** is in the Modify section of the toolbar. Its strip offers turns has its line where the turn puts it, or, when that would put it between the points, as far past the outermost point as before. With Smart Guides on, a linear dimension placed with its line within the Smart Guides snapping - tolerance of the level of a parallel line of a visible, unlocked linear dimension already drawn - has its line on that level. This is VectorCraft's own rule. With Alignment Guides on, a guide - runs along the level across both lines while the dimension is placed. + tolerance of the level of a parallel line of a linear dimension already drawn has its line on + that level. The other dimension, and every layer and group it is in, must be visible and + unlocked. The tool reads at most 20,000 visible, unlocked objects, from the frontmost back, so in + a larger document a dimension past them is not a level. This is VectorCraft's own rule. With + Alignment Guides on, a guide runs along the level across both lines while the dimension is + placed. - **Angular:** hover a corner where two straight segments meet and drag outwards. Or click two straight lines that meet (or would, extended), then click to place. - **Radial:** hover a circle, or a segment that is a perfect arc, and drag: outwards gives its From 9215d2080a6cc85589fa4c2c560db10b76765ca7 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 08:37:41 -0800 Subject: [PATCH 3/7] Dimension tool: a dimension hidden while another is placed is no longer a level While a linear dimension is placed with Smart Guides on, the tool reads the lines of the other dimensions again when the document changes, so a dimension a command hides, locks or deletes stops being a level, and one shown again or grouped is a level again. The preview of the dimension being placed is left out of the lines and out of the 20,000 objects the tool reads. --- crates/engine/tests/it/dimensions.rs | 16 +++ crates/tools/src/dimension.rs | 156 ++++++++++++++++++++++++--- 2 files changed, 160 insertions(+), 12 deletions(-) diff --git a/crates/engine/tests/it/dimensions.rs b/crates/engine/tests/it/dimensions.rs index 17391ae98a..45778fa350 100644 --- a/crates/engine/tests/it/dimensions.rs +++ b/crates/engine/tests/it/dimensions.rs @@ -2080,6 +2080,22 @@ fn a_dimension_of_the_same_points_lines_up_and_the_line_follows_the_pointer() { assert_eq!(recipe(&s, id).line_ends(), (pt(200.0, 186.0), pt(300.0, 186.0))); } +/// With Real-time Drawing off, a dimension hidden or deleted by a command while another is placed +/// is no longer a level: no guide runs along its level. +#[test] +fn a_dimension_hidden_or_deleted_while_another_is_placed_is_no_longer_a_level() { + let plain = ViewInfo::default(); + for cmd in ["object.hide", "edit.clear"] { + let (mut s, first) = level_start(plain); + run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": false})); + linear_click(&mut s, plain, 200.0, 200.0); + linear_click(&mut s, plain, 300.0, 200.0); + assert!(!guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: on the level before"); + run(&mut s, cmd, json!({"ids": [first]})); + assert!(guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: no level after"); + } +} + /// A dimension dragged out from a segment, with its line within the Smart Guides snapping /// tolerance of the level of another dimension's parallel line, lands on that level. #[test] diff --git a/crates/tools/src/dimension.rs b/crates/tools/src/dimension.rs index 5d96908e7d..97801b50fe 100644 --- a/crates/tools/src/dimension.rs +++ b/crates/tools/src/dimension.rs @@ -80,9 +80,14 @@ pub struct DimensionTool { /// the ends of that other line. A Smart Guide runs along the level across both lines. level_guide: Option<(Point, Point)>, /// While a linear dimension is placed: the lines of the visible, unlocked linear dimensions in - /// the document before its first preview ([`dimension_lines`]), which its line can line up with - /// while Smart Guides are on. + /// the document ([`dimension_lines`]), which its line can line up with while Smart Guides are + /// on. With Smart Guides on, they are read again when the document's revision has moved. levels: Vec, + /// The document revision `levels` were read at. + levels_at: (u64, u64), + /// The document's next object id at the dimension's first preview: the id its preview takes + /// (`dimension.create` gives the dimension the next id). The preview is not a level. + preview_id: u64, } /// What a linear dimension between `a` and `b` measures with the pointer at `p` while it is @@ -295,11 +300,14 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { /// The line of a linear dimension already drawn: its ends and its direction. type DimensionLine = ((Point, Point), Vec2); -/// The lines of the visible, unlocked linear dimensions in the document. Bounded work, as in -/// [`on_dimensions`]. -fn dimension_lines(cx: &ToolContext) -> Vec { - fn visit(n: &Node, budget: &mut usize, out: &mut Vec) { - if *budget == 0 || !n.visible || n.locked { +/// The lines of the visible, unlocked linear dimensions in the document, except the preview of the +/// dimension being placed: a dimension with the id `preview.0` that measures the points +/// `preview.1`. Bounded work, as in [`on_dimensions`]. +fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec { + fn visit(n: &Node, preview: (u64, [Point; 2]), budget: &mut usize, out: &mut Vec) { + let is_preview = n.id.0 == preview.0 + && n.extras().dimension.as_ref().is_some_and(|d| d.a.distance(preview.1[0]) < 1e-9 && d.b.distance(preview.1[1]) < 1e-9); + if *budget == 0 || !n.visible || n.locked || is_preview { return; } *budget -= 1; @@ -310,12 +318,12 @@ fn dimension_lines(cx: &ToolContext) -> Vec { return; } for c in n.children().into_iter().flatten().rev() { - visit(c, budget, out); + visit(c, preview, budget, out); } } let (mut budget, mut out) = (20_000usize, vec![]); for n in cx.doc.layers.iter().rev() { - visit(n, &mut budget, &mut out); + visit(n, preview, &mut budget, &mut out); } out } @@ -524,9 +532,17 @@ impl DimensionTool { } // With Smart Guides on, a linear dimension's line lands on the level of a parallel // dimension line already drawn within the Smart Guides snapping tolerance. The lines are - // read before the first preview, so the preview of this dimension is not one of them. - if !self.began && d.mode == DimensionMode::Linear { - self.levels = dimension_lines(cx); + // read at the first preview and, with Smart Guides on, again when the document has changed + // since (a command hid, locked or deleted a dimension). The preview of this dimension is + // not one of them. + if d.mode == DimensionMode::Linear { + if !self.began { + self.preview_id = cx.doc.peek_next_id(); + } + if !self.began || (cx.smart_guides && self.levels_at != cx.revision) { + self.levels = dimension_lines(cx, (self.preview_id, [d.a, d.b])); + self.levels_at = cx.revision; + } } let level = if cx.smart_guides { line_level(&self.levels, d, p, cx.snap_tol()) } else { None }; d.place(level.map_or(p, |(on_level, _)| on_level)); @@ -913,6 +929,122 @@ mod tests { assert!(t.levels.is_empty(), "an angular dimension reads no lines"); } + /// A dimension hidden, locked or deleted while another is placed is no longer a level, and one + /// shown again or grouped is: the lines are read again when the document's revision moves. The + /// preview of the dimension itself, with the id the document gave next when it began, is never + /// a level. + #[test] + fn dimension_lines_are_read_again_when_the_document_changes() { + use vectorcraft_doc::{Node, NodeKind}; + let (mut d, _) = doc_with_rect(); + let pt = Point::new; + let line = |y: f64| Some(Box::new(DimensionTool::default().recipe(DimensionMode::Linear, pt(300.0, y), pt(400.0, y), pt(350.0, y), None))); + let id = d.alloc_id(); + let mut drawn = Node::new(id, NodeKind::Group { children: vec![], clip: false }); + drawn.extras_mut().dimension = line(300.0); + let l = d.layers[0].id; + d.insert(Some(l), usize::MAX, drawn).unwrap(); + let (s, p) = (Selection::default(), paint()); + let ev = |kind, x: f64, y: f64| PointerEvent::new(kind, x, y); + let offset = |t: &mut DimensionTool, c: &ToolContext| { + let acts = t.pointer(c, &ev(PointerKind::Move, 420.0, 302.0)); + let Some(Action::Preview(_, params)) = acts.last() else { panic!("{acts:?}") }; + params["offset"].clone() + }; + let mut t = DimensionTool::default(); + let c = cx(&d, &s, &p); + for (x, y) in [(400.0, 400.0), (450.0, 400.0)] { + t.pointer(&c, &ev(PointerKind::Down, x, y)); + t.pointer(&c, &ev(PointerKind::Up, x, y)); + } + assert!(matches!(t.pointer(&c, &ev(PointerKind::Move, 420.0, 450.0)).first(), Some(Action::Begin(_)))); + assert_eq!(offset(&mut t, &c), json!(-100.0), "on the level of the line drawn at y = 300"); + // With Smart Guides off the lines are not read; turned on, they are read as they are now. + let mut hidden = d.clone(); + hidden.node_mut(id).unwrap().visible = false; + let off = ToolContext { revision: (0, 1), smart_guides: false, ..cx(&hidden, &s, &p) }; + offset(&mut t, &off); + assert_eq!(t.levels.len(), 1, "not read with Smart Guides off"); + let on = ToolContext { revision: (0, 1), ..cx(&hidden, &s, &p) }; + assert_eq!(offset(&mut t, &on), json!(-98.0), "read when Smart Guides are turned on"); + for (rev, edit) in [(1, "hidden"), (2, "locked"), (3, "deleted")] { + let mut doc = d.clone(); + match edit { + "hidden" => doc.node_mut(id).unwrap().visible = false, + "locked" => doc.node_mut(id).unwrap().locked = true, + _ => { + doc.remove(id).unwrap(); + } + } + let c = ToolContext { revision: (0, rev), ..cx(&doc, &s, &p) }; + assert_eq!(offset(&mut t, &c), json!(-98.0), "{edit}: off every level"); + } + let c = ToolContext { revision: (0, 4), ..cx(&d, &s, &p) }; + assert_eq!(offset(&mut t, &c), json!(-100.0), "shown again: on the level"); + // Grouped while it is placed, in a group with the id the preview takes: still a level. + let mut doc = d.clone(); + let moved = doc.remove(id).unwrap(); + let group = doc.alloc_id(); + doc.insert(Some(l), usize::MAX, Node::new(group, NodeKind::Group { children: vec![moved], clip: false })).unwrap(); + let c = ToolContext { revision: (0, 5), ..cx(&doc, &s, &p) }; + assert_eq!(offset(&mut t, &c), json!(-100.0), "grouped: on the level"); + // The dimension's own preview, which takes the next id and measures its points, is not a + // level. Another dimension that takes that id is. + let mut own = DimensionTool::default().recipe(DimensionMode::Linear, pt(400.0, 400.0), pt(450.0, 400.0), pt(425.0, 400.0), None); + own.place(pt(425.0, 304.0)); + assert_eq!(own.line_ends(), (pt(400.0, 304.0), pt(450.0, 304.0))); + for (rev, made, level) in [(6, Some(Box::new(own)), json!(-98.0)), (7, line(304.0), json!(-96.0))] { + let mut doc = d.clone(); + let mut preview = Node::new(doc.alloc_id(), NodeKind::Group { children: vec![], clip: false }); + preview.extras_mut().dimension = made; + doc.node_mut(id).unwrap().visible = false; + doc.insert(Some(l), usize::MAX, preview).unwrap(); + let c = ToolContext { revision: (0, rev), ..cx(&doc, &s, &p) }; + assert_eq!(offset(&mut t, &c), level, "revision {rev}"); + } + } + + /// The preview of the dimension itself does not count toward the 20,000 objects read: a + /// dimension that was the last one read stays a level once the preview is in front of it. + #[test] + fn the_preview_does_not_push_the_last_dimension_read_out_of_reach() { + use std::sync::Arc; + use vectorcraft_doc::{Node, NodeKind}; + let (mut d, _) = doc_with_rect(); + let pt = Point::new; + let line = |y: f64| Some(Box::new(DimensionTool::default().recipe(DimensionMode::Linear, pt(300.0, y), pt(400.0, y), pt(350.0, y), None))); + let mut drawn = Node::new(d.alloc_id(), NodeKind::Group { children: vec![], clip: false }); + drawn.extras_mut().dimension = line(300.0); + // The layer, the group and 19,997 empty groups before the dimension: it is the 20,000th. + let mut children = vec![Arc::new(drawn)]; + children.extend((0..19_997).map(|_| Arc::new(Node::new(d.alloc_id(), NodeKind::Group { children: vec![], clip: false })))); + let l = d.layers[0].id; + let group = Node::new(d.alloc_id(), NodeKind::Group { children, clip: false }); + d.insert(Some(l), usize::MAX, group).unwrap(); + let (s, p) = (Selection::default(), paint()); + let ev = |kind, x: f64, y: f64| PointerEvent::new(kind, x, y); + let offset = |t: &mut DimensionTool, c: &ToolContext| { + let acts = t.pointer(c, &ev(PointerKind::Move, 420.0, 302.0)); + let Some(Action::Preview(_, params)) = acts.last() else { panic!("{acts:?}") }; + params["offset"].clone() + }; + let mut t = DimensionTool::default(); + let c = cx(&d, &s, &p); + for (x, y) in [(400.0, 400.0), (450.0, 400.0)] { + t.pointer(&c, &ev(PointerKind::Down, x, y)); + t.pointer(&c, &ev(PointerKind::Up, x, y)); + } + assert!(matches!(t.pointer(&c, &ev(PointerKind::Move, 420.0, 450.0)).first(), Some(Action::Begin(_)))); + assert_eq!(offset(&mut t, &c), json!(-100.0), "the 20,000th object is read"); + let mut previewed = d.clone(); + let mut preview = Node::new(previewed.alloc_id(), NodeKind::Group { children: vec![], clip: false }); + preview.extras_mut().dimension = + Some(Box::new(DimensionTool::default().recipe(DimensionMode::Linear, pt(400.0, 400.0), pt(450.0, 400.0), pt(425.0, 304.0), None))); + previewed.insert(Some(l), usize::MAX, preview).unwrap(); + let c = ToolContext { revision: (0, 1), ..cx(&previewed, &s, &p) }; + assert_eq!(offset(&mut t, &c), json!(-100.0), "still read with the preview in front"); + } + #[test] fn a_dropped_placement_press_does_not_commit_the_dimension() { let (d, _) = doc_with_rect(); From d515b1fb961544d7750c054ffc47ed3aa1be46bc Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 12:30:12 -0800 Subject: [PATCH 4/7] Dimension tool: the dimension reads stop at the 20,000-object limit The walks that look for dimension ends and lines to snap to, and the dimension lines a linear dimension lines up with, stop going through the remaining layers and siblings once they have read 20,000 objects. --- crates/tools/src/dimension.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/tools/src/dimension.rs b/crates/tools/src/dimension.rs index 97801b50fe..12e8bdc458 100644 --- a/crates/tools/src/dimension.rs +++ b/crates/tools/src/dimension.rs @@ -270,6 +270,9 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { } } for c in n.children().into_iter().flatten().rev() { + if *budget == 0 { + return; + } lines(c, measured, p, reach, budget, best); } } @@ -284,6 +287,9 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { return; } for c in n.children().into_iter().flatten().rev() { + if *budget == 0 { + return; + } visit(c, p, reach, budget, best); } } @@ -292,6 +298,9 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { } let (reach, mut budget, mut best) = ([cx.tol(ANCHOR_REACH), cx.tol(8.0)], 20_000usize, Best::default()); for n in cx.doc.layers.iter().rev() { + if budget == 0 { + break; + } visit(n, p, reach, &mut budget, &mut best); } best.end.map(|(_, q)| (q, true)).or_else(|| best.line.map(|(_, q)| (q, false))) @@ -318,11 +327,17 @@ fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec Date: Wed, 18 Nov 2026 14:52:47 -0800 Subject: [PATCH 5/7] Dimension tool: a dimension locked while another is placed is no longer a level The engine test that runs commands while a linear dimension is placed now also locks the other dimension, as well as hiding and deleting it, and checks that no guide runs along its level. docs/dimensions.md says that layers and groups count toward the 20,000 objects the tool reads for levels. --- crates/engine/tests/it/dimensions.rs | 8 ++++---- docs/dimensions.md | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/crates/engine/tests/it/dimensions.rs b/crates/engine/tests/it/dimensions.rs index 45778fa350..c73fa8d0a6 100644 --- a/crates/engine/tests/it/dimensions.rs +++ b/crates/engine/tests/it/dimensions.rs @@ -2080,12 +2080,12 @@ fn a_dimension_of_the_same_points_lines_up_and_the_line_follows_the_pointer() { assert_eq!(recipe(&s, id).line_ends(), (pt(200.0, 186.0), pt(300.0, 186.0))); } -/// With Real-time Drawing off, a dimension hidden or deleted by a command while another is placed -/// is no longer a level: no guide runs along its level. +/// With Real-time Drawing off, a dimension hidden, locked or deleted by a command while another is +/// placed is no longer a level: no guide runs along its level. #[test] -fn a_dimension_hidden_or_deleted_while_another_is_placed_is_no_longer_a_level() { +fn a_dimension_hidden_locked_or_deleted_while_another_is_placed_is_no_longer_a_level() { let plain = ViewInfo::default(); - for cmd in ["object.hide", "edit.clear"] { + for cmd in ["object.hide", "object.lock", "edit.clear"] { let (mut s, first) = level_start(plain); run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": false})); linear_click(&mut s, plain, 200.0, 200.0); diff --git a/docs/dimensions.md b/docs/dimensions.md index 811a864ed0..e90e4ecf20 100644 --- a/docs/dimensions.md +++ b/docs/dimensions.md @@ -73,8 +73,9 @@ The **Dimension Tool** is in the Modify section of the toolbar. Its strip offers With Smart Guides on, a linear dimension placed with its line within the Smart Guides snapping tolerance of the level of a parallel line of a linear dimension already drawn has its line on that level. The other dimension, and every layer and group it is in, must be visible and - unlocked. The tool reads at most 20,000 visible, unlocked objects, from the frontmost back, so in - a larger document a dimension past them is not a level. This is VectorCraft's own rule. With + unlocked. The tool reads at most 20,000 visible, unlocked layers, groups and objects, from the + frontmost back, so in a larger document a dimension past them is not a level. This is + VectorCraft's own rule. With Alignment Guides on, a guide runs along the level across both lines while the dimension is placed. - **Angular:** hover a corner where two straight segments meet and drag outwards. Or click two From d3696410d88a4cccafb1070316dc99c1cfb816a5 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Wed, 18 Nov 2026 18:00:26 -0800 Subject: [PATCH 6/7] Dimension tool: levels come from the document the next preview applies to While a linear dimension is placed, each preview starts again from the document as the placement began. The tool now reads the lines of the other dimensions from that document (the new ToolContext field interaction_doc), not from the document a command changed in between, so a dimension that a command moves or hides and that the next preview puts back does not leave the placed dimension on a level the committed document does not have. The engine test now drags a dimension out, runs dimension.update or object.hide on the other dimension, releases, and checks the committed line against that dimension as the document has it. The tool test that checks which dimensions read lines also covers radius and diameter dimensions. --- crates/engine/src/tooling.rs | 1 + crates/engine/tests/it/dimensions.rs | 37 +++++++++++---- crates/tools/src/context.rs | 4 ++ crates/tools/src/dimension.rs | 70 +++++++++++++++++++++++++--- crates/tools/src/lib.rs | 1 + 5 files changed, 97 insertions(+), 16 deletions(-) diff --git a/crates/engine/src/tooling.rs b/crates/engine/src/tooling.rs index 65ea837527..0edf9f9a93 100644 --- a/crates/engine/src/tooling.rs +++ b/crates/engine/src/tooling.rs @@ -476,6 +476,7 @@ impl Session { plane_targets: self.prefs.perspective_widget.targets(), precise_cursors: self.precise_cursors(), global_edit: st.global_edit.as_ref().map_or(&[], |g| g.members.as_slice()), + interaction_doc: st.interaction.as_ref().map(|it| &*it.doc), }; let tool = &mut self.tool; match crate::guard::catch_panic(|| f(tool.as_mut(), &cx)) { diff --git a/crates/engine/tests/it/dimensions.rs b/crates/engine/tests/it/dimensions.rs index c73fa8d0a6..28417f031a 100644 --- a/crates/engine/tests/it/dimensions.rs +++ b/crates/engine/tests/it/dimensions.rs @@ -2080,19 +2080,36 @@ fn a_dimension_of_the_same_points_lines_up_and_the_line_follows_the_pointer() { assert_eq!(recipe(&s, id).line_ends(), (pt(200.0, 186.0), pt(300.0, 186.0))); } -/// With Real-time Drawing off, a dimension hidden, locked or deleted by a command while another is -/// placed is no longer a level: no guide runs along its level. +/// A command that moves or hides a dimension while another is placed (Real-time Drawing on) does +/// not leave the placed dimension on a level the committed document does not have: committed with +/// its line near the other dimension's line as the document has it then, it is on that level, and +/// otherwise at the pointer. #[test] -fn a_dimension_hidden_locked_or_deleted_while_another_is_placed_is_no_longer_a_level() { +fn a_dimension_placed_after_a_command_lines_up_with_the_committed_document() { let plain = ViewInfo::default(); - for cmd in ["object.hide", "object.lock", "edit.clear"] { + for (cmd, params, y) in [("dimension.update", json!({"offset": -10.0}), 192.0), ("object.hide", json!({}), 172.0)] { let (mut s, first) = level_start(plain); - run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": false})); - linear_click(&mut s, plain, 200.0, 200.0); - linear_click(&mut s, plain, 300.0, 200.0); - assert!(!guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: on the level before"); - run(&mut s, cmd, json!({"ids": [first]})); - assert!(guide_lines(&mut s, plain, 250.0, 172.5).is_empty(), "{cmd}: no level after"); + run(&mut s, "prefs.set", json!({"key": "realTimeDrawing", "value": true})); + // The bottom edge dragged out onto the level of the first line. + for (kind, y) in [(PointerKind::Move, 300.0), (PointerKind::Down, 300.0), (PointerKind::Drag, 240.0), (PointerKind::Drag, 172.0)] { + s.pointer(&PointerEvent::new(kind, 160.0, y), plain).unwrap(); + } + let mut params = params; + params["ids"] = json!([first]); + run(&mut s, cmd, params); + if cmd == "dimension.update" { + assert_eq!(recipe(&s, first).line_ends().0.y, 190.0, "moved before the release"); + } + // Released without a drag in between: the release places the dimension. + s.pointer(&PointerEvent::new(PointerKind::Up, 160.0, y), plain).unwrap(); + let placed = s.doc().unwrap().selection.objects[0].0; + assert_ne!(placed, first, "{cmd}: a new dimension"); + let reference = s.doc().unwrap().doc.node(NodeId(first)).map(|n| (n.visible, recipe(&s, first).line_ends().0.y)); + let expected = match reference { + Some((true, level)) if (level - y).abs() <= 4.0 => level, + _ => y, + }; + assert_eq!(recipe(&s, placed).line_ends().0.y, expected, "{cmd}: the other dimension is {reference:?}"); } } diff --git a/crates/tools/src/context.rs b/crates/tools/src/context.rs index 0946ad7a2d..21969a4f2e 100644 --- a/crates/tools/src/context.rs +++ b/crates/tools/src/context.rs @@ -350,6 +350,10 @@ pub struct ToolContext<'a> { /// The objects of the Global Edit in progress (Select › Start Global Edit), the one it started /// from first, each with its transform; empty while Global Edit is off. pub global_edit: &'a [(NodeId, vectorcraft_geom::Affine)], + /// While an interaction is in progress: the document as it was when the interaction began, + /// which each preview of the interaction replaces the document with before it applies. None + /// outside an interaction. + pub interaction_doc: Option<&'a Document>, } impl ToolContext<'_> { diff --git a/crates/tools/src/dimension.rs b/crates/tools/src/dimension.rs index 9d22d1f03e..a44a82a255 100644 --- a/crates/tools/src/dimension.rs +++ b/crates/tools/src/dimension.rs @@ -484,10 +484,10 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> { /// The line of a linear dimension already drawn: its ends and its direction. type DimensionLine = ((Point, Point), Vec2); -/// The lines of the visible, unlocked linear dimensions in the document, except the preview of the +/// The lines of the visible, unlocked linear dimensions in `doc`, except the preview of the /// dimension being placed: a dimension with the id `preview.0` that measures the points /// `preview.1`. Bounded work, as in [`on_dimensions`]. -fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec { +fn dimension_lines(doc: &vectorcraft_doc::Document, preview: (u64, [Point; 2])) -> Vec { fn visit(n: &Node, preview: (u64, [Point; 2]), budget: &mut usize, out: &mut Vec) { let is_preview = n.id.0 == preview.0 && n.extras().dimension.as_ref().is_some_and(|d| d.a.distance(preview.1[0]) < 1e-9 && d.b.distance(preview.1[1]) < 1e-9); @@ -509,7 +509,7 @@ fn dimension_lines(cx: &ToolContext, preview: (u64, [Point; 2])) -> Vec