mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-18 23:31:18 +00:00
Part of #5590: Dimension tool lines line up with dimensions already drawn
A linear dimension placed next to another one had its line exactly where the pointer was. Chained dimensions only lined up when the pointer hit the other line's level exactly, which at a normal zoom it rarely does. - 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 applies to two clicked points and to a segment dragged out. - With Alignment Guides on, a guide runs along that level across both lines while the dimension is placed. - Smart Guides off, a level further off, a locked dimension or one that is not parallel leaves the line where the pointer puts it. Docs: docs/dimensions.md, docs/target-app-parity.md.
This commit is contained in:
@@ -1933,6 +1933,91 @@ fn an_anchor_beside_a_drawn_dimension_takes_the_point() {
|
||||
assert_eq!(linear_marker(&mut s, zoomed, 125.5, 358.3), (Some((pt(126.0, 358.0), 10.0)), vec!["anchor".to_string()]));
|
||||
}
|
||||
|
||||
/// The Smart Guide lines a pointer move at (`x`, `y`) shows, as their ends.
|
||||
fn guide_lines(s: &mut Session, view: ViewInfo, x: f64, y: f64) -> Vec<(vectorcraft_geom::Point, vectorcraft_geom::Point)> {
|
||||
use vectorcraft_engine::tools::Overlay;
|
||||
s.pointer(&PointerEvent::new(PointerKind::Move, x, y), view).unwrap();
|
||||
s.overlays(view).into_iter().filter_map(|o| if let Overlay::Line { a, b, .. } = o { Some((a, b)) } else { None }).collect()
|
||||
}
|
||||
|
||||
/// A dimension placed next to another, with its line within the Smart Guides snapping tolerance of
|
||||
/// the level of the other's parallel line, has its line on that level, and an alignment guide
|
||||
/// runs across both lines while it is placed. A level further off, Smart Guides off, a locked
|
||||
/// dimension or one that is not parallel leaves the line where the pointer puts it. A dimension
|
||||
/// dragged out from a segment lands on the level too.
|
||||
#[test]
|
||||
fn a_dimension_line_placed_beside_another_lands_on_its_level() {
|
||||
let plain = ViewInfo::default();
|
||||
let off = ViewInfo { smart_guides: false, ..plain };
|
||||
let pt = vectorcraft_geom::Point::new;
|
||||
// An edge with anchors at x 100, 200 and 300, and a dimension from 100 to 200 placed 30 points
|
||||
// above it.
|
||||
let start = |view: ViewInfo| {
|
||||
let mut s = session();
|
||||
run(&mut s, "path.create", json!({"d": "M100 200 L200 200 L300 200 L300 300 L100 300 Z"}));
|
||||
run(&mut s, "select.none", json!({}));
|
||||
s.select_tool("dimension", view).unwrap();
|
||||
linear_click(&mut s, view, 100.0, 200.0);
|
||||
linear_click(&mut s, view, 200.0, 200.0);
|
||||
linear_click(&mut s, view, 150.0, 170.0);
|
||||
let first = s.doc().unwrap().selection.objects[0].0;
|
||||
assert_eq!(recipe(&s, first).line_ends(), (pt(100.0, 170.0), pt(200.0, 170.0)));
|
||||
run(&mut s, "select.none", json!({}));
|
||||
(s, first)
|
||||
};
|
||||
// The next dimension, from 200 to 300, placed with the pointer at `y`: where its line lies.
|
||||
let next = |s: &mut Session, view: ViewInfo, y: f64| {
|
||||
linear_click(s, view, 200.0, 200.0);
|
||||
linear_click(s, view, 300.0, 200.0);
|
||||
linear_click(s, view, 250.0, y);
|
||||
let id = s.doc().unwrap().selection.objects[0].0;
|
||||
recipe(s, id).line_ends()
|
||||
};
|
||||
// 2.5 points below the first line's level, and 3.5 above it: on the level.
|
||||
for y in [172.5, 166.5] {
|
||||
let (mut s, _) = start(plain);
|
||||
assert_eq!(next(&mut s, plain, y), (pt(200.0, 170.0), pt(300.0, 170.0)), "pointer at y {y}");
|
||||
}
|
||||
// While it is placed, one guide runs along the level from the first line's left end to the
|
||||
// new line's right end.
|
||||
let (mut s, _) = start(plain);
|
||||
linear_click(&mut s, plain, 200.0, 200.0);
|
||||
linear_click(&mut s, plain, 300.0, 200.0);
|
||||
let guides = guide_lines(&mut s, plain, 250.0, 172.5);
|
||||
assert!(guides.iter().any(|(a, b)| near(*a, pt(100.0, 170.0)) && near(*b, pt(300.0, 170.0))), "{guides:?}");
|
||||
assert!(guide_lines(&mut s, plain, 250.0, 180.0).is_empty(), "no guide off the level");
|
||||
// 10 points off: where the pointer is.
|
||||
let (mut s, _) = start(plain);
|
||||
assert_eq!(next(&mut s, plain, 180.0), (pt(200.0, 180.0), pt(300.0, 180.0)));
|
||||
// Smart Guides off: where the pointer is.
|
||||
let (mut s, _) = start(off);
|
||||
assert_eq!(next(&mut s, off, 172.5), (pt(200.0, 172.5), pt(300.0, 172.5)));
|
||||
// A locked dimension does not pull the line.
|
||||
let (mut s, first) = start(plain);
|
||||
run(&mut s, "select.set", json!({"ids":[first]}));
|
||||
run(&mut s, "object.lock", json!({}));
|
||||
assert_eq!(next(&mut s, plain, 172.5), (pt(200.0, 172.5), pt(300.0, 172.5)));
|
||||
// A dimension of the right edge has a vertical line, which is not parallel to the first: the
|
||||
// pointer 2.5 points below the first line's level places it where the pointer is.
|
||||
let (mut s, _) = start(plain);
|
||||
linear_click(&mut s, plain, 300.0, 200.0);
|
||||
linear_click(&mut s, plain, 300.0, 300.0);
|
||||
linear_click(&mut s, plain, 330.0, 172.5);
|
||||
let id = s.doc().unwrap().selection.objects[0].0;
|
||||
assert_eq!(recipe(&s, id).line_ends(), (pt(330.0, 200.0), pt(330.0, 300.0)));
|
||||
// The bottom edge dragged out to 2 points below the level of the first line, 130 points
|
||||
// above the edge: on the level.
|
||||
let (mut s, _) = start(plain);
|
||||
for (kind, y) in
|
||||
[(PointerKind::Move, 300.0), (PointerKind::Down, 300.0), (PointerKind::Drag, 240.0), (PointerKind::Drag, 172.0), (PointerKind::Up, 172.0)]
|
||||
{
|
||||
s.pointer(&PointerEvent::new(kind, 160.0, y), plain).unwrap();
|
||||
}
|
||||
let id = s.doc().unwrap().selection.objects[0].0;
|
||||
let (a, b) = recipe(&s, id).line_ends();
|
||||
assert!(near(a, pt(300.0, 170.0)) && near(b, pt(100.0, 170.0)) || near(a, pt(100.0, 170.0)) && near(b, pt(300.0, 170.0)), "{a:?} {b:?}");
|
||||
}
|
||||
|
||||
/// The page content streams of exported PDF `v`, inflated.
|
||||
fn pdf_content(v: &Value) -> String {
|
||||
let bytes = vectorcraft_format::base64_decode(v["dataBase64"].as_str().unwrap()).unwrap();
|
||||
|
||||
@@ -76,6 +76,9 @@ pub struct DimensionTool {
|
||||
/// for that click (a snap or Shift can move the point away from it): placed with the pointer
|
||||
/// still at either, it is aligned.
|
||||
second: Option<(Point, Point)>,
|
||||
/// 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)>,
|
||||
}
|
||||
|
||||
/// What a linear dimension between `a` and `b` measures with the pointer at `p` while it is
|
||||
@@ -285,6 +288,44 @@ fn on_dimensions(cx: &ToolContext, p: Point) -> Option<(Point, bool)> {
|
||||
best.end.map(|(_, q)| (q, true)).or_else(|| best.line.map(|(_, q)| (q, false)))
|
||||
}
|
||||
|
||||
/// Where the line of the linear dimension `d`, placed through `p`, lands on the level of the line
|
||||
/// of a visible, unlocked linear dimension already drawn that runs parallel to it, within `reach`
|
||||
/// of `p` across the line (the nearest level wins, then the nearest line): the point to place `d`
|
||||
/// through, and the ends of that other line. A dimension that measures the same two points as `d`
|
||||
/// is skipped, because the preview of `d` itself is one. Bounded work, as in [`on_dimensions`].
|
||||
fn line_level(cx: &ToolContext, d: &Dimension, p: Point, reach: f64) -> Option<(Point, (Point, Point))> {
|
||||
type Best = Option<(f64, f64, f64, (Point, Point))>;
|
||||
fn visit(n: &Node, d: &Dimension, p: Point, reach: f64, budget: &mut usize, best: &mut Best) {
|
||||
if *budget == 0 || !n.visible || n.locked {
|
||||
return;
|
||||
}
|
||||
*budget -= 1;
|
||||
if let Some(other) = &n.extras().dimension {
|
||||
let (u, normal) = (d.direction(), d.normal());
|
||||
if other.mode == DimensionMode::Linear && (other.a, other.b) != (d.a, d.b) && u.cross(other.direction()).abs() <= 1e-6 {
|
||||
let ends = other.line_ends();
|
||||
let shift = (ends.0 - p).dot(normal);
|
||||
let along = (ends.0 - p).dot(u).abs().min((ends.1 - p).dot(u).abs());
|
||||
if shift.is_finite() && shift.abs() <= reach && best.is_none_or(|(s, a, _, _)| (shift.abs(), along) < (s, a)) {
|
||||
*best = Some((shift.abs(), along, shift, ends));
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for c in n.children().into_iter().flatten().rev() {
|
||||
visit(c, d, p, reach, budget, best);
|
||||
}
|
||||
}
|
||||
if d.mode != DimensionMode::Linear {
|
||||
return None;
|
||||
}
|
||||
let (mut budget, mut best) = (20_000usize, None);
|
||||
for n in cx.doc.layers.iter().rev() {
|
||||
visit(n, d, p, reach, &mut budget, &mut best);
|
||||
}
|
||||
best.map(|(_, _, shift, ends)| (p + d.normal() * shift, ends))
|
||||
}
|
||||
|
||||
/// The point of `edge` closest to `p`.
|
||||
fn nearest_on(cx: &ToolContext, edge: &SegmentRef, p: Point) -> Option<Point> {
|
||||
use vectorcraft_geom::kurbo::ParamCurveNearest;
|
||||
@@ -435,6 +476,7 @@ impl DimensionTool {
|
||||
p
|
||||
}
|
||||
fn preview(&mut self, cx: &ToolContext, p: Point) -> Vec<Action> {
|
||||
self.level_guide = None;
|
||||
let Some(d) = &mut self.pending else { return vec![] };
|
||||
if matches!(d.mode, DimensionMode::Radius | DimensionMode::Diameter)
|
||||
&& let Some(Target::Radial { center, radius, .. }) = self.press.as_ref().and_then(|(_, t)| t.as_ref())
|
||||
@@ -462,10 +504,14 @@ impl DimensionTool {
|
||||
if d.resolve(cx.doc).is_err() {
|
||||
return vec![];
|
||||
}
|
||||
d.place(p);
|
||||
// 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.
|
||||
let level = if cx.smart_guides { line_level(cx, d, p, cx.tol(cx.snapping_tolerance)) } else { None };
|
||||
d.place(level.map_or(p, |(on_level, _)| on_level));
|
||||
if d.validate().is_err() {
|
||||
return vec![];
|
||||
}
|
||||
self.level_guide = level.map(|(_, ends)| ends);
|
||||
let mut actions = vec![];
|
||||
if !self.began {
|
||||
actions.push(Action::Begin("Create Dimension".into()));
|
||||
@@ -495,6 +541,7 @@ impl DimensionTool {
|
||||
self.snap.clear();
|
||||
self.snapped = None;
|
||||
self.second = None;
|
||||
self.level_guide = None;
|
||||
}
|
||||
/// A plain click: picks a point or a line, or measures a circle's radius.
|
||||
fn click(&mut self, cx: &ToolContext, p: Point, target: Option<Target>, mods: Mods) -> Vec<Action> {
|
||||
@@ -734,6 +781,21 @@ impl Tool for DimensionTool {
|
||||
if linear_pick {
|
||||
out.extend(self.snap.guides().iter().cloned());
|
||||
}
|
||||
// A dimension line placed on the level of another: one alignment guide across both lines,
|
||||
// unless Alignment Guides are off.
|
||||
if cx.alignment_guides
|
||||
&& let (Some(d), Some((c, e))) = (&self.pending, self.level_guide)
|
||||
{
|
||||
let (a, b) = d.line_ends();
|
||||
let u = d.direction();
|
||||
let along = |q: &Point| q.to_vec2().dot(u);
|
||||
let ends = [a, b, c, e];
|
||||
if let (Some(lo), Some(hi)) =
|
||||
(ends.iter().min_by(|p, q| along(p).total_cmp(&along(q))), ends.iter().max_by(|p, q| along(p).total_cmp(&along(q))))
|
||||
{
|
||||
out.push(Overlay::Line { a: *lo, b: *hi, color: cx.smart_guide_color, dashed: false });
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,11 @@ The **Dimension Tool** is in the Modify section of the toolbar. Its strip offers
|
||||
point as before. An unlinked dimension that
|
||||
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, so chained dimensions line up. 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
|
||||
|
||||
@@ -630,6 +630,7 @@ since 2026-10-01.
|
||||
**Drawing tools, Dimension tool points on a Smart Guide stay on the guide:** By VectorCraft's own rule, a clicked point that lies on a Smart Guide already, such as one in line with an object's center, stays where the pointer is when no anchor is within 8 pixels and no segment is within the Smart Guides snapping tolerance, instead of moving onto a segment farther than that tolerance and within 8 pixels; with Snap to Grid or Snap to Pixel on, a point stays on the grid or the whole pixel those options give. `a_point_on_a_guide_stays_on_the_guide` covers it.
|
||||
**Drawing tools, Dimension tool second point without construction guides through a first point off the anchors:** By VectorCraft's own rule, with Smart Guides on, the second Linear point does not snap to the construction guides through a first point that is not on an anchor, so a click beside a segment straight below such a first point lands on the segment; after a first point picked on an anchor, the construction guides through it still apply. The second point still snaps to anchors, centers and alignment lines, and with Snap to Perpendicular or Snap to Tangent on, it lands where the line from the first point meets a segment square or grazes a curve. `a_point_on_a_guide_stays_on_the_guide`, `the_second_point_after_an_anchor_lands_on_construction_guides`, `the_second_point_lands_square_to_a_segment_or_grazing_a_curve` and `linear_picks_show_and_snap_to_smart_guides` cover it.
|
||||
**Drawing tools, Dimension tool points land on dimensions already drawn (#8063):** By VectorCraft's own rule, with Smart Guides or Snap to Point on, a Linear point that no anchor of the art within 8 pixels takes lands on the end of a visible, unlocked dimension's dimension line, or on the far end of its extension line, within 8 pixels, and a point that nothing else places lands on the closest point of such a line within 8 pixels, so at any zoom a dimension can start where another one ends. The end of an extension line next to the point it measures does not pull points away from that anchor. With Smart Guides and Anchor/Path Labels on, a point on an anchor or line end shows the "anchor" label and a point on a segment or line shows the "path" label. `linear_picks_land_on_anchors_paths_and_drawn_dimensions` and `an_anchor_beside_a_drawn_dimension_takes_the_point` cover it.
|
||||
**Drawing tools, Dimension tool lines line up with dimensions already drawn (#8063, #5590):** By VectorCraft's own rule, 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, and with Alignment Guides on a guide runs along the level across both lines while it is placed. `a_dimension_line_placed_beside_another_lands_on_its_level` covers it.
|
||||
**Drawing tools, Dimension tool dimensions selected with their art keep their lines and label:** Object › Expand, Object › Expand Appearance and Object › Path › Outline Stroke leave a dimension selected with art it measures, directly or in selected groups without fills, strokes or effects of their own, as it is and change only the other art; when the new art no longer fits its link, the dimension stays where it was, no longer linked, and undo links it again. `expand_leaves_a_dimension_selected_with_its_art_as_it_is`, `expand_appearance_leaves_a_dimension_selected_with_its_art_as_it_is`, `outline_stroke_leaves_a_dimension_selected_with_its_art_as_it_is`, `a_dimension_selected_with_art_that_has_nothing_to_expand_changes_nothing`, `a_group_effect_expanded_reaches_the_dimension_it_holds`, `expand_keeps_a_dimension_in_its_asset_and_its_variable_binding`, `a_dimension_keeps_no_link_to_the_art_expand_replaced`, `a_dimension_outlasts_the_art_outline_stroke_or_expand_appearance_replaced`, `a_dimension_outlasts_the_stroke_expand_outlined` and `expand_appearance_in_safe_mode_leaves_a_dimension_selected_with_its_art` cover it.
|
||||
**Drawing tools, Line Segment from one curve onto a common tangent of another:** By VectorCraft's own rule, with Smart Guides and Snap to Tangent on, a Line Segment drag pressed anywhere on a convex closed path with curves and dragged to within the snapping tolerance of another such path lands on a common tangent of the two ([tangent lines to circles](https://en.wikipedia.org/wiki/Tangent_lines_to_circles)): both ends move to where the line touches the paths, the start sliding along the first path, and each end shows the "tangent" label when Anchor/Path Labels is on, with the line drawn as a guide when Alignment Guides is on. The line is the tangent whose touch point on the second path is nearest the pointer, so moving the pointer around the second path switches between the outer tangent and the one crossing between the paths. The start stays where it was pressed when Shift, Alt or Space is held, when an anchor, center or crossing lies nearer the pointer than the second path does, when the press snapped to an anchor, center or crossing off the first path, when Snap to Tangent is off, when Snap to Grid or pixel snapping places drawn points, or when either path bends inward somewhere or has more than 512 segments. `a_line_from_one_circle_to_another_lands_on_their_common_tangent`, `a_line_from_a_turned_ellipse_lands_on_its_tangent_with_a_circle`, `a_line_near_the_second_path_takes_the_tangent_touching_it_nearest`, `a_line_keeps_its_start_without_a_tangent_snap`, `a_line_to_a_crescent_or_from_an_anchor_beside_the_curve_keeps_its_start` and `a_line_segment_drag_draws_the_common_tangent_as_one_undo_step` cover it.
|
||||
**Live trace result bounds and selection highlights exclude the retained bitmap except in source-image views:** `live_trace_result_bounds_exclude_the_retained_bitmap_at_any_angle` checks every TraceView, geometric and visual bounds and rotated result bounds. `live_trace_selection_highlight_excludes_the_retained_source_rectangle` checks result highlights and the existing ordinary-group policy. Shared editing-child traversal also preserves Shaper handling.
|
||||
|
||||
Reference in New Issue
Block a user