mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 19:36:16 +00:00
Merge pull request #9001 from dotCooCoo/feat/tangent-circle-preview-prefs
Path Precision Tools: the Tangent Circle Tool's options set its preview and how near it snaps
This commit is contained in:
@@ -16,6 +16,16 @@
|
||||
//! document, or a change to the first segment that leaves no undo step (a live preview, or one that
|
||||
//! was canceled) forgets the first segment. The circles are looked for again whenever either
|
||||
//! segment's shape differs from the one they were found on.
|
||||
//!
|
||||
//! The tool's options (its options dialog, `tool.setOption`; kept with the preferences): `radius`;
|
||||
//! `center` and `radii` show or hide the circle's center cross and the lines from its center to the
|
||||
//! two points it touches; `color` is the color of the circle, the cross, those lines and the note
|
||||
//! (one of [`COLORS`]); `snapTolerance` is how near (screen pixels) the pointer picks a segment
|
||||
//! with Smart Guides on, where Smart Guides' Snapping Tolerance counts instead when it is larger,
|
||||
//! or with Smart Guides off while `snapWithoutGuides` is on. Without snapping a segment is picked
|
||||
//! within the selection tolerance, as a click on a path picks it, and that is also the least reach
|
||||
//! snapping has. Of the segments within reach the nearest is picked ([`pick_at`]). By default the
|
||||
//! cross and the lines show, the color is red, the tolerance is 3 px and `snapWithoutGuides` is on.
|
||||
|
||||
use kurbo::{CubicBez, Shape};
|
||||
use serde_json::{Value, json};
|
||||
@@ -42,6 +52,22 @@ pub const NO_CIRCLE: &str = "No tangent circle here";
|
||||
const BLUE: [u8; 3] = [0x4f, 0x9d, 0xff];
|
||||
const RED: [u8; 3] = [0xe0, 0x3c, 0x3c];
|
||||
const GREY: [u8; 3] = [0x80, 0x80, 0x80];
|
||||
/// The colors the `color` option takes, by option value, with the color the circle, its center
|
||||
/// cross, its radii and the note are drawn in. Red is the first.
|
||||
pub const COLORS: &[(&str, [u8; 3])] = &[
|
||||
("red", RED),
|
||||
("blue", crate::draw2::FEEDBACK),
|
||||
("magenta", [0xd6, 0x2c, 0xd6]),
|
||||
("green", [0x1f, 0xb4, 0x4b]),
|
||||
("black", [0x00, 0x00, 0x00]),
|
||||
("gray", GREY),
|
||||
];
|
||||
/// The snapping tolerance the tool starts with (screen pixels).
|
||||
pub const SNAP_PX: f64 = 3.0;
|
||||
/// The snapping tolerance the `snapTolerance` option takes (screen pixels).
|
||||
pub const SNAP_RANGE: (f64, f64) = (0.0, 25.0);
|
||||
/// The option keys that are true or false.
|
||||
const SWITCHES: &[&str] = &["center", "radii", "snapWithoutGuides"];
|
||||
|
||||
/// A segment under the pointer: where on it, and the segment itself.
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
@@ -72,6 +98,14 @@ struct Press {
|
||||
|
||||
pub struct TangentCircleTool {
|
||||
radius: f64,
|
||||
/// Whether the preview shows the center cross and the radii.
|
||||
center: bool,
|
||||
radii: bool,
|
||||
/// An entry of [`COLORS`].
|
||||
color: usize,
|
||||
/// The snapping tolerance (screen pixels), and whether the tool snaps with Smart Guides off.
|
||||
snap_px: f64,
|
||||
snap_without_guides: bool,
|
||||
first: Option<Pick>,
|
||||
hover: Option<Pick>,
|
||||
press: Option<Press>,
|
||||
@@ -91,13 +125,45 @@ type CacheKey = (NodeId, usize, usize, Option<u64>, CubicBez, Vec<CubicBez>);
|
||||
|
||||
impl Default for TangentCircleTool {
|
||||
fn default() -> Self {
|
||||
Self { radius: RADIUS, first: None, hover: None, press: None, picking: false, found: None, looked: false, pointer: Point::ZERO, cache: None }
|
||||
Self {
|
||||
radius: RADIUS,
|
||||
center: true,
|
||||
radii: true,
|
||||
color: 0,
|
||||
snap_px: SNAP_PX,
|
||||
snap_without_guides: true,
|
||||
first: None,
|
||||
hover: None,
|
||||
press: None,
|
||||
picking: false,
|
||||
found: None,
|
||||
looked: false,
|
||||
pointer: Point::ZERO,
|
||||
cache: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The path segment under `p`, of any editable path.
|
||||
fn pick_at(cx: &ToolContext, p: Point) -> Option<Pick> {
|
||||
let (id, subpath, segment, t) = crate::draw2::hit_segment(cx, p, cx.pick_tol())?;
|
||||
/// The nearest path segment within `reach` of `p`, of any editable path; of segments at the same
|
||||
/// distance, one of a selected path, then the one on top.
|
||||
fn pick_at(cx: &ToolContext, p: Point, reach: f64) -> Option<Pick> {
|
||||
let mut best: Option<((NodeId, usize, usize, f64), f64)> = None;
|
||||
for id in crate::draw2::candidate_paths(cx) {
|
||||
let Some(pd) = cx.doc.node(id).and_then(|n| n.path_data()) else { continue };
|
||||
// A path whose control points' box, with its edges, lies out of reach holds no point within
|
||||
// reach.
|
||||
let near = |b: vectorcraft_geom::Rect| p.x >= b.x0 - reach && p.x <= b.x1 + reach && p.y >= b.y0 - reach && p.y <= b.y1 + reach;
|
||||
if pd.control_bounds().is_none_or(|b| !near(b)) {
|
||||
continue;
|
||||
}
|
||||
if let Some((subpath, segment, t, _, d)) = pd.nearest(p)
|
||||
&& d <= reach
|
||||
&& best.is_none_or(|(_, b)| d < b)
|
||||
{
|
||||
best = Some(((id, subpath, segment, t), d));
|
||||
}
|
||||
}
|
||||
let ((id, subpath, segment, t), _) = best?;
|
||||
let sp = cx.doc.node(id)?.path_data()?.subpaths.get(subpath)?;
|
||||
if segment >= sp.segment_count() {
|
||||
return None;
|
||||
@@ -197,6 +263,26 @@ fn segment_path(c: &CubicBez) -> BezPath {
|
||||
}
|
||||
|
||||
impl TangentCircleTool {
|
||||
/// How near (document units) the pointer picks a segment: with Smart Guides on, the snapping
|
||||
/// tolerance or Smart Guides' Snapping Tolerance, whichever is larger; with them off, the
|
||||
/// snapping tolerance while `snapWithoutGuides` is on, and otherwise none. Never less than the
|
||||
/// selection tolerance.
|
||||
fn reach(&self, cx: &ToolContext) -> f64 {
|
||||
let pick = cx.pick_tol();
|
||||
if cx.smart_guides {
|
||||
pick.max(cx.tol(self.snap_px)).max(cx.snap_tol())
|
||||
} else if self.snap_without_guides {
|
||||
pick.max(cx.tol(self.snap_px))
|
||||
} else {
|
||||
pick
|
||||
}
|
||||
}
|
||||
|
||||
/// The color the preview is drawn in.
|
||||
fn preview_color(&self) -> [u8; 3] {
|
||||
COLORS.get(self.color).map_or(RED, |(_, rgb)| *rgb)
|
||||
}
|
||||
|
||||
/// The radius a drag gives, with Shift in round steps.
|
||||
fn shown_radius(cx: &ToolContext, r: f64, shift: bool) -> f64 {
|
||||
if !shift {
|
||||
@@ -304,12 +390,12 @@ impl Tool for TangentCircleTool {
|
||||
self.pointer = ev.pos;
|
||||
match ev.kind {
|
||||
PointerKind::Move => {
|
||||
self.hover = pick_at(cx, ev.pos);
|
||||
self.hover = pick_at(cx, ev.pos, self.reach(cx));
|
||||
self.look(cx, ev.pos, ev.mods);
|
||||
vec![]
|
||||
}
|
||||
PointerKind::Down => {
|
||||
let Some(pick) = pick_at(cx, ev.pos) else { return vec![] };
|
||||
let Some(pick) = pick_at(cx, ev.pos, self.reach(cx)) else { return vec![] };
|
||||
self.forget_if_changed(cx);
|
||||
let Some(first) = self.first.clone() else {
|
||||
self.first = Some(pick);
|
||||
@@ -415,21 +501,26 @@ impl Tool for TangentCircleTool {
|
||||
{
|
||||
out.push(Overlay::Line { a: press.at, b: self.pointer, color: GREY, dashed: false });
|
||||
}
|
||||
let color = self.preview_color();
|
||||
if let Some(c) = &self.found {
|
||||
let (at, r) = (c.circle.center, c.circle.radius);
|
||||
// A tolerance of at least a ten-thousandth of the radius keeps a huge circle to a few
|
||||
// dozen segments.
|
||||
let tol = cx.tol(0.1).max(r * 1e-4);
|
||||
out.push(Overlay::Path { path: kurbo::Circle::new(at, r).to_path(tol), color: RED, width: 1.0, dashed: false });
|
||||
let arm = cx.tol(4.0);
|
||||
out.push(Overlay::Line { a: at - kurbo::Vec2::new(arm, 0.0), b: at + kurbo::Vec2::new(arm, 0.0), color: RED, dashed: false });
|
||||
out.push(Overlay::Line { a: at - kurbo::Vec2::new(0.0, arm), b: at + kurbo::Vec2::new(0.0, arm), color: RED, dashed: false });
|
||||
out.push(Overlay::Line { a: at, b: c.first, color: RED, dashed: true });
|
||||
out.push(Overlay::Line { a: at, b: c.second, color: RED, dashed: true });
|
||||
out.push(Overlay::Path { path: kurbo::Circle::new(at, r).to_path(tol), color, width: 1.0, dashed: false });
|
||||
if self.center {
|
||||
let arm = cx.tol(4.0);
|
||||
out.push(Overlay::Line { a: at - kurbo::Vec2::new(arm, 0.0), b: at + kurbo::Vec2::new(arm, 0.0), color, dashed: false });
|
||||
out.push(Overlay::Line { a: at - kurbo::Vec2::new(0.0, arm), b: at + kurbo::Vec2::new(0.0, arm), color, dashed: false });
|
||||
}
|
||||
if self.radii {
|
||||
out.push(Overlay::Line { a: at, b: c.first, color, dashed: true });
|
||||
out.push(Overlay::Line { a: at, b: c.second, color, dashed: true });
|
||||
}
|
||||
out.push(Overlay::Measure { p: self.pointer, text: format!("R: {}", cx.len(r)) });
|
||||
} else if self.looked {
|
||||
// A label, which the canvas shows in the interface language.
|
||||
out.push(Overlay::Label { p: self.pointer, text: NO_CIRCLE.into(), color: RED });
|
||||
out.push(Overlay::Label { p: self.pointer, text: NO_CIRCLE.into(), color });
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -439,14 +530,29 @@ impl Tool for TangentCircleTool {
|
||||
}
|
||||
|
||||
fn options(&self) -> Value {
|
||||
json!({ "radius": self.radius })
|
||||
json!({
|
||||
"radius": self.radius,
|
||||
"center": self.center,
|
||||
"radii": self.radii,
|
||||
"color": COLORS.get(self.color).map_or("red", |(name, _)| *name),
|
||||
"snapTolerance": self.snap_px,
|
||||
"snapWithoutGuides": self.snap_without_guides,
|
||||
})
|
||||
}
|
||||
|
||||
/// Sets one option; a value the option does not take leaves it as it was.
|
||||
fn set_option(&mut self, key: &str, v: &Value) {
|
||||
if key == "radius"
|
||||
&& let Some(r) = v.as_f64().filter(|r| (RADIUS_RANGE.0..=RADIUS_RANGE.1).contains(r))
|
||||
{
|
||||
self.radius = r;
|
||||
if self.check_option(key, v).is_err() {
|
||||
return;
|
||||
}
|
||||
match key {
|
||||
"radius" => self.radius = v.as_f64().unwrap_or(self.radius),
|
||||
"center" => self.center = v.as_bool().unwrap_or(self.center),
|
||||
"radii" => self.radii = v.as_bool().unwrap_or(self.radii),
|
||||
"color" => self.color = v.as_str().and_then(|s| COLORS.iter().position(|(name, _)| *name == s)).unwrap_or(self.color),
|
||||
"snapTolerance" => self.snap_px = v.as_f64().unwrap_or(self.snap_px),
|
||||
"snapWithoutGuides" => self.snap_without_guides = v.as_bool().unwrap_or(self.snap_without_guides),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -454,6 +560,9 @@ impl Tool for TangentCircleTool {
|
||||
use crate::option_check as c;
|
||||
match key {
|
||||
"radius" => c::number(key, v, RADIUS_RANGE.0, RADIUS_RANGE.1),
|
||||
"snapTolerance" => c::number(key, v, SNAP_RANGE.0, SNAP_RANGE.1),
|
||||
"color" => c::one_of(key, v, &COLORS.iter().map(|(name, _)| *name).collect::<Vec<_>>()),
|
||||
k if SWITCHES.contains(&k) => c::boolean(key, v),
|
||||
_ => Err(c::unknown(key)),
|
||||
}
|
||||
}
|
||||
@@ -598,6 +707,123 @@ mod tests {
|
||||
assert!(close(drawn(&released), (130.0, 100.0, 40.0, 40.0)), "{released:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preview_options_set_its_cross_radii_and_color() {
|
||||
let d = doc();
|
||||
let (sel, p) = (Selection::default(), paint());
|
||||
let cx = cx(&d, &sel, &p);
|
||||
let green = COLORS.iter().find(|(name, _)| *name == "green").map(|(_, rgb)| *rgb);
|
||||
let lines =
|
||||
|ov: &[Overlay], dashed_lines: bool| ov.iter().filter(|o| matches!(o, Overlay::Line { dashed, .. } if *dashed == dashed_lines)).count();
|
||||
let mut t = TangentCircleTool::default();
|
||||
t.pointer(&cx, &ev(PointerKind::Down, 150.0, 101.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Up, 150.0, 101.0));
|
||||
t.pointer(&cx, &ev(PointerKind::Move, 200.0, 139.0));
|
||||
// By default: the red circle, its center cross (two lines) and its two radii.
|
||||
let ov = t.overlays(&cx);
|
||||
assert_eq!((lines(&ov, false), lines(&ov, true)), (2, 2), "{ov:?}");
|
||||
assert!(ov.iter().any(|o| matches!(o, Overlay::Path { color, width, .. } if *color == RED && *width == 1.0)), "{ov:?}");
|
||||
t.set_option("center", &json!(false));
|
||||
let ov = t.overlays(&cx);
|
||||
assert_eq!((lines(&ov, false), lines(&ov, true)), (0, 2), "no cross: {ov:?}");
|
||||
t.set_option("radii", &json!(false));
|
||||
t.set_option("color", &json!("green"));
|
||||
let ov = t.overlays(&cx);
|
||||
assert_eq!((lines(&ov, false), lines(&ov, true)), (0, 0), "no radii: {ov:?}");
|
||||
assert!(ov.iter().any(|o| matches!(o, Overlay::Path { color, .. } if Some(*color) == green)), "{ov:?}");
|
||||
assert!(ov.iter().any(|o| matches!(o, Overlay::Measure { text, .. } if text.starts_with("R: 20.00"))), "the radius still shows: {ov:?}");
|
||||
// The note takes the color too.
|
||||
t.set_option("radius", &json!(5));
|
||||
t.pointer(&cx, &shifted(PointerKind::Move, 200.0, 140.0));
|
||||
assert!(t.overlays(&cx).iter().any(|o| matches!(o, Overlay::Label { text, color, .. } if text == NO_CIRCLE && Some(*color) == green)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preview_and_snap_options_take_only_their_values() {
|
||||
let mut t = TangentCircleTool::default();
|
||||
let o = t.options();
|
||||
assert_eq!(
|
||||
(&o["center"], &o["radii"], &o["color"], &o["snapTolerance"], &o["snapWithoutGuides"]),
|
||||
(&json!(true), &json!(true), &json!("red"), &json!(3.0), &json!(true))
|
||||
);
|
||||
for (key, good) in [
|
||||
("center", json!(false)),
|
||||
("radii", json!(false)),
|
||||
("snapWithoutGuides", json!(false)),
|
||||
("color", json!("gray")),
|
||||
("snapTolerance", json!(0)),
|
||||
("snapTolerance", json!(25)),
|
||||
("snapTolerance", json!(7.5)),
|
||||
] {
|
||||
assert_eq!(t.check_option(key, &good), Ok(()), "{key} {good}");
|
||||
t.set_option(key, &good);
|
||||
let now = t.options()[key].clone();
|
||||
assert!(now == good || (good.is_number() && now.as_f64() == good.as_f64()), "{key}: {now} for {good}");
|
||||
}
|
||||
let colors = "`color` must be one of `red`, `blue`, `magenta`, `green`, `black`, `gray`";
|
||||
for (key, bad, error) in [
|
||||
("center", json!(1), "`center` must be true or false"),
|
||||
("radii", json!("no"), "`radii` must be true or false"),
|
||||
("snapWithoutGuides", Value::Null, "`snapWithoutGuides` must be true or false"),
|
||||
("color", json!("orange"), colors),
|
||||
("color", json!("Red"), colors),
|
||||
("color", json!(0), colors),
|
||||
("snapTolerance", json!(-1), "`snapTolerance` must be a number from 0 to 25"),
|
||||
("snapTolerance", json!(26), "`snapTolerance` must be a number from 0 to 25"),
|
||||
("snapTolerance", json!("3"), "`snapTolerance` must be a number from 0 to 25"),
|
||||
] {
|
||||
assert_eq!(t.check_option(key, &bad), Err(error.into()), "{key} {bad}");
|
||||
let before = t.options();
|
||||
t.set_option(key, &bad);
|
||||
assert_eq!(t.options(), before, "{key} {bad}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_snap_options_set_how_near_a_segment_is_picked() {
|
||||
let d = doc();
|
||||
let (sel, p) = (Selection::default(), paint());
|
||||
// At 100%, Selection Tolerance 3 px; the first line is at y = 100.
|
||||
let picks = |t: &mut TangentCircleTool, cx: &ToolContext, y: f64| {
|
||||
t.forget();
|
||||
t.pointer(cx, &ev(PointerKind::Down, 150.0, y));
|
||||
t.pointer(cx, &ev(PointerKind::Up, 150.0, y));
|
||||
t.first.is_some()
|
||||
};
|
||||
let guides = |tolerance: f64| ToolContext { smart_guides: true, snapping_tolerance: tolerance, ..cx(&d, &sel, &p) };
|
||||
let no_guides = ToolContext { smart_guides: false, ..cx(&d, &sel, &p) };
|
||||
let mut t = TangentCircleTool::default();
|
||||
// Smart Guides on: their Snapping Tolerance when it is larger than the tool's.
|
||||
assert!(picks(&mut t, &guides(10.0), 109.0));
|
||||
assert!(!picks(&mut t, &guides(10.0), 111.0));
|
||||
t.set_option("snapTolerance", &json!(12));
|
||||
assert!(picks(&mut t, &guides(4.0), 111.0), "the tool's when it is larger");
|
||||
assert!(!picks(&mut t, &guides(4.0), 113.0));
|
||||
// Smart Guides off: the tool's tolerance while it snaps without them.
|
||||
t.set_option("snapTolerance", &json!(8));
|
||||
assert!(picks(&mut t, &no_guides, 107.0));
|
||||
assert!(!picks(&mut t, &no_guides, 109.0));
|
||||
// Without snapping, only the Selection Tolerance; a tolerance below it does not shrink it.
|
||||
t.set_option("snapWithoutGuides", &json!(false));
|
||||
assert!(!picks(&mut t, &no_guides, 105.0));
|
||||
assert!(picks(&mut t, &no_guides, 102.5));
|
||||
t.set_option("snapWithoutGuides", &json!(true));
|
||||
t.set_option("snapTolerance", &json!(0));
|
||||
assert!(picks(&mut t, &no_guides, 102.5));
|
||||
// Over the gap between the two lines, the nearer one is picked, though both are in reach.
|
||||
t.set_option("snapTolerance", &json!(25));
|
||||
t.forget();
|
||||
t.pointer(&no_guides, &ev(PointerKind::Move, 150.0, 122.0));
|
||||
assert!(t.hover.as_ref().is_some_and(|h| (h.p.y - 140.0).abs() < 1e-9), "{:?}", t.hover);
|
||||
t.pointer(&no_guides, &ev(PointerKind::Move, 150.0, 118.0));
|
||||
assert!(t.hover.as_ref().is_some_and(|h| (h.p.y - 100.0).abs() < 1e-9), "{:?}", t.hover);
|
||||
// A segment exactly at the reach is in reach, on either side of it.
|
||||
t.pointer(&no_guides, &ev(PointerKind::Move, 150.0, 75.0));
|
||||
assert!(t.hover.as_ref().is_some_and(|h| (h.p.y - 100.0).abs() < 1e-9), "{:?}", t.hover);
|
||||
t.pointer(&no_guides, &ev(PointerKind::Move, 150.0, 165.0));
|
||||
assert!(t.hover.as_ref().is_some_and(|h| (h.p.y - 140.0).abs() < 1e-9), "{:?}", t.hover);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_drag_sets_the_radius_with_shift_steps_and_a_slow_drag() {
|
||||
let d = doc();
|
||||
|
||||
@@ -108,7 +108,7 @@ const ROWS: &[Row] = &[
|
||||
(&[crate::addons::extend_path::ID], None, &["mode"]),
|
||||
(&[crate::addons::corner_tool::ID], None, &["radius", "kind"]),
|
||||
(&[crate::addons::shared_edge::ID], None, &["diameter", "tolerance", "together"]),
|
||||
(&[crate::addons::tangent_circle::ID], None, &["radius"]),
|
||||
(&[crate::addons::tangent_circle::ID], None, &["radius", "center", "radii", "color", "snapTolerance", "snapWithoutGuides"]),
|
||||
(&[crate::addons::smart_pen::ID], None, &["next"]),
|
||||
// The kind first: a new kind resets the values after it.
|
||||
(&[crate::addons::parametric_shape::ID], None, &["kind", "count", "a", "b", "radius", "width", "height", "rotation"]),
|
||||
|
||||
@@ -301,7 +301,18 @@ fn options_params(tool: &str, lengths: LengthUnits) -> Vec<Param> {
|
||||
if tool == tangent_circle_tool::ID {
|
||||
let (lo, hi) = tangent_circle_tool::RADIUS_RANGE;
|
||||
let kind = ParamKind::number(Some(lo), Some(hi), tangent_circle_tool::RADIUS, 1.0, 2);
|
||||
return vec![Param::new("radius", tl!("Radius"), kind).length(lengths)];
|
||||
let colors =
|
||||
tangent_circle_tool::COLORS.iter().zip(TANGENT_CIRCLE_COLORS).map(|((name, _), label)| ((*name).to_owned(), tl!(label).into())).collect();
|
||||
let (snap_lo, snap_hi) = tangent_circle_tool::SNAP_RANGE;
|
||||
let snap = ParamKind::number(Some(snap_lo), Some(snap_hi), tangent_circle_tool::SNAP_PX, 1.0, 2);
|
||||
return vec![
|
||||
Param::new("radius", tl!("Radius"), kind).length(lengths),
|
||||
Param::new("center", tl!("Circle Center"), ParamKind::bool(true)),
|
||||
Param::new("radii", tl!("Circle Radii Lines"), ParamKind::bool(true)),
|
||||
Param::new("color", tl!("Color"), ParamKind::choice(colors, Some("red".into()))),
|
||||
Param::new("snapTolerance", tl!("Snap Tolerance"), snap).unit(UnitKind::Pixels),
|
||||
Param::new("snapWithoutGuides", tl!("Snap When Smart Guides Are Off"), ParamKind::bool(true)),
|
||||
];
|
||||
}
|
||||
let (size, tolerance) = (anchor_eraser::SIZE_RANGE, anchor_eraser::TOLERANCE_RANGE);
|
||||
vec![
|
||||
@@ -311,6 +322,9 @@ fn options_params(tool: &str, lengths: LengthUnits) -> Vec<Param> {
|
||||
]
|
||||
}
|
||||
|
||||
/// The labels of the Tangent Circle tool's colors ([`tangent_circle_tool::COLORS`]), in its order.
|
||||
const TANGENT_CIRCLE_COLORS: [&str; 6] = ["Red", "Blue", "Magenta", "Green", "Black", "Gray"];
|
||||
|
||||
/// Open the options of add-on tool `tool` with its current values. OK sets them; when the tool refuses one, the dialog
|
||||
/// stays open with the reason.
|
||||
pub fn open_options(app: &mut VectorcraftApp, tool: &str) -> Result<Value, String> {
|
||||
|
||||
@@ -93,6 +93,90 @@ fn double_clicking_the_brush_opens_its_options_and_ok_sets_them() {
|
||||
assert_eq!(KIND, "pathToolOptions");
|
||||
}
|
||||
|
||||
/// The Tangent Circle tool's options dialog shows the preview and snapping options, OK sets them,
|
||||
/// and a value the tool refuses sets none of them and keeps the dialog open.
|
||||
#[test]
|
||||
fn the_tangent_circle_options_set_the_preview_and_snapping() {
|
||||
let mut app = app_with_window();
|
||||
let ctx = host::ctx(&app);
|
||||
let ok = |app: &mut VectorcraftApp, set: &[(&str, FieldValue)]| {
|
||||
held(app, |d| {
|
||||
let d = d.expect("the held dialog");
|
||||
for (key, value) in set {
|
||||
d.set_field(*key, value.clone());
|
||||
}
|
||||
});
|
||||
app.dialogs().expect("the window's dialogs").with(|h| h.confirm::<HostedParamDialog>(&ctx));
|
||||
crate::dialogs::host::pump(app, &ctx);
|
||||
crate::tests_synthetic::key_frame(app, &ctx, vec![]);
|
||||
};
|
||||
app.run("tool.options", json!({"tool": "tangentCircle"})).unwrap();
|
||||
let shown = held(&app, |d| {
|
||||
let f = d.expect("the held dialog").fields();
|
||||
(f.bool("center"), f.bool("radii"), f.text("color").map(str::to_owned), f.number("snapTolerance"), f.bool("snapWithoutGuides"))
|
||||
});
|
||||
assert_eq!(shown, (Some(true), Some(true), Some("red".to_owned()), Some(3.0), Some(true)));
|
||||
ok(
|
||||
&mut app,
|
||||
&[
|
||||
("center", FieldValue::Bool(false)),
|
||||
("radii", FieldValue::Bool(false)),
|
||||
("color", FieldValue::Text("magenta".into())),
|
||||
("snapTolerance", FieldValue::Number(9.0)),
|
||||
("snapWithoutGuides", FieldValue::Bool(false)),
|
||||
],
|
||||
);
|
||||
assert!(held(&app, |d| d.is_none()), "OK closes the dialog");
|
||||
let o = app.session.tool_options_of("tangentCircle");
|
||||
assert_eq!((&o["center"], &o["radii"], &o["color"], &o["snapWithoutGuides"]), (&json!(false), &json!(false), &json!("magenta"), &json!(false)));
|
||||
assert_eq!(o["snapTolerance"].as_f64(), Some(9.0));
|
||||
// A negative tolerance is refused: nothing changes and the dialog stays open.
|
||||
app.run("tool.options", json!({"tool": "tangentCircle"})).unwrap();
|
||||
ok(&mut app, &[("center", FieldValue::Bool(true)), ("snapTolerance", FieldValue::Number(-2.0))]);
|
||||
assert!(held(&app, |d| d.is_some()), "a refusal keeps the dialog open");
|
||||
let o = app.session.tool_options_of("tangentCircle");
|
||||
assert_eq!((&o["center"], o["snapTolerance"].as_f64()), (&json!(false), Some(9.0)));
|
||||
}
|
||||
|
||||
/// The Tangent Circle tool's options dialog has a row for each option, a fractional snapping
|
||||
/// tolerance opens as it is, and every color has a label, in the tool's order.
|
||||
#[test]
|
||||
fn the_tangent_circle_options_have_their_rows_and_a_fractional_tolerance() {
|
||||
use craft::ui::patterns::form_dialogs::ParamKind;
|
||||
let mut app = app_with_window();
|
||||
let params = super::options_params("tangentCircle", crate::canvas::rulers::general_lengths(&app));
|
||||
let rows: Vec<(&str, &str)> = params.iter().map(|p| (p.key.as_str(), p.label.as_str())).collect();
|
||||
assert_eq!(
|
||||
rows,
|
||||
[
|
||||
("radius", "Radius"),
|
||||
("center", "Circle Center"),
|
||||
("radii", "Circle Radii Lines"),
|
||||
("color", "Color"),
|
||||
("snapTolerance", "Snap Tolerance"),
|
||||
("snapWithoutGuides", "Snap When Smart Guides Are Off"),
|
||||
]
|
||||
);
|
||||
let colors = params.iter().find_map(|p| match &p.kind {
|
||||
ParamKind::Choice { options, .. } if p.key == "color" => {
|
||||
Some(options.iter().map(|(id, label)| (id.clone(), label.as_str().to_owned())).collect::<Vec<_>>())
|
||||
}
|
||||
_ => None,
|
||||
});
|
||||
let expected: Vec<(String, String)> = vectorcraft_tools::addons::tangent_circle::COLORS
|
||||
.iter()
|
||||
.zip(super::TANGENT_CIRCLE_COLORS)
|
||||
.map(|((name, _), label)| ((*name).to_owned(), label.to_owned()))
|
||||
.collect();
|
||||
assert_eq!(colors, Some(expected));
|
||||
for (name, _) in vectorcraft_tools::addons::tangent_circle::COLORS {
|
||||
assert!(super::TANGENT_CIRCLE_COLORS.iter().any(|label| label.to_lowercase() == *name), "{name} has a label");
|
||||
}
|
||||
app.run("tool.setOption", json!({"tool": "tangentCircle", "values": {"snapTolerance": 7.5}})).unwrap();
|
||||
app.run("tool.options", json!({"tool": "tangentCircle"})).unwrap();
|
||||
assert_eq!(held(&app, |d| d.expect("the held dialog").fields().number("snapTolerance")), Some(7.5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_parametric_shape_panel_edits_the_selected_shape_or_the_tools_next_one() {
|
||||
let mut app = app();
|
||||
|
||||
+11
-4
@@ -15048,8 +15048,9 @@ Tools:
|
||||
preferences): `diameter` (0.25 to 200 pt, 20), `tolerance` (how near two anchors count as coincident, 0 to 3 pt,
|
||||
0.002) and `together` (Keep Shared Points Together).
|
||||
- **Tangent Circle Tool** (`tangentCircle`): draws a circle on two path segments of any unlocked paths, selected or
|
||||
not. A click picks the first segment; over a second segment the circle that would be drawn shows (red) with its
|
||||
center, its radii to the two touch points and its radius, or a note that there is none. A click there draws the
|
||||
not. A click picks the segment nearest the pointer within reach (see `snapTolerance` below) as the first segment;
|
||||
over a second segment the circle that would be drawn shows (in `color`) with its center cross, its radii to the two
|
||||
touch points (`center`, `radii`) and its radius, or a note that there is none. A click there draws the
|
||||
circle that is tangent to the first segment at the point clicked and touches the second (its center on the first
|
||||
segment's normal there). With Shift the circle instead has the tool's `radius` and may touch the first segment
|
||||
anywhere along it. A drag from the second segment sets the radius to the drag's length, and the circle may again
|
||||
@@ -15069,8 +15070,14 @@ Tools:
|
||||
change to the first segment that makes no undo step (a live preview, or one that was canceled) forgets the first
|
||||
segment. The circle is looked for again whenever either segment no longer has the shape it was found on, so a
|
||||
canceled preview does not leave a circle worked out on the previewed paths.
|
||||
Option (`tool.setOption`, or a double-click on the tool): `radius` (pt, 0.01 to 1000000, 36). `tool.setOption`
|
||||
gives an error for a value outside that range or one that is not a number, and for any other option.
|
||||
Options (`tool.setOption`, or a double-click on the tool; kept with the preferences): `radius` (pt, 0.01 to
|
||||
1000000, 36); `center` and `radii` (true or false, both true) show the center cross and the radii; `color` (`red`,
|
||||
`blue`, `magenta`, `green`, `black` or `gray`; `red`) is the color of the circle, the cross, the radii and the note;
|
||||
`snapTolerance` (screen pixels, 0 to 25, 3; VectorCraft's own range and default) is how near the pointer picks a
|
||||
segment while Smart Guides are on (their Snapping Tolerance counts instead when it is larger) or while they are off
|
||||
with `snapWithoutGuides` (true or false, true) on. Otherwise a segment is picked within the Selection Tolerance, which is also the least reach with snapping.
|
||||
`tool.setOption` gives an error for a value outside an option's range, of the wrong type, or a color not listed, and
|
||||
for any other option, and then sets none of the values.
|
||||
- **Trim at Crossings Tool** (`trimAtCrossings`): removes stretches of paths between the places where they are crossed,
|
||||
on any path that can be edited, selected or not. A click runs `addon.pathtools.trim` with `at`, for the path within 4
|
||||
screen pixels of the pointer. A drag draws a rectangle and runs it with `rect` on release; once the pointer has
|
||||
|
||||
@@ -3069,6 +3069,8 @@ A VectorCraft addition, not a feature of the reference app, so no area score mov
|
||||
|
||||
A VectorCraft addition, so no area score moves. The Tangent Circle Tool (`tangentCircle`; Object › Plug-ins › Path Precision Tools and the All Tools drawer) draws a circle on two clicked path segments: tangent to the first at the point clicked (its center on the normal there) and touching the second segment or one beside it on its subpath, the touch nearest the pointer winning. Shift gives the circle the tool's radius, and a drag from the second segment sets the radius to the drag's length (Shift: steps of 1, 2 or 5 times a power of 10 pt, at least 4 screen pixels; Cmd/Ctrl: a tenth of the movement); with a radius the circle may touch the first segment anywhere along it. Before the click the circle shows with its center, radii and radius, or a note says there is none. The circles are found by sampling the distance to the second segments along the first segment's normal (or along the first segment, for a radius) and taking the places where it equals the radius (samples, bisection where it crosses, and a search where it only touches). Left out are circles whose nearest point of the second segments is not on the circle (within a millionth of the radius: where the first segment turns back on itself the distance jumps past the radius without a touch), circles that cross the first segment, circles that touch both segments at one point, circles without a finite radius above 0, circles too small or too large for three of their points to give them back in floating point, and circles that would reach past the canvas; a circle found twice (the same center, touching the first segment at the same point) is kept once. The circle is a new ellipse with the current paint, one undo step; the first segment stays picked until it is drawn, also when drawing fails or the press is canceled, and the circles are looked for again when a live preview, or one that was canceled, changes either segment without an undo step (a changed first segment is forgotten). Tests: `tangent_circle::tests` in `vectorcraft-pathops` (parallel and crossing lines, a curved second segment, a corner's fillet, lines twice the radius apart, a touch between the places tried, the ends of a line with its handles on its anchors, a circle that crosses the first segment, a first segment that turns back, no circle), `addons::tangent_circle::tests` in `vectorcraft-tools` (two clicks, Shift and the radius option, a drag with Shift and Cmd/Ctrl, no circle and Escape, a canceled press, a canceled preview, a circle its three points cannot draw, a circle past the canvas), the session test for a failed draw in `vectorcraft-engine` and the Path Precision Tools menu, options, drawer and catalog tests in `vectorcraft-ui-egui`. Commands: `docs/mcp.md` › Path Precision Tools add-on.
|
||||
|
||||
The tool's options dialog also sets the preview and how a segment is picked, the options the help page lists (https://docs.astutegraphics.com/subscribe/tangent-circle-tool): Circle Center and Circle Radii Lines (`center`, `radii`) show or hide the center cross and the radii, Color (`color`: red, blue, magenta, green, black or gray) colors the circle, the cross, the radii and the note, Snap Tolerance (`snapTolerance`, screen pixels) is how near the pointer picks a segment with Smart Guides on, the Smart Guides Snapping Tolerance counting when it is larger, and Snap When Smart Guides Are Off (`snapWithoutGuides`) keeps that reach with Smart Guides off; without it the Selection Tolerance applies. Of the segments within reach the nearest is picked. The defaults (both shown, red, 3 px, snapping on) and the 0 to 25 px range are VectorCraft's own; they are kept with the preferences, and `tool.setOption` gives an error for a value an option does not take. Tests: `addons::tangent_circle::tests` in `vectorcraft-tools` (the preview options, the snapping reach, the options' values) and `the_tangent_circle_options_set_the_preview_and_snapping` in `vectorcraft-ui-egui`.
|
||||
|
||||
## Path Precision Tools add-on: Trim at Crossings (2026-11-13)
|
||||
|
||||
A VectorCraft addition, not a feature of the reference app, so no area score moves. Object › Plug-ins › Path Precision Tools › Trim at Crossings Tool (also in the Scissors tool's group in both shipped toolbars, after the Knife, since 2026-11-16; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut) removes stretches of paths between the places where they are crossed by another path or by themselves, on any path that can be edited, selected or not. A click removes the stretch under the pointer, a drag removes every stretch its rectangle touches, and an Alt-drag removes every stretch its freehand line crosses; each is one undo step, and Escape during a drag removes nothing. A closed path that loses a stretch becomes open, an open path that loses a middle stretch becomes two paths with its appearance in its place in the stacking order, a path that nothing crosses is removed whole, and the stretches that stay get no new anchors. Hidden and locked paths, guides and clipping paths are not trimmed and do not count as crossing. Add Points at / Split at Crossings share the crossing search: segments that meet at an anchor now count where they cross again elsewhere, and with Self Crossings a curved segment that loops over itself crosses itself. Command `addon.pathtools.trim`; `vectorcraft_pathops::addons::pathtools::{crossings_on, spans, without_spans}`. Hovering shows in red the stretch a click would remove, worked out by the same code the command uses (`vectorcraft_tools::addons::trim::plan`), and a drag that reaches at most 32 paths shows what its release would remove; a preview spends at most a twentieth of the crossing work a click may (2026-11-15; tests `hovering_*`, `in_isolation_mode_*`, `a_path_whose_crossings_*` and `a_small_drag_*` in `addons::trim` in `vectorcraft-tools`, `hovering_with_the_tool_shows_the_stretch_its_click_removes` and `what_the_tool_shows_*` in `vectorcraft-engine`). Not yet: crossings with type, images and symbol instances. Tests: `crossings_on_*`, `segments_*`, `a_segment_that_loops_over_itself_crosses_itself`, `one_work_budget_*`, `spans_divide_*`, `a_subpath_without_*` and `a_slice_*` in `addons::pathtools::tests` in `vectorcraft-pathops`, `addons::trim` in `vectorcraft-tools` (click, rectangle, freehand line, Escape), `cmd::addons::pathtools::trim::tests` in `vectorcraft-engine` (a middle and an end stretch, a closed path opening, a rectangle and a line as one undo step, locked and hidden paths, guides and clipping paths, paths nothing crosses, compound path members, the selection, 3,000 other paths, a path too large to search left alone until touched, bad params refused), `the_plugins_submenu_selects_the_tools_and_opens_the_anchor_inspector` in `vectorcraft-ui-egui`, `edit_toolbar::tests` and `command_sweep`. Commands: `docs/mcp.md` › Path Precision Tools add-on. The tool shows the Knife's cursor, now drawn as a knife with the blade's point on the hotspot (2026-11-16; tests `trim_at_crossings_is_in_the_scissors_flyout` and `a_saved_toolbar_without_trim_at_crossings_keeps_its_layout` in `edit_toolbar::tests`, `trim_at_crossings_is_in_the_scissors_group_once` in `addons::tests`, `headless_backend_methods` in `vectorcraft-mcp`, `the_knife_shows_a_knife_with_its_point_on_the_hotspot` in `cursors::tests` and `drawing_tools_show_their_own_cursor` in `vectorcraft-tools`).
|
||||
|
||||
+1
-1
@@ -556,7 +556,7 @@ next unit in the order a right-click on a ruler lists them, from Feet back to Po
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Divide into Dashes… (Dash and Gap in any unit, Fit to Corners and Ends, Remove Gaps; Preview) cuts the selected paths, or only their direct-selected segments, into open pieces along the curve, keeping their appearance, one undo step | done | #4950; `addon.pathtools.divideDashes`, `crates/pathops/src/addons/pathtools/dashes.rs`, `crates/ui-egui/src/addons/pathtools/dashes.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Set Corners… (also a button in the Anchor Inspector's Corners section: Radius in any unit, Corner kind, Anchors: All, Odd-Numbered or Even-Numbered, counted from each path's first anchor; Angle: from … to …°, only the corners whose sides meet at an angle in that range; Preview) cuts corners on the chosen anchors of every selected path, one undo step | done | #5546, #5545; `addon.pathtools.cornerSet` (`every`, `minAngle`, `maxAngle`), `crates/ui-egui/src/addons/pathtools/set_corners.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Trim at Crossings Tool (also in the Scissors tool's group in both shipped toolbars, after the Knife, and listed there in the All Tools drawer; a toolbar edited before keeps its saved layout until Reset Toolbar; no shortcut until one is set in Edit › Keyboard Shortcuts › Tools; the Knife's cursor, drawn as a knife with the blade's point on the hotspot) removes stretches of paths between the places where they are crossed, on any editable path, selected or not: a click removes the stretch under the pointer, a drag removes every stretch its rectangle touches, and an Alt-drag removes every stretch its freehand line crosses; one undo step each; Escape during a drag removes nothing; hovering shows in red the stretch a click would remove, and a drag that reaches few paths shows what its release would remove | done | `addon.pathtools.trim` (in `crates/engine/src/cmd/addons/pathtools/trim.rs`), `crates/tools/src/addons/trim.rs` and their tests; not a feature of the reference app, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Tangent Circle Tool (also in the All Tools drawer): a click on a path segment, then on another, draws the circle tangent to the first at the point clicked that touches the second or a segment beside it; Shift uses the tool's radius (36 pt to start, set in its options) and a drag from the second segment sets the radius (Shift in round steps, Cmd/Ctrl slowly), the circle then touching the first segment anywhere along it; the circle shows with its center and radii first, or a note when there is none; one undo step | done | tool `tangentCircle` (in `crates/tools/src/addons/tangent_circle.rs`, geometry in `crates/pathops/src/addons/pathtools/tangent_circle/on_segments.rs`) and its tests; a VectorCraft addition, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Tangent Circle Tool (also in the All Tools drawer): a click on a path segment, then on another, draws the circle tangent to the first at the point clicked that touches the second or a segment beside it; Shift uses the tool's radius (36 pt to start, set in its options) and a drag from the second segment sets the radius (Shift in round steps, Cmd/Ctrl slowly), the circle then touching the first segment anywhere along it; the circle shows with its center and radii first, or a note when there is none (its options show or hide the center cross and the radii, set their color, and set how near a segment is picked with Smart Guides on or off); one undo step | done | tool `tangentCircle` (in `crates/tools/src/addons/tangent_circle.rs`, geometry in `crates/pathops/src/addons/pathtools/tangent_circle/on_segments.rs`) and its tests; a VectorCraft addition, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Expand Dashes into Paths turns each selected path's dashed stroke into separate open paths, one per dash, laid out as the stroke draws them (pattern, offset, Align Dashes to Corners and Path Ends), each keeping the stroke with the dashes off; one undo step | done | #4922; `addon.pathtools.expandDashes` (in `crates/engine/src/cmd/addons/pathtools.rs`, using the renderer's dash layout) and its tests; not a feature of the reference app, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Smooth Bridge… (Radius as a percentage of the smaller circle's radius, or with Constant Gap that radius plus a gap; Reach; Keep Originals; Preview) joins two selected circles into one outline with two concave arcs that touch both circles, or three or more each to the others within reach, united where the bridges connect, in place of the circles or above them (a pair within reach gets no bridge when its arcs would not reach both circles or would cross, or when its neck would be thinner than the precision its shape is united at; a circle bridged to no other stays as it is); one undo step | done | `addon.pathtools.bridge`, `crates/pathops/src/addons/pathtools/bridge.rs`, `crates/ui-egui/src/addons/pathtools/bridge.rs` and their tests; a VectorCraft addition, so it is not scored |
|
||||
| Path Precision Tools add-on (VectorCraft addition): Object › Plug-ins › Path Precision Tools › Tangent Circle… draws the circles that touch two selected paths or compound paths at a radius, or three of them, each touching the outlines without crossing them; Radius (two shapes), a Circle menu (All or one by number) and Preview; one undo step | done | `addon.pathtools.tangentCircle` (in `crates/engine/src/cmd/addons/pathtools/tangent_circle.rs`, geometry in `crates/pathops/src/addons/pathtools/tangent_circle.rs`) and its tests; a VectorCraft addition, so it is not scored |
|
||||
|
||||
Reference in New Issue
Block a user