Three-Point Arc: join arcs to open path ends and snap to carry a path on

The Three-Point Arc tool gets two options in its Tool Options:

- Join to Open Path Ends (`join`, off by default; J switches it while
  the ends are placed): an end placed within 5 screen points of an end
  of an open path lands on it, and the arc is joined to that path. The
  path keeps its look and, when one end joins, its direction. With both
  ends on open path ends the two paths become one, or the path closes
  when both are its own ends. It is one undo step.
- Snap Where the Arc Continues a Path (`tangentSnap`, on by default): in
  direction mode, when the direction line starts on an end of an open
  path, a third point near the line along which the arc carries the
  path on, the same way or turned back, snaps onto it, and the tool
  shows the line dashed.

`shape.threePointArc` takes `join: true` for the same join; it picks a
path in the selection first, then the front one, and in isolation mode
only paths inside the isolated group.
This commit is contained in:
dotCooCoo committed 2026-11-28 04:34:06 -08:00
1 parent 3d88485fa6
commit 48a0c6017e
10 files changed
+646 -35

No files matched your search

+1
View File
@@ -174,6 +174,7 @@ Ranked; detail in [docs/roadmap.md](docs/roadmap.md) and [docs/gaps.md](docs/gap
- 2026-11-18: Common Tangents also takes a point (a path of one anchor) and a convex closed path: the lines from the point that touch the path, and the line from the point to the path's center if asked; a point on the outline gets the one tangent there, and a point inside gets none, with a message (#7846). A VectorCraft addition: headline numbers unchanged.
- 2026-11-15: With Smart Guides and Snap to Tangent on, a Line Segment drag pressed on one convex curved path and dragged near another lands on a common tangent of the two: both ends move to where the line touches the paths, each labeled "tangent" (#7845). A VectorCraft addition: headline numbers unchanged.
- 2026-11-17: Three-Point Arc tool, in the Line Segment tool's group after the Arc tool: two ends placed by a drag or two clicks, then a third point the open circular arc passes through, or with Third Point Sets Direction (Tool Options, or `]` while drawing) the direction the arc leaves an end in; it previews the arc, its center and, with Measurement Labels on, its radius, and draws it in one undo step (`shape.threePointArc`). Points with no arc are refused with a message. A VectorCraft addition: headline numbers unchanged.
- 2026-11-28: The Three-Point Arc tool joins an arc to the open paths whose ends its ends are placed on, with Join to Open Path Ends (Tool Options, or J while drawing; `shape.threePointArc` `join`), and in direction mode snaps the third point to where the arc carries an open path on, the same way or turned back (Snap Where the Arc Continues a Path, on by default). Headline numbers unchanged.
- 2026-11-15: Smooth Bridge joins the Path Precision Tools add-on (Object › Plug-ins › Path Precision Tools): two selected circles become one closed outline joined by two concave arcs that touch both circles, so every anchor is smooth; the arcs' radius is a percentage of the smaller circle's radius (1 to 1000%, 100% by default), and Keep Originals adds the outline above the circles instead of replacing them. A dialog with Preview, one undo step (`addon.pathtools.bridge`). A VectorCraft addition: headline numbers unchanged.
- 2026-11-18: Smooth Bridge also joins three or more circles: every two whose outlines are within Reach (10 pt by default) are joined, the bridges that connect become one shape each, and a circle bridged to no other stays as it is (at most 2000 circles); with Constant Gap the arcs' radius is the smaller circle's radius plus a gap (#8030). A VectorCraft addition: headline numbers unchanged.
- 2026-11-03: Text Tweaker, the first tool of the Type Tools add-on (Object › Plug-ins › Type Tools): one character attribute (size, baseline shift, rotation, horizontal or vertical scale, tracking, leading or stroke weight) goes letter by letter from a start value to an end value along a straight ramp, an ease, a bow, a spike or at random with a seed, set as the Character panel sets it, while the text stays live; a dialog with Preview, one undo step (`addon.type.textTweaker`, #4924). A VectorCraft addition: headline numbers unchanged.
+27 -2
View File
@@ -110,7 +110,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Three-Point Arc",
[],
None,
"{start: [x, y], end: [x, y], through?: [x, y], toward?: [x, y], at?: \"start\"|\"end\" (default \"start\"; only with `toward`)} → {id, cx, cy, radius, sweep}: an open circular arc from `start` to `end` in the current stroke (black when it is none) with no fill, its ends exactly at the two points (not pixel-aligned). With `through`, the arc passes through that point, an anchor of the path; with `toward`, it leaves the end `at` names heading toward that point (its tangent there). Give exactly one of `through` and `toward`; `at` with `through` is an error. `sweep` is the arc's turn in degrees, positive clockwise on the page. Two points that are the same, three on one line, or an arc reaching past the canvas are an error, and nothing is drawn",
"{start: [x, y], end: [x, y], through?: [x, y], toward?: [x, y], at?: \"start\"|\"end\" (default \"start\"; only with `toward`), join?: bool (default false)} → {id, cx, cy, radius, sweep, joined?}: an open circular arc from `start` to `end` in the current stroke (black when it is none) with no fill, its ends exactly at the two points (not pixel-aligned). With `through`, the arc passes through that point, an anchor of the path; with `toward`, it leaves the end `at` names heading toward that point (its tangent there). Give exactly one of `through` and `toward`; `at` with `through` is an error. `sweep` is the arc's turn in degrees, positive clockwise on the page. With `join`, an end of the arc on an end of an editable open path (inside the isolated group in isolation mode) joins the arc to that path, which keeps its look and, when one end joins, its direction (a path in the selection comes first); with both ends on open path ends the second path joins too, or the path closes when both are its own ends. The result then has `joined: true` and `id` is the joined path (or its compound path). A `join` that is not true or false is an error. Two points that are the same, three on one line, or an arc reaching past the canvas are an error, and nothing is drawn",
has_doc,
three_point_arc
),
@@ -747,7 +747,8 @@ fn arc(s: &mut Session, p: &Value) -> Result<Value> {
}
/// An open circular arc from `start` to `end` ([`shapes::CircularArc`]): through `through`, or
/// leaving the end `at` names toward `toward`. One undo step, named as an Arc tool drag is.
/// leaving the end `at` names toward `toward`. With `join`, joined to the open paths whose ends
/// its ends lie on ([`super::path::join_arc`]). One undo step, named as an Arc tool drag is.
fn three_point_arc(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "shape.threePointArc";
let point = |key: &str| finite_numbers::<2>(&p[key]).map(|[x, y]| Point::new(x, y)).ok_or_else(|| bad(C, format!("`{key}` must be [x, y]")));
@@ -774,8 +775,32 @@ fn three_point_arc(s: &mut Session, p: &Value) -> Result<Value> {
}
_ => return Err(bad(C, "give exactly one of `through` and `toward`")),
};
let join = match p.get("join") {
None => false,
Some(Value::Bool(on)) => *on,
Some(_) => return Err(bad(C, "`join` must be true or false")),
};
let arc = arc.ok_or_else(|| bad(C, "no arc fits these points: two are the same or all three lie on one line"))?;
let path = via.map_or_else(|| arc.to_path(), |v| arc.to_path_via(v));
let ends = if join {
let st = s.doc()?;
let selected = st.selection.objects.clone();
let find = |at| super::path::open_end_at(&st.doc, st.isolation, &selected, at);
(find(start), find(end))
} else {
(None, None)
};
if ends.0.is_some() || ends.1.is_some() {
let sub = path.subpaths.first().cloned().ok_or_else(|| bad(C, "no arc fits these points"))?;
let id = s.edit("Arc", |d, sel| {
let id = super::path::join_arc(d, &sub, ends.0, ends.1)?;
sel.set([id]);
Ok(id)
})?;
return Ok(
json!({ "id": id.0, "joined": true, "cx": arc.center.x, "cy": arc.center.y, "radius": arc.radius, "sweep": arc.sweep.to_degrees() }),
);
}
let look = s.new_art_look(
vectorcraft_color::Paint::None,
if s.paint.stroke.is_none() { vectorcraft_color::Paint::solid(vectorcraft_color::Color::BLACK) } else { s.paint.stroke.clone() },
+85
View File
@@ -1504,6 +1504,91 @@ fn join_pair(d: &mut Document, (a, sa): (NodeId, usize), (b, sb): (NodeId, usize
Ok(compound_or_self(d, a))
}
/// An end of an open subpath of an editable path (not a guide) at `at`: the path, the subpath and
/// whether the end is the subpath's first anchor. In isolation mode (`scope`), only a path inside
/// the isolated node counts. Among several, one in or inside the selection `selected` comes first,
/// then the last in paint order.
pub(super) fn open_end_at(d: &Document, scope: Option<NodeId>, selected: &[NodeId], at: Point) -> Option<(NodeId, usize, bool)> {
let editable = d.editable();
let mut found: Option<((NodeId, usize, bool), bool)> = None;
d.walk(|n| {
let NodeKind::Path { path, guide: false, .. } = &n.kind else { return };
if !editable(n.id) {
return;
}
let chain = d.ancestry(n.id).unwrap_or_default();
if scope.is_some_and(|s| !chain.contains(&s)) {
return;
}
let chosen = chain.iter().any(|id| selected.contains(id));
for (si, sp) in path.subpaths.iter().enumerate().filter(|(_, sp)| !sp.closed) {
let Some((first, last)) = end_points(sp) else { continue };
let end = if last.distance(at) < 1e-6 {
false
} else if first.distance(at) < 1e-6 {
true
} else {
continue;
};
if found.is_none_or(|(_, was)| chosen || !was) {
found = Some(((n.id, si, end), chosen));
}
}
});
found.map(|(end, _)| end)
}
/// `sp`, an open subpath whose end (its first anchor when `at_first`) lies on an end of `arc`
/// (its first anchor when `arc_at_start`), with `arc` added there: one subpath running the way
/// `sp` runs. The anchor where they meet is `sp`'s, with its handle on the arc's side taken from
/// the arc.
fn splice(sp: &SubPath, at_first: bool, arc: &SubPath, arc_at_start: bool) -> SubPath {
let mut arc = arc.clone();
if arc_at_start == at_first {
arc.reverse();
}
let mut out = sp.clone();
if at_first {
let meet = arc.anchors.pop();
if let (Some(meet), Some(first)) = (meet, out.anchors.first_mut()) {
first.h_in = meet.h_in;
}
arc.anchors.extend(out.anchors);
out.anchors = arc.anchors;
} else {
if !arc.anchors.is_empty() {
let meet = arc.anchors.remove(0);
if let Some(last) = out.anchors.last_mut() {
last.h_out = meet.h_out;
}
}
out.anchors.extend(arc.anchors);
}
out
}
/// The arc `arc` joined to the open path ends `start` (at its first anchor) and `end` (at its
/// last), as [`open_end_at`] gives them, at least one of them. The arc joins the path at `start`
/// first, keeping that path's direction and look, and then, when `end` is an end of another open
/// subpath, that subpath joins it as Join joins two paths; when `end` is the other end of the same
/// subpath, the subpath closes. Returns what to select: the joined path, or its compound path.
pub(super) fn join_arc(d: &mut Document, arc: &SubPath, start: Option<(NodeId, usize, bool)>, end: Option<(NodeId, usize, bool)>) -> Result<NodeId> {
let err = || EngineError::Other("join needs open paths".into());
let ((id, si, at_first), arc_at_start, rest) = match (start, end) {
(Some(s), e) => (s, true, e),
(None, Some(e)) => (e, false, None),
(None, None) => return Err(err()),
};
let path = path_mut(d, id)?;
let sp = path.subpaths.get_mut(si).filter(|sp| !sp.closed && !sp.anchors.is_empty()).ok_or_else(err)?;
*sp = splice(sp, at_first, arc, arc_at_start);
match rest {
// The arc's far end is the first anchor of the joined subpath when it was added before it.
Some((other, osi, other_first)) => join_pair(d, (id, si), (other, osi), (at_first, !other_first), None),
None => Ok(compound_or_self(d, id)),
}
}
pub(super) type AnchorTargets = Vec<(NodeId, Vec<(usize, usize)>)>;
pub(super) fn anchor_targets(s: &Session) -> Result<AnchorTargets> {
+174
View File
@@ -217,4 +217,178 @@ fn set_option_sets_the_direction_and_refuses_bad_values() {
assert_eq!(s.set_tool_option_cmd(&p).unwrap_err(), want, "{p}");
}
assert_eq!(s.tool_options_of("threePointArc")["direction"], json!(false));
// `join` starts off and `tangentSnap` on; both take only true or false.
assert_eq!(
(s.tool_options_of("threePointArc")["join"].clone(), s.tool_options_of("threePointArc")["tangentSnap"].clone()),
(json!(false), json!(true))
);
let set = s.set_tool_option_cmd(&json!({"tool": "threePointArc", "values": {"join": true, "tangentSnap": false}})).unwrap();
assert_eq!((set["join"].clone(), set["tangentSnap"].clone()), (json!(true), json!(false)));
for key in ["join", "tangentSnap"] {
let e = s.set_tool_option_cmd(&json!({"tool": "threePointArc", "key": key, "value": 1})).unwrap_err();
assert_eq!(e, format!("tool `threePointArc`: `{key}` must be true or false"));
}
}
/// An open path drawn from SVG path data, selected.
fn open_path(s: &mut Session, d: &str) -> NodeId {
id_of(&s.execute("path.create", &json!({ "d": d })).unwrap())
}
/// The anchors of the first subpath of `id`, and whether it is closed.
fn anchors(s: &Session, id: NodeId) -> (Vec<Point>, bool) {
let n = node(s, id);
let sp = &n.path_data().unwrap().subpaths[0];
(sp.anchors.iter().map(|a| a.p).collect(), sp.closed)
}
/// With `join`, an arc starting on the last anchor of an open path is added to that path: the path
/// keeps its id and direction and now ends where the arc ends, the anchor where they meet is not
/// doubled, and it is one undo step. An arc ending on a path's first anchor is added before it.
#[test]
fn join_adds_the_arc_to_the_open_path_it_starts_on() {
let mut s = session();
let id = open_path(&mut s, "M0 100 L100 100");
let (undo, count) = (undo_len(&s), object_count(&s));
let out = s.execute(C, &json!({"start": [100, 100], "end": [180, 100], "through": [140, 60], "join": true})).unwrap();
assert_eq!((id_of(&out), out["joined"].clone(), out["radius"].as_f64()), (id, json!(true), Some(40.0)), "{out}");
assert_eq!((undo_len(&s), object_count(&s)), (undo + 1, count));
let (pts, closed) = anchors(&s, id);
assert!(!closed);
assert_eq!((pts.first().copied(), pts.last().copied()), (Some(Point::new(0.0, 100.0)), Some(Point::new(180.0, 100.0))), "{pts:?}");
assert_eq!(pts.iter().filter(|p| **p == Point::new(100.0, 100.0)).count(), 1, "{pts:?}");
assert!(farthest_from_path(&s, id, &[Point::new(140.0, 60.0), Point::new(50.0, 100.0)]) < 1e-9);
assert_eq!(s.doc().unwrap().selection.objects, [id]);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!(anchors(&s, id).0, [Point::new(0.0, 100.0), Point::new(100.0, 100.0)]);
// The arc ends on the first anchor of a path running right: the path still runs right, from
// the arc's start.
let id = open_path(&mut s, "M300 100 L400 100");
let out = s.execute(C, &json!({"start": [220, 100], "end": [300, 100], "toward": [220, 60], "join": true})).unwrap();
assert_eq!(id_of(&out), id);
let (pts, _) = anchors(&s, id);
assert_eq!((pts.first().copied(), pts.last().copied()), (Some(Point::new(220.0, 100.0)), Some(Point::new(400.0, 100.0))), "{pts:?}");
assert!(farthest_from_path(&s, id, &[Point::new(260.0, 60.0)]) < 1e-9);
}
/// With both ends on ends of two open paths, the arc joins them into one path in one undo step;
/// with both ends on the two ends of one open path, the path closes.
#[test]
fn join_with_both_ends_on_open_paths_makes_one_path() {
let mut s = session();
let a = open_path(&mut s, "M0 100 L100 100");
let b = open_path(&mut s, "M180 100 L280 100");
let (undo, count) = (undo_len(&s), object_count(&s));
let out = s.execute(C, &json!({"start": [100, 100], "end": [180, 100], "through": [140, 60], "join": true})).unwrap();
assert_eq!(id_of(&out), a);
assert_eq!((undo_len(&s), object_count(&s)), (undo + 1, count - 1));
assert!(s.doc().unwrap().doc.node(b).is_none());
let (pts, closed) = anchors(&s, a);
assert!(!closed);
let ends = (pts.first().copied(), pts.last().copied());
assert!(
ends == (Some(Point::new(0.0, 100.0)), Some(Point::new(280.0, 100.0)))
|| ends == (Some(Point::new(280.0, 100.0)), Some(Point::new(0.0, 100.0))),
"{pts:?}"
);
for p in [Point::new(100.0, 100.0), Point::new(180.0, 100.0)] {
assert_eq!(pts.iter().filter(|q| **q == p).count(), 1, "{pts:?}");
}
assert!(farthest_from_path(&s, a, &[Point::new(140.0, 60.0), Point::new(230.0, 100.0)]) < 1e-9);
s.execute("edit.undo", &json!({})).unwrap();
assert_eq!((object_count(&s), anchors(&s, b).0.len()), (count, 2));
// One path's two ends: it closes.
let id = open_path(&mut s, "M100 300 L180 300");
let out = s.execute(C, &json!({"start": [180, 300], "end": [100, 300], "through": [140, 340], "join": true})).unwrap();
assert_eq!(id_of(&out), id);
let (pts, closed) = anchors(&s, id);
assert!(closed, "{pts:?}");
assert_eq!(pts.iter().filter(|q| **q == Point::new(100.0, 300.0)).count(), 1, "{pts:?}");
assert!(farthest_from_path(&s, id, &[Point::new(140.0, 340.0), Point::new(140.0, 300.0)]) < 1e-9);
}
/// Of two open path ends at the arc's start, `join` takes the one in the selection, and with
/// neither selected the one in front.
#[test]
fn join_prefers_the_selected_path_then_the_front_one() {
let mut s = session();
let back = open_path(&mut s, "M0 100 L100 100");
let front = open_path(&mut s, "M100 200 L100 100");
for (selected, want) in [(Some(back), back), (None, front)] {
let ids: Vec<u64> = selected.iter().map(|id| id.0).collect();
s.execute("select.set", &json!({ "ids": ids })).unwrap();
let out = s.execute(C, &json!({"start": [100, 100], "end": [180, 100], "through": [140, 60], "join": true})).unwrap();
assert_eq!(id_of(&out), want, "{selected:?}");
s.execute("edit.undo", &json!({})).unwrap();
}
// In isolation mode, a path outside the isolated group is left alone.
s.execute("select.set", &json!({ "ids": [back.0] })).unwrap();
let group = s.execute("object.group", &json!({})).unwrap()["id"].as_u64().unwrap();
s.execute("object.isolate", &json!({ "id": group })).unwrap();
s.execute("select.set", &json!({ "ids": [] })).unwrap();
let out = s.execute(C, &json!({"start": [100, 100], "end": [100, 20], "through": [60, 60], "join": true})).unwrap();
assert_eq!(id_of(&out), back, "{out}");
s.execute("edit.undo", &json!({})).unwrap();
let out = s.execute(C, &json!({"start": [100, 200], "end": [180, 200], "through": [140, 160], "join": true})).unwrap();
assert!(out.get("joined").is_none(), "{out}");
assert_eq!(anchors(&s, front).0.len(), 2);
}
/// Without `join`, away from open path ends, on a locked path, or on a closed path's anchor, the
/// arc is a new path; a `join` that is not true or false is an error and draws nothing.
#[test]
fn join_leaves_paths_it_cannot_join_alone() {
let mut s = session();
let line = open_path(&mut s, "M0 100 L100 100");
let rect = open_path(&mut s, "M200 200 L300 200 L300 300 Z");
let arc = |s: &mut Session, start: [f64; 2], end: [f64; 2], via: [f64; 2], join: Value| {
s.execute(C, &json!({"start": start, "end": end, "through": via, "join": join}))
};
for (start, end, via, join) in [
([100.0, 100.0], [180.0, 100.0], [140.0, 60.0], json!(false)),
([100.0, 120.0], [180.0, 120.0], [140.0, 80.0], json!(true)),
([200.0, 200.0], [120.0, 200.0], [160.0, 160.0], json!(true)),
] {
let count = object_count(&s);
let out = arc(&mut s, start, end, via, join.clone()).unwrap();
assert!(out.get("joined").is_none() && id_of(&out) != line && id_of(&out) != rect, "{join}: {out}");
assert_eq!(object_count(&s), count + 1);
}
assert_eq!(anchors(&s, line).0.len(), 2);
s.execute("select.set", &json!({"ids": [line.0]})).unwrap();
s.execute("object.lock", &json!({})).unwrap();
// On the line's other end, where none of the arcs above ends.
let out = arc(&mut s, [0.0, 100.0], [0.0, 180.0], [40.0, 140.0], json!(true)).unwrap();
assert!(out.get("joined").is_none(), "{out}");
assert_eq!(anchors(&s, line).0.len(), 2);
let count = object_count(&s);
let e = arc(&mut s, [100.0, 300.0], [180.0, 300.0], [140.0, 260.0], json!("yes")).unwrap_err().to_string();
assert!(e.contains("`join` must be true or false"), "{e}");
assert_eq!(object_count(&s), count);
}
/// With the tool's `join` option on, clicks near an open path's end place the arc's end on it and
/// the arc joins the path; with it off the arc is a path of its own, and J while the ends are
/// placed switches it on.
#[test]
fn the_tool_joins_the_arc_to_the_path_end_it_starts_near() {
let mut s = session();
let id = open_path(&mut s, "M0 100 L100 100");
s.execute("select.set", &json!({"ids": []})).unwrap();
s.select_tool("threePointArc", view()).unwrap();
let count = object_count(&s);
for p in [(100.0, 100.0), (180.0, 100.0), (140.0, 60.0)] {
click(&mut s, p.0, p.1);
}
assert_eq!((object_count(&s), anchors(&s, id).0.len()), (count + 1, 2), "off: a path of its own");
s.execute("edit.undo", &json!({})).unwrap();
// J after the first click, near the path's end, switches `join` on.
click(&mut s, 99.0, 100.5);
s.tool_key(ToolKey::Letter('j'), Mods::default(), view()).unwrap();
click(&mut s, 180.0, 100.0);
click(&mut s, 140.0, 60.0);
assert_eq!(object_count(&s), count);
let (pts, _) = anchors(&s, id);
assert_eq!((pts.len() > 2, pts.last().copied()), (true, Some(Point::new(180.0, 100.0))), "{pts:?}");
assert_eq!(s.tool_options_of("threePointArc")["join"], json!(true), "J keeps the option switched");
}
+1 -1
View File
@@ -51,7 +51,7 @@ const ROWS: &[Row] = &[
(&["mirrorCut"], None, &["axis", "keep"]),
(&["puppetWarp"], None, &["showMesh", "expand"]),
(&["arc"], None, &["closed", "lengthX", "lengthY", "reference", "baseAlong", "slope", "fillArc"]),
(&[crate::three_point_arc::ID], None, &["direction"]),
(&[crate::three_point_arc::ID], None, &["direction", "join", "tangentSnap"]),
(&["spiral"], None, &["decay", "segments", "clockwise"]),
// The grids' Tool Options: the dividers and switches the drag uses, the Default Size and
// Reference Point a click's dialog opens with.
+207 -21
View File
@@ -8,6 +8,11 @@
//! the second end along the line from that end to the point, and Shift keeps the line at 45°
//! steps). `direction` is set in the tool's Tool Options and kept with the preferences; `]` (with
//! or without Shift) switches it while the ends are placed. Every point snaps to Smart Guides.
//! With the `join` option on (Tool Options, or J while the ends are placed), an end placed within
//! reach of an end of an open path lands on it, and the arc is joined to that path. With
//! `tangentSnap` on (the default), in direction mode, when the direction line starts at an end of
//! an open path, the third point snaps onto the line along which the arc carries on the path, the
//! same way or turned back, and the tool shows that line dashed.
//! Until the third point is placed, the tool shows the arc as a dashed outline with its ends, its
//! center as a small cross, the direction line in direction mode and, with Measurement Labels on,
//! the radius by the pointer. Where no arc fits (the third point lies on the line through the
@@ -17,9 +22,9 @@
//! the ends; a second click on the first end (a double-click) places nothing.
use serde_json::{Value, json};
use vectorcraft_doc::MAX_COORD;
use vectorcraft_doc::{MAX_COORD, NodeKind};
use vectorcraft_geom::shapes::CircularArc;
use vectorcraft_geom::{PathData, Point, Vec2};
use vectorcraft_geom::{PathData, Point, SubPath, Vec2};
use crate::guides::{DrawSnap, Leave};
use crate::{Action, Cursor, Mods, Overlay, PointerEvent, PointerKind, Tool, ToolContext, ToolKey};
@@ -34,6 +39,12 @@ const CROSS_PX: f64 = 4.0;
const REACH_PX: f64 = 3.0;
/// The label the tool shows by the pointer where no arc fits.
pub const TOO_LARGE: &str = "Arc too large";
/// How near (screen points) an end of an open path an end of the arc counts as on it, the Pen's
/// reach for the path ends it joins.
const END_PX: f64 = 5.0;
/// How near (screen points) the line along which the arc carries on an open path the third point
/// snaps onto it.
const TANGENT_PX: f64 = 5.0;
/// The press in progress.
#[derive(Clone, Copy, Debug, PartialEq)]
@@ -47,16 +58,82 @@ enum Press {
Third,
}
#[derive(Default)]
/// An end of an open path under an end of the arc: where it is, and the direction a path carrying
/// on from it heads in (none for a path of one anchor).
#[derive(Clone, Copy, Debug, PartialEq)]
struct OpenEnd {
at: Point,
out: Option<Vec2>,
}
/// The end of an open subpath of an editable path (not a guide) within reach of `p`.
fn open_end(cx: &ToolContext, p: Point) -> Option<OpenEnd> {
let tol = cx.tol(END_PX).max(cx.point_tol());
let editable = cx.doc.editable();
// The nearest end; among ends equally near, as `shape.threePointArc`'s `join` picks among the
// ends at a point: one in the selection first, then the last in paint order, and of one
// subpath's two ends its last anchor.
let mut best: Option<(OpenEnd, f64, bool)> = None;
cx.doc.walk(|n| {
let NodeKind::Path { path, guide: false, .. } = &n.kind else { return };
if !editable(n.id) {
return;
}
// In isolation mode, only art inside the isolated node.
let chain = cx.doc.ancestry(n.id).unwrap_or_default();
if cx.isolation.is_some_and(|s| !chain.contains(&s)) {
return;
}
let chosen = chain.iter().any(|id| cx.selection.objects.contains(id));
for sp in path.subpaths.iter().filter(|sp| !sp.closed) {
let ends = [false, true].map(|at_first| end_of(sp, at_first));
let near = match ends {
[Some(last), Some(first)] => Some(if last.at.distance(p) <= first.at.distance(p) { last } else { first }),
[last, first] => last.or(first),
};
let Some(e) = near else { continue };
let d = e.at.distance(p);
if d <= tol && best.is_none_or(|(_, bd, was)| d < bd || (d == bd && (chosen || !was))) {
best = Some((e, d, chosen));
}
}
});
best.map(|(e, _, _)| e)
}
/// The end of the open subpath `sp` (its first anchor when `at_first`), with the direction a path
/// carrying on from it heads in.
fn end_of(sp: &SubPath, at_first: bool) -> Option<OpenEnd> {
let n = sp.anchors.len();
let (end, next) =
if at_first { (sp.anchors.first()?, sp.anchors.get(1)) } else { (sp.anchors.last()?, n.checked_sub(2).and_then(|i| sp.anchors.get(i))) };
// The path reaches the end along the first of its control points that is off the end.
let mut back = vec![if at_first { end.h_out } else { end.h_in }];
if let Some(q) = next {
back.extend([if at_first { q.h_in } else { q.h_out }, q.p]);
}
let out = back.into_iter().map(|q| end.p - q).find(|v| v.hypot() > 0.0).map(|v| v / v.hypot());
Some(OpenEnd { at: end.p, out })
}
pub struct ThreePointArcTool {
snap: DrawSnap,
/// The third point gives the arc's direction at an end instead of a point it passes through.
direction: bool,
/// An end of the arc on an end of an open path joins the arc to that path.
join: bool,
/// In direction mode, the third point snaps to where the arc carries on the open path its
/// direction line starts at, the same way or turned back.
tangent_snap: bool,
start: Option<Point>,
end: Option<Point>,
/// The open path ends found under the first and the second end as each was placed.
open: [Option<OpenEnd>; 2],
press: Option<Press>,
/// Where the pointer is, snapped: the point the next press or release places.
pointer: Option<Point>,
/// The line the third point snapped to: the end it runs through and its direction.
tangent: Option<(Point, Vec2)>,
/// Alt was held at the last pointer event: in direction mode, the direction is at the second end.
at_end: bool,
/// Where the pointer was at its last event, pressed or hovering, before snapping, and the keys
@@ -64,6 +141,25 @@ pub struct ThreePointArcTool {
raw: Option<(Point, Mods)>,
}
impl Default for ThreePointArcTool {
fn default() -> Self {
Self {
snap: DrawSnap::default(),
direction: false,
join: false,
tangent_snap: true,
start: None,
end: None,
open: [None; 2],
press: None,
pointer: None,
tangent: None,
at_end: false,
raw: None,
}
}
}
/// The arc from `start` to `end` shaped by `third`, as `shape.threePointArc` draws it: through
/// `third`, or with `direction`, heading toward `third` from `start` (or, with `at_end`, arriving
/// at `end` along the line from `end` to `third`). None where no arc fits or the arc would reach
@@ -81,14 +177,18 @@ pub fn arc_of(start: Point, end: Point, third: Point, direction: bool, at_end: b
on_canvas.then_some((arc, path))
}
/// The command the tool runs for the arc from `start` to `end` shaped by `third`.
fn command(start: Point, end: Point, third: Point, direction: bool, at_end: bool) -> (String, Value) {
/// The command the tool runs for the arc from `start` to `end` shaped by `third`, joined to the
/// open paths at its ends with `join`.
fn command(start: Point, end: Point, third: Point, direction: bool, at_end: bool, join: bool) -> (String, Value) {
let pair = |p: Point| json!([p.x, p.y]);
let params = if direction {
let mut params = if direction {
json!({ "start": pair(start), "end": pair(end), "toward": pair(third), "at": if at_end { "end" } else { "start" } })
} else {
json!({ "start": pair(start), "end": pair(end), "through": pair(third) })
};
if join {
params["join"] = json!(true);
}
("shape.threePointArc".into(), params)
}
@@ -96,11 +196,37 @@ impl ThreePointArcTool {
fn clear(&mut self) {
self.start = None;
self.end = None;
self.open = [None; 2];
self.press = None;
self.pointer = None;
self.tangent = None;
self.snap.clear();
}
/// The end `which` (0 the first, 1 the second) placed at `p`: the open path end under it is
/// noted, and with `join` on the end lands on it.
fn place(&mut self, cx: &ToolContext, which: usize, p: Point) -> Point {
let found = open_end(cx, p);
if let Some(slot) = self.open.get_mut(which) {
*slot = found;
}
match found {
Some(e) if self.join => e.at,
_ => p,
}
}
/// The second end let go at `b`, with the first at `a`: placed, unless landing on an open path
/// end puts it on the first end, which leaves it to another try.
fn place_end(&mut self, cx: &ToolContext, a: Point, b: Point) {
let at = self.place(cx, 1, b);
if at.distance(a) > cx.tol(REACH_PX) {
self.end = Some(at);
} else {
self.open[1] = None;
}
}
/// How the point being placed keeps to the points before it: the second end to the first, and
/// in direction mode the third point to the end its direction line starts from.
fn leave(&self, cx: &ToolContext, mods: Mods) -> Option<Leave> {
@@ -111,6 +237,28 @@ impl ThreePointArcTool {
}
}
/// The third point at `q`, snapped: in direction mode with `tangentSnap` on, near the line
/// along which the arc carries on the open path its direction line starts at, it moves onto
/// that line. Shift keeps the line at 45° steps instead.
fn third(&mut self, cx: &ToolContext, q: Point, mods: Mods) -> Point {
self.tangent = None;
let (Some(a), Some(b)) = (self.start, self.end) else { return q };
if !self.direction || !self.tangent_snap || mods.shift {
return q;
}
let (o, end) = if self.at_end { (b, self.open[1]) } else { (a, self.open[0]) };
// The direction line starts on the path's end itself, so the arc carries the path on.
let Some(OpenEnd { at, out: Some(t) }) = end.filter(|e| e.at == o) else { return q };
let k = (q - at).dot(t);
let foot = at + t * k;
if k != 0.0 && q.distance(foot) <= cx.tol(TANGENT_PX) {
self.tangent = Some((at, t));
foot
} else {
q
}
}
/// The pressed pointer moved to `ev`, or Shift or Alt changed: the point being placed follows
/// it. A change of keys alone does not make the press a drag.
fn follow(&mut self, cx: &ToolContext, ev: &PointerEvent) {
@@ -122,10 +270,15 @@ impl ThreePointArcTool {
let leave = Leave::segment(cx, *at, ev.mods.shift);
self.pointer = Some(self.snap.drag(cx, ev.pos, Some(&leave)));
}
Some(Press::End | Press::Third) => {
Some(Press::End) => {
let leave = self.leave(cx, ev.mods);
self.pointer = Some(self.snap.drag(cx, ev.pos, leave.as_ref()));
}
Some(Press::Third) => {
let leave = self.leave(cx, ev.mods);
let q = self.snap.drag(cx, ev.pos, leave.as_ref());
self.pointer = Some(self.third(cx, q, ev.mods));
}
None => {}
}
}
@@ -153,7 +306,8 @@ impl Tool for ThreePointArcTool {
PointerKind::Move => {
self.raw = Some((ev.pos, ev.mods));
let leave = self.leave(cx, ev.mods);
self.pointer = Some(self.snap.hover(cx, ev.pos, &[], leave.as_ref()));
let q = self.snap.hover(cx, ev.pos, &[], leave.as_ref());
self.pointer = Some(self.third(cx, q, ev.mods));
vec![]
}
PointerKind::Down => {
@@ -161,7 +315,8 @@ impl Tool for ThreePointArcTool {
let leave = self.leave(cx, ev.mods);
match (self.start, self.end) {
(None, _) => {
let at = self.snap.press(cx, ev.pos, &[], None);
let snapped = self.snap.press(cx, ev.pos, &[], None);
let at = self.place(cx, 0, snapped);
self.start = Some(at);
self.press = Some(Press::Start { at, from: ev.pos, dragged: false });
self.pointer = Some(at);
@@ -177,7 +332,8 @@ impl Tool for ThreePointArcTool {
self.pointer = Some(at);
}
(Some(_), Some(_)) => {
self.pointer = Some(self.snap.press(cx, ev.pos, &[], leave.as_ref()));
let q = self.snap.press(cx, ev.pos, &[], leave.as_ref());
self.pointer = Some(self.third(cx, q, ev.mods));
self.press = Some(Press::Third);
}
}
@@ -195,8 +351,8 @@ impl Tool for ThreePointArcTool {
self.follow(cx, ev);
}
match (self.press.take(), self.start, self.pointer) {
(Some(Press::Start { at, dragged: true, .. }), _, Some(b)) if b.distance(at) >= cx.tol(DRAG_PX) => self.end = Some(b),
(Some(Press::End), Some(a), Some(b)) if b.distance(a) > cx.tol(REACH_PX) => self.end = Some(b),
(Some(Press::Start { at, dragged: true, .. }), _, Some(b)) if b.distance(at) >= cx.tol(DRAG_PX) => self.place_end(cx, at, b),
(Some(Press::End), Some(a), Some(b)) if b.distance(a) > cx.tol(REACH_PX) => self.place_end(cx, a, b),
(Some(Press::Third), Some(a), Some(c)) => {
let Some(b) = self.end else { return vec![] };
// Where no arc fits, nothing is drawn and the ends stay for another try.
@@ -204,7 +360,7 @@ impl Tool for ThreePointArcTool {
self.snap.clear();
return vec![];
}
let (name, params) = command(a, b, c, self.direction, self.at_end);
let (name, params) = command(a, b, c, self.direction, self.at_end, self.join);
self.clear();
return vec![Action::Exec(name, params)];
}
@@ -229,18 +385,40 @@ impl Tool for ThreePointArcTool {
(Some(_), Some((p, mods))) => self.follow(cx, &PointerEvent::new(PointerKind::Drag, p.x, p.y).with_mods(mods)),
(None, Some((p, mods))) if self.end.is_some() && self.pointer.is_some() => {
let leave = self.leave(cx, mods);
self.pointer = Some(self.snap.hover(cx, p, &[], leave.as_ref()));
let q = self.snap.hover(cx, p, &[], leave.as_ref());
self.pointer = Some(self.third(cx, q, mods));
}
_ => {}
}
}
ToolKey::Letter('j') if self.start.is_some() => {
self.join = !self.join;
// Switched on: the ends placed on open path ends land on them, unless that would
// put one end on the other.
if self.join {
let reach = cx.tol(REACH_PX);
if let Some(e) = self.open[0]
&& self.end.is_none_or(|b| b.distance(e.at) > reach)
{
self.start = Some(e.at);
if let Some(Press::Start { at, .. }) = &mut self.press {
*at = e.at;
}
}
if let (Some(a), Some(_), Some(e)) = (self.start, self.end, self.open[1])
&& a.distance(e.at) > reach
{
self.end = Some(e.at);
}
}
}
_ => {}
}
vec![]
}
fn claims_key(&self, _cx: &ToolContext, key: ToolKey) -> bool {
matches!(key, ToolKey::Escape | ToolKey::BracketRight) && self.start.is_some()
matches!(key, ToolKey::Escape | ToolKey::BracketRight | ToolKey::Letter('j')) && self.start.is_some()
}
/// An end placed: Escape drops it.
@@ -266,6 +444,7 @@ impl Tool for ThreePointArcTool {
fn hover_ended(&mut self, _cx: &ToolContext) {
if self.press.is_none() {
self.pointer = None;
self.tangent = None;
self.snap.clear();
}
}
@@ -285,6 +464,11 @@ impl Tool for ThreePointArcTool {
if self.direction {
o.push(Overlay::Line { a: if self.at_end { b } else { a }, b: p, color, dashed: false });
}
// The line the third point snapped to, as far past its end as the pointer is.
if let Some((at, t)) = self.tangent {
let reach = t * p.distance(at);
o.push(Overlay::Line { a: at - reach, b: at + reach, color, dashed: true });
}
match self.arc() {
Some((arc, path)) => {
o.push(Overlay::Path { path: path.to_bezpath(), color, width: 1.0, dashed: true });
@@ -313,21 +497,23 @@ impl Tool for ThreePointArcTool {
}
fn options(&self) -> Value {
json!({ "direction": self.direction })
json!({ "direction": self.direction, "join": self.join, "tangentSnap": self.tangent_snap })
}
fn set_option(&mut self, key: &str, value: &Value) {
if key == "direction"
&& let Some(on) = value.as_bool()
{
self.direction = on;
let Some(on) = value.as_bool() else { return };
match key {
"direction" => self.direction = on,
"join" => self.join = on,
"tangentSnap" => self.tangent_snap = on,
_ => {}
}
}
fn check_option(&self, key: &str, v: &Value) -> Result<(), String> {
use crate::option_check as c;
match key {
"direction" => c::boolean(key, v),
"direction" | "join" | "tangentSnap" => c::boolean(key, v),
_ => Err(c::unknown(key)),
}
}
+118 -4
View File
@@ -166,11 +166,11 @@ fn in_direction_mode_the_third_point_sets_the_tangent_at_an_end() {
let mut t = ThreePointArcTool::default();
assert!(!t.claims_key(&cx, ToolKey::BracketRight), "no ends: ] is left to the app");
t.key(&cx, ToolKey::BracketRight, Mods::default());
assert_eq!(t.options(), json!({ "direction": false }));
assert_eq!(t.options()["direction"], json!(false));
drag(&mut t, &cx, (300.0, 300.0), &[(380.0, 300.0)], Mods::default());
assert!(t.claims_key(&cx, ToolKey::BracketRight));
t.key(&cx, ToolKey::BracketRight, Mods::default());
assert_eq!(t.options(), json!({ "direction": true }));
assert_eq!(t.options()["direction"], json!(true));
// Straight up the page from (300, 300): the upper half circle about (340, 300).
hover(&mut t, &cx, (300.0, 250.0), Mods::default());
let o = t.overlays(&cx);
@@ -201,10 +201,10 @@ fn the_direction_option_takes_a_bool() {
t.set_option("direction", &json!(true));
for v in [json!("false"), json!(0), json!(null)] {
t.set_option("direction", &v);
assert_eq!(t.options(), json!({ "direction": true }), "{v}");
assert_eq!(t.options()["direction"], json!(true), "{v}");
}
t.set_option("direction", &json!(false));
assert_eq!(t.options(), json!({ "direction": false }));
assert_eq!(t.options(), json!({ "direction": false, "join": false, "tangentSnap": true }));
}
/// `]` pressed while the third point is held down places the point as the new mode keeps it: the
@@ -373,6 +373,120 @@ fn escape_history_and_a_double_click_drop_or_keep_the_ends() {
assert!(!t.busy() && t.overlays(&cx).is_empty());
}
/// A document holding an open straight path from (100, 100) to (200, 100), unselected.
fn doc_with_open_line() -> vectorcraft_doc::Document {
let mut d = vectorcraft_doc::Document::new(500.0, 500.0);
let (l, id) = (d.layers[0].id, d.alloc_id());
let path = vectorcraft_geom::shapes::line(Point::new(100.0, 100.0), Point::new(200.0, 100.0));
d.insert(Some(l), 0, vectorcraft_doc::Node::path(id, path, vectorcraft_doc::Appearance::default_art())).unwrap();
d
}
/// The arc command's params in `acts`, its only action.
fn params_of(acts: &[Action]) -> Value {
let [Action::Exec(name, params)] = acts else { panic!("{acts:?}") };
assert_eq!(name, "shape.threePointArc");
params.clone()
}
/// With `join` on, an end placed near an open path's end lands on it and the command asks for the
/// join; with it off, the end stays where it was placed and the command asks for none. J while
/// the ends are placed switches `join`, moving a placed end onto the path's end.
#[test]
fn with_join_an_end_near_an_open_path_end_lands_on_it() {
let d = doc_with_open_line();
let (s, p) = (Selection::default(), paint());
// Snap to Point off, so only `join` moves an end onto the path's end.
let isolated = ToolContext { smart_guides: false, snap_to_point: false, isolation: Some(vectorcraft_doc::NodeId(u64::MAX)), ..cx(&d, &s, &p) };
let cx = ToolContext { smart_guides: false, snap_to_point: false, ..cx(&d, &s, &p) };
let mut t = ThreePointArcTool::default();
assert!(!t.claims_key(&cx, ToolKey::Letter('j')), "no ends: J is left to the app");
click(&mut t, &cx, (198.5, 100.5));
click(&mut t, &cx, (280.0, 180.0));
let off = params_of(&click(&mut t, &cx, (280.0, 100.0)));
assert_eq!((off["start"].clone(), off.get("join")), (json!([198.5, 100.5]), None), "{off}");
t.set_option("join", &json!(true));
click(&mut t, &cx, (198.5, 100.5));
click(&mut t, &cx, (280.0, 180.0));
let on = params_of(&click(&mut t, &cx, (280.0, 100.0)));
assert_eq!((on["start"].clone(), on["join"].clone()), (json!([200.0, 100.0]), json!(true)), "{on}");
// The second end lands on the path's first end.
click(&mut t, &cx, (20.0, 180.0));
click(&mut t, &cx, (101.5, 100.5));
let on = params_of(&click(&mut t, &cx, (20.0, 100.0)));
assert_eq!(on["end"], json!([100.0, 100.0]), "{on}");
// In isolation mode, a path outside the isolated node is left alone.
click(&mut t, &isolated, (198.5, 100.5));
assert_eq!(t.start, Some(Point::new(198.5, 100.5)));
t.key(&cx, ToolKey::Escape, Mods::default());
// Past the path's end, off its stroke, but within reach of the end.
click(&mut t, &cx, (203.5, 102.0));
assert_eq!(t.start, Some(Point::new(200.0, 100.0)));
t.key(&cx, ToolKey::Escape, Mods::default());
// A second end that would land on the first end is not placed, by a click or by a drag.
click(&mut t, &cx, (200.0, 100.0));
click(&mut t, &cx, (196.0, 100.0));
assert_eq!((t.start, t.end), (Some(Point::new(200.0, 100.0)), None));
t.key(&cx, ToolKey::Escape, Mods::default());
drag(&mut t, &cx, (200.0, 100.0), &[(196.0, 100.0)], Mods::default());
assert_eq!((t.start, t.end), (Some(Point::new(200.0, 100.0)), None));
t.key(&cx, ToolKey::Escape, Mods::default());
// J switches `join` off and on again while the ends are placed.
t.set_option("join", &json!(false));
click(&mut t, &cx, (198.5, 100.5));
assert!(t.claims_key(&cx, ToolKey::Letter('j')));
t.key(&cx, ToolKey::Letter('j'), Mods::default());
assert_eq!((t.options()["join"].clone(), t.start), (json!(true), Some(Point::new(200.0, 100.0))));
click(&mut t, &cx, (280.0, 180.0));
let on = params_of(&click(&mut t, &cx, (280.0, 100.0)));
assert_eq!((on["start"].clone(), on["join"].clone()), (json!([200.0, 100.0]), json!(true)), "{on}");
}
/// In direction mode, with the first end on an open path's end, a third point near the line along
/// which the arc carries the path on (here the line y = 100) snaps onto it, the same way or turned
/// back, and the tool shows the line dashed; farther away, with Shift, with `tangentSnap` off, or
/// away from a path's end, the point stays where it is.
#[test]
fn in_direction_mode_the_third_point_snaps_to_carry_the_path_on() {
let d = doc_with_open_line();
let (s, p) = (Selection::default(), paint());
let cx = ToolContext { smart_guides: false, ..cx(&d, &s, &p) };
let mut t = ThreePointArcTool::default();
t.set_option("direction", &json!(true));
let dashed_through = |o: &[Overlay]| {
o.iter().any(|o| matches!(o, Overlay::Line { a, b, dashed: true, .. } if (a.y - 100.0).abs() < 1e-9 && (b.y - 100.0).abs() < 1e-9 && a.midpoint(*b) == Point::new(200.0, 100.0)))
};
for (third, want) in [((260.0, 103.0), (260.0, 100.0)), ((140.0, 97.0), (140.0, 100.0)), ((260.0, 120.0), (260.0, 120.0))] {
click(&mut t, &cx, (200.0, 100.0));
click(&mut t, &cx, (200.0, 200.0));
hover(&mut t, &cx, third, Mods::default());
assert_eq!(dashed_through(&t.overlays(&cx)), third != want, "{third:?}");
assert_eq!(params_of(&click(&mut t, &cx, third))["toward"], json!([want.0, want.1]), "{third:?}");
}
// Shift keeps the line at 45° steps instead: the pointer just off 45° goes onto 45°.
click(&mut t, &cx, (200.0, 100.0));
click(&mut t, &cx, (200.0, 200.0));
let shift = Mods { shift: true, ..Mods::default() };
let toward = params_of(&click_with(&mut t, &cx, (240.0, 63.0), shift))["toward"].clone();
assert!((toward[0].as_f64().unwrap() - 200.0 + toward[1].as_f64().unwrap() - 100.0).abs() < 1e-9, "{toward}");
// From an end away from the path, or with the snap off, no snap.
for (first, snap) in [((200.0, 140.0), true), ((200.0, 100.0), false)] {
t.set_option("tangentSnap", &json!(snap));
click(&mut t, &cx, first);
click(&mut t, &cx, (200.0, 220.0));
let toward = params_of(&click(&mut t, &cx, (260.0, first.1 + 3.0)))["toward"].clone();
assert_eq!(toward, json!([260.0, first.1 + 3.0]), "{first:?}");
}
// With Alt, the line from the second end, on the path's first end, carries the path on to the
// left.
t.set_option("tangentSnap", &json!(true));
click(&mut t, &cx, (100.0, 200.0));
click(&mut t, &cx, (100.0, 100.0));
let alt = Mods { alt: true, ..Mods::default() };
let acts = click_with(&mut t, &cx, (40.0, 98.0), alt);
assert_eq!((params_of(&acts)["toward"].clone(), params_of(&acts)["at"].clone()), (json!([40.0, 100.0]), json!("end")));
}
/// The catalog lists the tool in the Line Segment tool's group, after the Arc tool, with no
/// default shortcut, and `create` makes it.
#[test]
@@ -1,8 +1,12 @@
//! Three-Point Arc Tool Options (double-click the Three-Point Arc tool, or `tool.options`):
//! Third Point Sets Direction, the tool's `direction` option. With it on, the third point gives the
//! direction the arc leaves an end in; with it off, the arc passes through the third point. OK
//! sets it with `tool.setOption {tool: "threePointArc", values: {direction}}`; it lasts across
//! tool switches and is saved with the preferences. `]` also switches it while an arc is drawn.
//! direction the arc leaves an end in; with it off, the arc passes through the third point. Snap
//! Where the Arc Continues a Path (`tangentSnap`, on by default) snaps the third point, in
//! direction mode, to where the arc carries on an open path it starts at. Join to Open Path Ends
//! (`join`) joins the arc to the open paths whose ends its ends are placed on. OK sets them with
//! `tool.setOption {tool: "threePointArc", values: {direction, tangentSnap, join}}`; they last
//! across tool switches and are saved with the preferences. `]` also switches `direction`, and J
//! `join`, while an arc is drawn.
use craft::ui::contract::Bind;
use craft::ui::patterns::form_dialogs::{HostedParamDialog, Param, ParamDialog, ParamKind, ParamResult};
@@ -17,7 +21,11 @@ pub const KIND: &str = "threePointArcOptions";
/// Open the tool's options with their current values.
pub fn open(app: &mut VectorcraftApp) -> Value {
let params = vec![Param::new("direction", tl!("Third Point Sets Direction"), ParamKind::bool(false))];
let params = vec![
Param::new("direction", tl!("Third Point Sets Direction"), ParamKind::bool(false)),
Param::new("tangentSnap", tl!("Snap Where the Arc Continues a Path"), ParamKind::bool(true)),
Param::new("join", tl!("Join to Open Path Ends"), ParamKind::bool(false)),
];
let options = app.session.tool_options_of(TOOL);
let fields = options.as_object().map(|m| form::fields_of(&params, m)).unwrap_or_default();
let (title, shown) = (tool_options::title(TOOL), params.clone());
+20 -3
View File
@@ -856,7 +856,7 @@ from −100 to 100 and is 50 when left out with `lengthX` and `lengthY`, or 100
`` `baseAlong` must be one of x, y ``), as is a `slope` outside its range; the arc is not drawn and no undo step is
added.
`shape.threePointArc {start: [x, y], end: [x, y], through?: [x, y], toward?: [x, y], at?: "start"|"end"}` draws an
`shape.threePointArc {start: [x, y], end: [x, y], through?: [x, y], toward?: [x, y], at?: "start"|"end", join?: bool}` draws an
open circular arc from `start` to `end` and selects it. With `through`, the arc passes through that point. With
`toward`, the arc leaves `start` heading toward that point, so the line from `start` to the point is the arc's tangent
there. With `at: "end"`, the line from `end` to the point is the tangent at `end` instead. `at` is `"start"` when left
@@ -869,14 +869,31 @@ when the third point lies on the line through the ends, when the arc would reach
`[x, y]`, when both or neither of `through` and `toward` are given, when `at` is anything but `"start"` or `"end"`, and
when `at` is given with `through`.
With `join: true`, an end of the arc that lies on an end of an open subpath of an editable path (not a guide, and in
isolation mode inside the isolated group) joins the arc to that path, as the published arc tool documentation describes for arcs started or ended on an open path's end
(https://docs.astutegraphics.com/subscribe/arc-by-points-tool/arc-by-points-preferences). When several open path ends
lie there, one in the selection comes first, then the last in paint order. The path keeps its look, and when one end
joins, its direction: the arc is added after the path's last anchor or before its first, and the anchor where they meet
is the path's own, with the handle on the arc's side taken from the arc. When the other end of the arc lies on an end of
another open path, that path is joined on as `path.join` joins two paths; when it lies on the other end of the
same subpath, the path closes. It is one undo step, the joined path (or its compound path) is selected, and the result
is `{id, cx, cy, radius, sweep, joined: true}` with `id` the joined path. With no open path end at either end, the arc
is drawn as a new path. A `join` that is not true or false is an error.
The Three-Point Arc tool, in the Line Segment tool's group after the Arc tool, runs this command. A drag from one end to
the other, or a click on each, places the ends; Shift keeps the second end at 45° steps from the first (from General ›
Constrain Angle). A click on a third point, or a press dragged to it, then draws the arc through it. With the tool's
`direction` option on, the third point gives the direction the arc leaves the first end in; with `mods.alt`, the
direction is at the second end, and Shift keeps the direction at 45° steps. Three-Point Arc Tool Options (`tool.options`,
or a double-click on the tool) sets `direction` with its Third Point Sets Direction box, and
`]` (with or without Shift) switches it while the ends are placed; the option is saved with the preferences. Until the
third point is placed, the tool shows the arc as a dashed outline, its center as a small cross, the direction line in
`]` (with or without Shift) switches it while the ends are placed; the option is saved with the preferences. The
`join` option (Join to Open Path Ends in Tool Options, off by default; J switches it while the ends are placed) makes an
end placed within 5 screen points of an end of an open path land on that end (the nearest one, picked among ends equally
near as the command picks), and the tool then runs the command with
`join: true`. The `tangentSnap` option (Snap Where the Arc Continues a Path, on by default) works in direction mode:
when the direction line starts on an end of an open path, a third point within 5 screen points of the line along which
the arc carries the path on, the same way or turned back, snaps onto it, and the tool shows that line dashed. Shift
keeps the direction at 45° steps instead. Until the third point is placed, the tool shows the arc as a dashed outline, its center as a small cross, the direction line in
direction mode and, with Measurement Labels on, the radius. Where no arc fits, the tool shows "Arc too large" by the
pointer (nothing while the pointer is on an end), and a click there draws nothing and keeps the ends. Escape, and an
edit, Undo or Redo made outside the tool, remove the ends.
+1
View File
@@ -814,6 +814,7 @@ since 2026-10-01.
- **Arcs along General › Constrain Angle:** with a Constrain Angle other than 0° or a whole turn, an arc dragged out with the Arc tool and an arc placed from the Arc Segment Tool Options click dialog are drawn along the turned x and y axes, with their bounding box turned. The drag's box and Shift's equal lengths are measured along those axes, the reference point stays at the drag's corner or at the click, and F, C and ↑/↓ keep the turn. `shape.arc` takes an optional `rotation` (degrees clockwise, about `x1`, `y1` or about the reference point `x`, `y`); a `rotation` that is not a number is an error. At 0° and whole turns arcs are drawn as before, and quarter turns are exact. The help page (<https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=226>) describes new objects being drawn along the turned axes; how the Arc tool's keys and reference point work with them is VectorCraft's own rule (tools `draw2::family::tests::arcs_follow_the_constrain_angle`; engine `constrain_angle_draws_a_dragged_arc_along_the_turned_axes`, `constrain_angle_turns_a_click_made_arc_about_its_reference_point`, `arc_rotation_turns_it_and_must_be_a_number`). Scores and hours unchanged.
- **Spirals turn as they are dragged, and along General › Constrain Angle:** a spiral dragged out with the Spiral tool turns about its center so that its outer end is at the pointer, so dragging around the center turns it, while Alt, Ctrl/Cmd, ↑/↓, Space and Escape work as before. A spiral placed from the Spiral dialog starts along the x axis turned by a Constrain Angle other than 0° or a whole turn, with its bounding box turned. `shape.spiral` takes an optional `rotation` (degrees clockwise about `cx`, `cy`); a `rotation` that is not a number is an error, and without one spirals are drawn as before. The help page (<https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=65>) says that moving the pointer around in a curve during the drag turns the new spiral, and the help page (<https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf#page=226>) describes new objects being drawn along the turned axes. Putting the outer end exactly at the pointer, keeping the last direction while the pointer is within 0.01 pt of the center, and leaving a dragged spiral's direction to the pointer with Shift or a Constrain Angle are VectorCraft's own rules (tools `draw2::family::tests::spiral_drag_turns_the_spiral_to_the_pointer`; engine `a_dragged_spiral_turns_its_outer_end_to_the_pointer`, `constrain_angle_turns_a_click_made_spiral`, `spiral_rotation_turns_it_and_must_be_a_number`; UI `spiral_click_dialog_starts_along_the_constrain_angle`). Scores and hours unchanged.
- **Three-Point Arc tool:** a new tool in the Line Segment tool's group, after the Arc tool, draws an open circular arc. A drag or two clicks place its ends (Shift keeps the second end at 45° steps), and a third click places a point the arc passes through. With Third Point Sets Direction on (the tool's Tool Options, or `]` while drawing), the third point gives the direction the arc leaves its first end in, or with Alt the direction at its second end. The tool previews the arc and its center, and with Measurement Labels on its radius, shows "Arc too large" where no arc fits, and draws the arc in one undo step with `shape.threePointArc {start, end, through | toward, at?}` (geom `shapes::tests::the_arc_through_a_point_passes_through_it`, `the_arc_leaving_along_a_direction_has_that_tangent`, `degenerate_points_give_no_arc`, `the_path_via_the_third_point_passes_through_it_exactly`; tools `three_point_arc::tests`; engine `tests::three_point_arc`; ui-egui `dialogs::three_point_arc_options::tests`). Scores and hours unchanged.
- **Three-Point Arc joins open paths:** with Join to Open Path Ends on (Tool Options, or J while drawing), an end of the arc placed near an end of an open path lands on it and the arc is joined to that path, which keeps its look; with both ends on open path ends the paths become one, or the path closes when both are its own ends (`shape.threePointArc {join: true}`, one undo step). In direction mode, with the direction line starting on an open path's end, Snap Where the Arc Continues a Path (on by default) snaps the third point onto the line along which the arc carries the path on, the same way or turned back (https://docs.astutegraphics.com/subscribe/arc-by-points-tool/arc-by-points-preferences; tools `three_point_arc::tests::with_join_an_end_near_an_open_path_end_lands_on_it`, `in_direction_mode_the_third_point_snaps_to_carry_the_path_on`; engine `tests::three_point_arc::join_adds_the_arc_to_the_open_path_it_starts_on`, `join_with_both_ends_on_open_paths_makes_one_path`, `join_prefers_the_selected_path_then_the_front_one`, `join_leaves_paths_it_cannot_join_alone`, `the_tool_joins_the_arc_to_the_path_end_it_starts_near`). Scores and hours unchanged.
- **Shape commands refuse invalid options:** `shape.arc` refuses a `reference` that is not a whole number from 0 to 8, a `baseAlong` other than `x` or `y` (either case), null included for both, and a `slope` outside −100…100, in both of its forms; before, such a value drew the arc with reference point 0 or 8, the X axis or the nearest slope. `shape.rectangularGrid` and `shape.polarGrid` refuse a divider count that is not a whole number of at least 0; before, such a count was 5. Each error names the key, and nothing is drawn. Left-out values keep their defaults. These ranges are VectorCraft's own command rules (engine `draw2::shape_arc_rejects_an_invalid_reference_base_along_or_slope`, `draw2::shape_arc_takes_every_reference_point_and_either_base_axis`, `draw2::grid_divider_counts_reject_fractions_and_negatives`). Scores and hours unchanged.
- **Roughen at Size 0 keeps the outline:** with Size 0 (relative or absolute), Effect › Distort & Transform › Roughen… moves no point: each segment is split at the Detail spacing (fewer points past the anchor limit) into pieces of equal length on the segment itself, so the path keeps its outline, with Smooth or Corner points alike. A straight segment gets corner points without handles, and a curve gets smooth points whose handles follow it. Before, the points were joined by straight lines (Corner) or a smoothed curve through them (Smooth), which changed curved outlines. Existing documents with a Roughen of Size 0 on a curved path, or with Smooth points, draw differently. This is VectorCraft's own rule; what Roughen does is described in [Distort and transform effects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/distort-and-transform-effects-in-illustrator.html) (effects `tests::roughen_at_size_0_keeps_the_outline_and_spaces_its_points_evenly`). Scores and hours unchanged.