diff --git a/crates/doc/src/corners.rs b/crates/doc/src/corners.rs index 56bbb29845..a4f4a683d6 100644 --- a/crates/doc/src/corners.rs +++ b/crates/doc/src/corners.rs @@ -6,8 +6,9 @@ use std::borrow::Cow; use std::collections::BTreeSet; use vectorcraft_geom::corners::{Corner, cut_corners, fitted_radii, path_corners}; +use vectorcraft_geom::kurbo::ParamCurveNearest; use vectorcraft_geom::shapes::{self, CornerKind}; -use vectorcraft_geom::{Affine, PathData, Point, Rect}; +use vectorcraft_geom::{Affine, ParamCurve, PathData, Point, Rect, SubPath}; use crate::node::{LiveShape, Node, NodeKind}; use crate::selection::AnchorRef; @@ -198,6 +199,46 @@ impl<'a> LiveCorners<'a> { &self.sources } + /// Whether any corner has a radius stored, so the path as drawn has its corners cut (or + /// cuts them again when an edit bends a straightened corner back). + pub fn is_cut(&self) -> bool { + self.radii.iter().any(|r| *r > 0.0) + } + + /// The anchors of `base` (subpath, anchor) that `anchors` of the path as drawn come from. + pub fn outline_anchors(&self, anchors: &BTreeSet) -> BTreeSet { + let ks: BTreeSet = anchors.iter().filter_map(|(si, ai)| self.sources.get(*si)?.get(*ai).copied()).collect(); + let mut out = BTreeSet::new(); + let mut first = 0; + for (si, sp) in self.base.subpaths.iter().enumerate() { + out.extend(ks.range(first..first + sp.anchors.len()).map(|k| (si, k - first))); + first += sp.anchors.len(); + } + out + } + + /// The first anchor of the path as drawn that anchor `(si, ai)` of `base` gives. + pub fn drawn_anchor(&self, (si, ai): AnchorRef) -> Option { + let first: usize = self.base.subpaths.get(..si)?.iter().map(|sp| sp.anchors.len()).sum(); + let k = first + ai; + self.sources.get(si)?.iter().position(|s| *s == k).map(|drawn| (si, drawn)) + } + + /// [`LiveCorners::drawn_anchor`] of each of `anchors`, counting the subpaths' anchors once. + pub fn drawn_anchors(&self, anchors: &BTreeSet) -> BTreeSet { + let mut out = BTreeSet::new(); + let mut first = 0; + for (si, sp) in self.base.subpaths.iter().enumerate() { + let Some(sources) = self.sources.get(si) else { break }; + for &(_, ai) in anchors.range((si, 0)..(si + 1, 0)) { + let k = first + ai; + out.extend(sources.iter().position(|s| *s == k).map(|drawn| (si, drawn))); + } + first += sp.anchors.len(); + } + out + } + /// The radius and kind `corners` share (each `None` when they differ, or for no corners). /// Radius is what was set ([`LiveCorners::radius`]: document lengths, or a fraction in 0..1 /// when [`LiveCorners::radii_relative`]), not the fitted draw size ([`LiveCorners::drawn_radius`]). @@ -325,13 +366,8 @@ pub fn edit_corner_anchors( anchors: &BTreeSet, edit: impl FnOnce(&mut PathData, &BTreeSet), ) -> Option<()> { - live.as_ref()?; - if let Some(LiveShape::Rectangle { xf, .. }) = live.as_deref() { - let [a, b, c, d, _, _] = xf.as_coeffs(); - let scale = (a * a + b * b).max(c * c + d * d).max(1e-12); - if ((a * a + b * b) - (c * c + d * d)).abs() > 1e-9 * scale || (a * c + b * d).abs() > 1e-9 * scale { - return None; - } + if live.as_deref().is_none_or(uneven_rectangle) { + return None; } let (mut base, moved, mut radii, kinds, relative) = { let lc = LiveCorners::new(path, live.as_deref())?; @@ -369,6 +405,156 @@ pub fn edit_corner_anchors( Some(()) } +/// Whether `live` is a rectangle whose transform shears it or scales it unevenly. +fn uneven_rectangle(live: &LiveShape) -> bool { + let LiveShape::Rectangle { xf, .. } = live else { return false }; + let [a, b, c, d, _, _] = xf.as_coeffs(); + let scale = (a * a + b * b).max(c * c + d * d).max(1e-12); + ((a * a + b * b) - (c * c + d * d)).abs() > 1e-9 * scale || (a * c + b * d).abs() > 1e-9 * scale +} + +/// Change the anchors of the uncut outline of a path with cut Live Corners and cut the corners +/// again. `edit` gets the outline in document space and returns, for each of its anchors after +/// the change, the index of the anchor before the change it is (`None` for an anchor it added). +/// Each corner keeps its radius and kind, and an added anchor has none; relative radii keep their +/// document lengths. A live rectangle or polygon becomes a [`LiveShape::Path`] with that outline, +/// and a path left with no radius and no corner kind other than round (or with no anchor) is a +/// plain path. Returns `None`, leaving the path unchanged, as [`edit_corner_anchors`] does, or when +/// `edit` returns `None` or does not list one entry per anchor. +fn rebuild_corner_outline( + path: &mut PathData, + live: &mut Option>, + edit: impl FnOnce(&mut PathData) -> Option>>, +) -> Option<()> { + if live.as_deref().is_none_or(uneven_rectangle) { + return None; + } + let (mut base, lengths, kinds, relative) = { + let lc = LiveCorners::new(path, live.as_deref())?; + if !lc.is_cut() { + return None; + } + let base = lc.base.transformed(lc.xf); + let mut radii = lc.radii.clone(); + radii.resize(base.anchor_count(), 0.0); + let lengths = if lc.relative { + let mut l = LiveShape::Path { base: base.clone(), radii, kinds: vec![], radii_relative: true }; + convert_radii_relative(&mut l, false); + let LiveShape::Path { radii, .. } = l else { return None }; + radii + } else { + radii + }; + (base, lengths, lc.kinds.clone(), lc.relative) + }; + let from = edit(&mut base)?; + if from.len() != base.anchor_count() { + return None; + } + let radii: Vec = from.iter().map(|f| f.and_then(|i| lengths.get(i).copied()).unwrap_or(0.0)).collect(); + let kinds: Vec = from.iter().map(|f| f.and_then(|i| kinds.get(i).copied()).unwrap_or_default()).collect(); + if radii.iter().all(|r| *r <= 0.0) && kinds.iter().all(|k| *k == CornerKind::Round) { + *path = base; + *live = None; + return Some(()); + } + let mut l = LiveShape::Path { base, radii, kinds, radii_relative: false }; + convert_radii_relative(&mut l, relative); + *path = l.to_path(); + *live = Some(Box::new(l)); + Some(()) +} + +/// Add an anchor at `t` (0..1) on segment `seg` of subpath `si` of a path with cut Live Corners: +/// it goes on the side of the uncut outline that the segment is part of, at the point of the +/// segment at `t`, and the corners are cut again, keeping their radii and kinds +/// ([`rebuild_corner_outline`]). Returns the new anchor's index in subpath `si` of the path as +/// drawn, or `None`, leaving the path unchanged, for a segment that is a corner's cut, a segment +/// that does not exist, or a path [`edit_corner_anchors`] leaves as it is. +pub fn insert_corner_anchor(path: &mut PathData, live: &mut Option>, si: usize, seg: usize, t: f64) -> Option { + let (target, first, local) = { + let lc = LiveCorners::new(path, Some(live.as_deref()?))?; + let sp = path.subpaths.get(si)?; + let from = lc.sources.get(si)?; + if seg >= sp.segment_count() || from.len() != sp.anchors.len() { + return None; + } + let (ka, kb) = (*from.get(seg)?, *from.get((seg + 1) % from.len())?); + // Both ends from one corner: the segment is that corner's cut. + if ka == kb { + return None; + } + let first: usize = lc.base.subpaths.get(..si)?.iter().map(|s| s.anchors.len()).sum(); + let outline = lc.base.subpaths.get(si)?; + let local = ka.checked_sub(first).filter(|a| *a < outline.anchors.len())?; + if !outline.has_segment(local, true) || kb != first + (local + 1) % outline.anchors.len() { + return None; + } + (sp.segment(seg).eval(t.clamp(0.0, 1.0)), first, local) + }; + let new_index = first + local + 1; + let (mut p, mut l) = (path.clone(), live.clone()); + rebuild_corner_outline(&mut p, &mut l, |base| { + let sp = base.subpaths.get_mut(si)?; + // A straight side is a cubic with its handles on its ends too, so the parameter of the + // point nearest `target` puts the new anchor there on either kind of side. + let tb = sp.segment(local).nearest(target, 1e-9).t; + sp.insert_anchor(local, tb.clamp(0.0, 1.0)); + Some((0..base.anchor_count()).map(|j| if j < new_index { Some(j) } else { (j > new_index).then(|| j - 1) }).collect()) + })?; + let drawn = match LiveCorners::new(&p, l.as_deref()) { + Some(lc) => lc.sources.get(si)?.iter().position(|k| *k == new_index)?, + None => local + 1, + }; + *path = p; + *live = l; + Some(drawn) +} + +/// Remove the anchors of the uncut outline that `anchors` (of the path as drawn) come from, so a +/// cut corner goes when either of its anchors is removed, and cut the remaining corners again, +/// keeping their radii and kinds ([`rebuild_corner_outline`]). `remove` takes the listed anchors +/// (in ascending order) out of one subpath of the outline, refitting the curve round each; a +/// subpath left with fewer than two anchors is removed, and a path left with none is an empty plain +/// path. Returns `None`, leaving the path unchanged, when no anchor maps to the outline, when +/// `remove` does not remove exactly the anchors listed, or for a path [`edit_corner_anchors`] +/// leaves as it is. +pub fn remove_corner_anchors( + path: &mut PathData, + live: &mut Option>, + anchors: &BTreeSet, + mut remove: impl FnMut(&mut SubPath, &[usize]), +) -> Option<()> { + let outline = LiveCorners::new(path, Some(live.as_deref()?))?.outline_anchors(anchors); + if outline.is_empty() { + return None; + } + let (mut p, mut l) = (path.clone(), live.clone()); + rebuild_corner_outline(&mut p, &mut l, |base| { + let mut from = vec![]; + let mut first = 0; + for (si, sp) in base.subpaths.iter_mut().enumerate() { + let n = sp.anchors.len(); + let gone: Vec = outline.range((si, 0)..=(si, usize::MAX)).map(|&(_, ai)| ai).collect(); + if !gone.is_empty() { + remove(sp, &gone); + if sp.anchors.len() + gone.len() != n { + return None; + } + } + if sp.anchors.len() >= 2 { + from.extend((0..n).filter(|ai| gone.binary_search(ai).is_err()).map(|ai| Some(first + ai))); + } + first += n; + } + base.subpaths.retain(|sp| sp.anchors.len() >= 2); + Some(from) + })?; + *path = p; + *live = l; + Some(()) +} + #[cfg(test)] mod tests { use super::*; @@ -431,6 +617,21 @@ mod tests { assert_eq!((path, live), (star, None)); } + /// Mapping a set of outline anchors gives the same anchors as drawn as mapping each one. + #[test] + fn drawn_anchors_match_drawn_anchor_across_subpaths() { + let mut star = shapes::star(Point::new(100.0, 100.0), 50.0, 25.0, 5, 0.0); + star.subpaths.extend(shapes::star(Point::new(300.0, 100.0), 50.0, 25.0, 4, 0.0).subpaths); + let (mut path, mut live) = (star, None); + set_corners(&mut path, &mut live, &set(&[0, 2, 10, 13]), Some(5.0), None); + let c = LiveCorners::new(&path, live.as_deref()).unwrap(); + let refs: BTreeSet = (0..3).flat_map(|si| (0..12).map(move |ai| (si, ai))).collect(); + let one_by_one: BTreeSet = refs.iter().filter_map(|r| c.drawn_anchor(*r)).collect(); + assert_eq!(one_by_one.len(), 18, "ten and eight outline anchors"); + assert_eq!(c.drawn_anchors(&refs), one_by_one); + assert_eq!(c.drawn_anchors(&BTreeSet::from([(1, 3)])), BTreeSet::from([(1, c.drawn_anchor((1, 3)).unwrap().1)])); + } + /// A polygon's corners are cut in the document and survive a change of sides when shared. #[test] fn polygon_corners_follow_their_sides() { diff --git a/crates/doc/src/lib.rs b/crates/doc/src/lib.rs index 3a5efc09a5..5466d2122b 100644 --- a/crates/doc/src/lib.rs +++ b/crates/doc/src/lib.rs @@ -103,7 +103,7 @@ pub use appearance::{ }; pub use assets::ExportAsset; pub use compound_shape::ShapeMode; -pub use corners::{LiveCorners, edit_corner_anchors, rebase_relative_radii}; +pub use corners::{LiveCorners, edit_corner_anchors, insert_corner_anchor, rebase_relative_radii, remove_corner_anchors}; pub use depth::{MAX_DEPTH, MAX_SYMBOL_NODES}; pub use graph::{ ColumnDesign, ColumnType, DEFAULT_FILLED_LINE_WIDTH, FILLED_LINE_OUTLINE_WIDTH, Fractions, GraphDesign, GraphKind, GraphSpec, LabelRows, diff --git a/crates/engine/src/cmd/draw2.rs b/crates/engine/src/cmd/draw2.rs index 13291b5307..4311fdf290 100644 --- a/crates/engine/src/cmd/draw2.rs +++ b/crates/engine/src/cmd/draw2.rs @@ -31,7 +31,7 @@ mod freehand; mod quickpen; mod smooth; -pub(super) use anchors::{following_anchors, remove_anchors_of}; +pub(super) use anchors::remove_anchors_following; pub use commands::specs; pub(super) use common::{center_strokes, ids_json, replace_with_pieces, usize_opt, with_anchor_path}; pub(super) use cut::{components, erase_outline}; diff --git a/crates/engine/src/cmd/draw2/anchors.rs b/crates/engine/src/cmd/draw2/anchors.rs index a1271a39a9..9d23053e2c 100644 --- a/crates/engine/src/cmd/draw2/anchors.rs +++ b/crates/engine/src/cmd/draw2/anchors.rs @@ -129,7 +129,12 @@ pub(super) fn remove_anchor(s: &mut Session, p: &Value) -> Result { sel.segments.remove(&id); return Ok(false); } - let sp = path_mut(d, id)?.subpaths.get(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?; + let path = match d.node(id).map(|n| &n.kind) { + Some(NodeKind::Path { path, .. }) => path, + Some(_) => return Err(EngineError::Other(format!("object {id} is not a path"))), + None => return Err(EngineError::NoNode(id)), + }; + let sp = path.subpaths.get(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?; if ai >= sp.anchors.len() { return Err(EngineError::Other("no such anchor".into())); } @@ -160,15 +165,14 @@ pub(super) fn remove_anchors(s: &mut Session, _: &Value) -> Result { let mut gone = Vec::new(); let mut emptied = Beside::replacing(d, &jobs.iter().map(|(id, _)| *id).collect::>()); for (id, anchors) in jobs { - let shape: Vec<(usize, bool)> = - d.node(id).and_then(Node::path_data).map(|p| p.subpaths.iter().map(|sp| (sp.anchors.len(), sp.closed)).collect()).unwrap_or_default(); - let next = following_anchors(&shape, &anchors); - if remove_anchors_of(d, sel, &mut emptied, id, anchors, false)? { - gone.push(id); - } else if !next.is_empty() { + match remove_anchors_following(d, sel, &mut emptied, id, anchors, false)? { + None => gone.push(id), // The next anchor along is selected, so the next Remove Anchor Points goes on from // there without picking it first (#2241). - sel.anchors.insert(id, next); + Some(next) if !next.is_empty() => { + sel.anchors.insert(id, next); + } + Some(_) => {} } } emptied.finish(d)?; @@ -225,12 +229,41 @@ pub(in crate::cmd) fn remove_anchors_of( sel: &mut Selection, emptied: &mut Beside, id: NodeId, - mut anchors: Vec<(usize, usize)>, + anchors: Vec<(usize, usize)>, curvature: bool, ) -> Result { - // The last first, so the indexes still to come stay valid. - anchors.sort_unstable_by(|a, b| b.cmp(a)); + Ok(remove_anchors_following(d, sel, emptied, id, anchors, curvature)?.is_none()) +} + +/// [`remove_anchors_of`], returning `None` when the path went, else the anchors that follow the +/// removed ones in each subpath ([`following_anchors`]), numbered as the path is after the removal. +/// A path with cut Live Corners keeps them ([`vectorcraft_doc::remove_corner_anchors`]): the anchors +/// of its uncut outline that `anchors` come from are removed, so removing either anchor of a cut +/// corner removes that corner, and the following anchors are those of the outline. +pub(in crate::cmd) fn remove_anchors_following( + d: &mut Document, + sel: &mut Selection, + emptied: &mut Beside, + id: NodeId, + mut anchors: Vec<(usize, usize)>, + curvature: bool, +) -> Result>> { + anchors.sort_unstable(); anchors.dedup(); + if let Some(next) = remove_live_corner_anchors(d, id, &anchors, curvature) { + if d.node(id).and_then(Node::path_data).is_none_or(PathData::is_empty) { + emptied.put(d, id, vec![])?; + return Ok(None); + } + sel.anchors.remove(&id); + sel.segments.remove(&id); + return Ok(Some(next)); + } + let shape: Vec<(usize, bool)> = + d.node(id).and_then(Node::path_data).map(|p| p.subpaths.iter().map(|sp| (sp.anchors.len(), sp.closed)).collect()).unwrap_or_default(); + let next = following_anchors(&shape, &anchors); + // The last first, so the indexes still to come stay valid. + anchors.reverse(); let path = path_mut(d, id)?; let mut rest = &anchors[..]; while let Some(&(si, _)) = rest.first() { @@ -246,14 +279,41 @@ pub(in crate::cmd) fn remove_anchors_of( } } path.subpaths.retain(|sp| sp.anchors.len() >= 2); - let gone = path.is_empty(); - if gone { + if path.is_empty() { emptied.put(d, id, vec![])?; - } else { - sel.anchors.remove(&id); - sel.segments.remove(&id); + return Ok(None); } - Ok(gone) + sel.anchors.remove(&id); + sel.segments.remove(&id); + Ok(Some(next)) +} + +/// Remove `anchors` (ascending, no repeats) of path `id` when it has cut Live Corners, keeping +/// them live ([`vectorcraft_doc::remove_corner_anchors`]), and return the anchors as drawn that +/// follow the removed ones; `None`, changing nothing, when the corners can't stay live. +fn remove_live_corner_anchors(d: &mut Document, id: NodeId, anchors: &[(usize, usize)], curvature: bool) -> Option> { + let NodeKind::Path { path, live, .. } = &mut d.node_mut(id)?.kind else { return None }; + // A plain path has no corners to keep. + live.as_ref()?; + let set: BTreeSet<(usize, usize)> = anchors.iter().copied().collect(); + let lc = vectorcraft_doc::LiveCorners::new(path, live.as_deref())?; + let shape: Vec<(usize, bool)> = lc.base.subpaths.iter().map(|sp| (sp.anchors.len(), sp.closed)).collect(); + let outline: Vec<(usize, usize)> = lc.outline_anchors(&set).into_iter().collect(); + drop(lc); + vectorcraft_doc::remove_corner_anchors(path, live, &set, |sp, gone| { + if curvature { + for &ai in gone.iter().rev() { + vectorcraft_tools::draw2::curvature_remove(sp, ai); + } + } else { + po::remove_anchors(sp, gone); + } + })?; + let next = following_anchors(&shape, &outline); + Some(match vectorcraft_doc::LiveCorners::new(path, live.as_deref()) { + Some(lc) => lc.drawn_anchors(&next), + None => next, + }) } pub(super) fn convert_anchor(s: &mut Session, p: &Value) -> Result { diff --git a/crates/engine/src/cmd/draw2/commands.rs b/crates/engine/src/cmd/draw2/commands.rs index eda5d19d23..46d862ae27 100644 --- a/crates/engine/src/cmd/draw2/commands.rs +++ b/crates/engine/src/cmd/draw2/commands.rs @@ -57,7 +57,7 @@ pub fn specs() -> Vec { "Delete Anchor Point", [], None, - "{id (a path, or type on a path), subpath?, anchor, curvature?} remove one anchor, re-fitting the curve (with curvature: true, the curve where it was follows the remaining anchors, as the Curvature tool curves its points); type on a path keeps two anchors on its path at least", + "{id (a path, or type on a path), subpath?, anchor, curvature?} remove one anchor, re-fitting the curve (with curvature: true, the curve where it was follows the remaining anchors, as the Curvature tool curves its points); type on a path keeps two anchors on its path at least; on a path with rounded Live Corners, the corner the anchor belongs to is removed and the other corners stay live", has_doc, remove_anchor ), @@ -66,7 +66,7 @@ pub fn specs() -> Vec { "Remove Anchor Points", ["Object", "Path"], None, - "{} remove the direct-selected anchors without opening their paths, refitting the curve round each; the anchor after each removed one is selected, so running it again goes on along the path → {removedObjects}", + "{} remove the direct-selected anchors without opening their paths, refitting the curve round each; the anchor after each removed one is selected, so running it again goes on along the path; on a path with rounded Live Corners, the corners the anchors belong to are removed and the other corners stay live → {removedObjects}", has_anchors, remove_anchors ), diff --git a/crates/engine/src/cmd/path.rs b/crates/engine/src/cmd/path.rs index 22bc93bb86..0907b3fca8 100644 --- a/crates/engine/src/cmd/path.rs +++ b/crates/engine/src/cmd/path.rs @@ -1,6 +1,6 @@ //! Path editing commands (used by the Pen and Direct Selection tools and Object → Path). -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::{BTreeMap, BTreeSet, HashMap}; use std::sync::Arc; use serde_json::{Value, json}; @@ -149,7 +149,7 @@ pub fn specs() -> Vec { "Add Anchor Point", [], None, - "{id (a path, or type on a path), subpath?, segment, t: 0..1, selectAnchor?: bool (the path becomes the selection with only the new anchor direct-selected, also when it is selected)} add an anchor at t on the segment → {anchor}; the direct-selected anchors and selected segments keep the same points (a selected segment it splits stays selected as its two halves), and a path that isn't selected becomes the selection with the new anchor direct-selected; type on a path is left selected whole, with no direct-selected anchors (with selectAnchor, or when it wasn't selected, it becomes the selection)", + "{id (a path, or type on a path), subpath?, segment, t: 0..1, selectAnchor?: bool (the path becomes the selection with only the new anchor direct-selected, also when it is selected)} add an anchor at t on the segment → {anchor}; the direct-selected anchors and selected segments keep the same points (a selected segment it splits stays selected as its two halves), and a path that isn't selected becomes the selection with the new anchor direct-selected; type on a path is left selected whole, with no direct-selected anchors (with selectAnchor, or when it wasn't selected, it becomes the selection); on a path with rounded Live Corners, an anchor added on a side keeps the corners live (the selection follows its corners), and one added on a corner's arc makes the path plain and answers with a warning", has_doc, insert_anchor ), @@ -2158,18 +2158,9 @@ pub(crate) fn delete_anchors_joined(s: &mut Session, p: &Value, keep_joined: boo if d.node(*id).is_none() { continue; } - if keep_joined - && !set.is_empty() - && !segments.contains_key(id) - && let Some(path) = d.node(*id).and_then(|n| match &n.kind { - NodeKind::Path { path, .. } => Some(path), - _ => None, - }) - { - let shape: Vec<(usize, bool)> = path.subpaths.iter().map(|sp| (sp.anchors.len(), sp.closed)).collect(); + if keep_joined && !set.is_empty() && !segments.contains_key(id) && d.node(*id).is_some_and(|n| matches!(n.kind, NodeKind::Path { .. })) { let anchors: Vec<(usize, usize)> = set.iter().copied().collect(); - let next = super::draw2::following_anchors(&shape, &anchors); - if !super::draw2::remove_anchors_of(d, selection, &mut emptied, *id, anchors, false)? { + if let Some(next) = super::draw2::remove_anchors_following(d, selection, &mut emptied, *id, anchors, false)? { survivors.push(*id); following.push((*id, next)); } @@ -2470,6 +2461,87 @@ fn stretch_weights(anchors: &Anchors, closed: bool, roles: &[Stretch]) -> Vec<[f /// the same points. /// A selected segment that the new anchor splits stays selected as its two halves, and the new /// anchor joins its ends in the anchors that move with it. +/// After anchor `new` of the uncut outline of path `id` was added on its segment `split` as drawn, +/// and the path's corners were cut again, select the segments as drawn that run between the same +/// anchors of the outline as `segments` (the path's selected segments before), each listed in +/// `before` and `after` as [`corner_sources`] gives them, `before` numbered as the outline is after +/// the addition. A selected `split` gives both its halves, and the new anchor is selected with +/// them, as [`renumber_after_insert`] selects them on a plain path. A segment whose two ends were +/// in `held` (the selected anchors that end a selected segment, as drawn before) has the ends of +/// its segments as drawn selected, and no other anchor of their corners. +#[allow(clippy::too_many_arguments)] +fn remap_corner_segments( + sel: &mut Selection, + id: NodeId, + segments: &BTreeSet, + held: &BTreeSet, + before: &[Vec], + after: &[Vec], + split: SegmentRef, + new: usize, +) { + let ends = |sources: &[Vec], (si, g): SegmentRef| { + let v = sources.get(si)?; + Some((*v.get(g)?, *v.get((g + 1) % v.len())?)) + }; + // Each subpath's segments as drawn by the corners at their ends, the first one for each pair. + let index: Vec> = after + .iter() + .enumerate() + .map(|(si, v)| { + let mut m = HashMap::new(); + for g in 0..v.len() { + if let Some(pair) = ends(after, (si, g)) { + m.entry(pair).or_insert(g); + } + } + m + }) + .collect(); + let drawn = |si: usize, pair: (usize, usize)| index.get(si).and_then(|m| m.get(&pair)).map(|&g| (si, g)); + let mut out = BTreeSet::new(); + let mut picked = BTreeSet::new(); + for &r in segments { + let Some((a, b)) = ends(before, r) else { continue }; + let found: Vec = if r == split { + [drawn(r.0, (a, new)), drawn(r.0, (new, b))].into_iter().flatten().collect() + } else { + drawn(r.0, (a, b)).into_iter().collect() + }; + let len = before.get(r.0).map_or(0, Vec::len); + if len > 0 && held.contains(&r) && held.contains(&(r.0, (r.1 + 1) % len)) { + let n = after.get(r.0).map_or(0, Vec::len); + picked.extend(found.iter().flat_map(|&(si, g)| [(si, g), (si, (g + 1) % n.max(1))])); + } + if r == split + && let Some(ai) = after.get(r.0).and_then(|v| v.iter().position(|k| *k == new)) + { + picked.insert((r.0, ai)); + } + out.extend(found); + } + if !picked.is_empty() { + sel.anchors.entry(id).or_default().extend(picked); + } + if sel.anchors.get(&id).is_some_and(BTreeSet::is_empty) { + sel.anchors.remove(&id); + } + if !out.is_empty() { + sel.segments.insert(id, out); + } +} + +/// The anchors as drawn that end the segments in `segments`, on subpaths of the lengths `sources` +/// lists ([`corner_sources`]). +fn segment_ends(segments: &BTreeSet, sources: &[Vec]) -> BTreeSet { + let mut out = BTreeSet::new(); + for &(si, g) in segments { + let Some(n) = sources.get(si).map(Vec::len).filter(|n| *n > 0 && g < *n) else { continue }; + out.extend([(si, g), (si, (g + 1) % n)]); + } + out +} + fn renumber_after_insert(sel: &mut Selection, id: NodeId, si: usize, added: usize) { if let Some(set) = sel.anchors.get_mut(&id) { // A selected anchor index can name no anchor (`select.anchors` takes any index), so the @@ -2628,17 +2700,17 @@ fn insert_anchor(s: &mut Session, p: &Value) -> Result { let seg = index_opt(p, "segment", "path.insertAnchor")?.ok_or_else(|| bad("path.insertAnchor", "missing segment"))?; let t = number_or(p, "t", 0.5, "path.insertAnchor")?.clamp(0.0, 1.0); let select_anchor = switch_or(p, "selectAnchor", false, "path.insertAnchor")?; - let idx = s.edit("Add Anchor Point", |d, sel| { - let idx = super::draw2::with_anchor_path(d, id, |path| { - let sp = path.subpaths.get_mut(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?; - if seg >= sp.segment_count() { - return Err(EngineError::Other("no such segment".into())); - } - Ok(sp.insert_anchor(seg, t)) - })?; - // Type on a path is selected whole and keeps no direct-selected anchors, as `path.removeAnchor` - // leaves it: the arrow keys and `path.moveAnchors` move anchors of paths only. + let (idx, expanded) = s.edit("Add Anchor Point", |d, sel| { if matches!(d.node(id).map(|n| &n.kind), Some(NodeKind::Text(_))) { + let idx = super::draw2::with_anchor_path(d, id, |path| { + let sp = path.subpaths.get_mut(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?; + if seg >= sp.segment_count() { + return Err(EngineError::Other("no such segment".into())); + } + Ok(sp.insert_anchor(seg, t)) + })?; + // Type on a path is selected whole and keeps no direct-selected anchors, as `path.removeAnchor` + // leaves it: the arrow keys and `path.moveAnchors` move anchors of paths only. if select_anchor || !sel.contains(id) { sel.clear(); } @@ -2648,9 +2720,53 @@ fn insert_anchor(s: &mut Session, p: &Value) -> Result { sel.key_anchor = None; } sel.add(id); - return Ok(idx); + return Ok((idx, false)); } - renumber_after_insert(sel, id, si, idx); + let (path, live) = match d.node(id).map(|n| &n.kind) { + Some(NodeKind::Path { path, live, .. }) => (path, live), + Some(_) => return Err(EngineError::Other(format!("object {id} is not a path"))), + None => return Err(EngineError::NoNode(id)), + }; + if seg >= path.subpaths.get(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?.segment_count() { + return Err(EngineError::Other("no such segment".into())); + } + // A plain path has no corners to keep, so it skips the Live Corners work. + let (before, cut) = match live.as_deref().and_then(|l| vectorcraft_doc::LiveCorners::new(path, Some(l))) { + Some(lc) => (Some(lc.sources().to_vec()), lc.is_cut()), + None => (None, false), + }; + let kept = match (&before, d.node_mut(id).map(|n| &mut n.kind)) { + (Some(_), Some(NodeKind::Path { path, live, .. })) => vectorcraft_doc::insert_corner_anchor(path, live, si, seg, t), + _ => None, + }; + let after = if kept.is_some() { corner_sources(d, id) } else { None }; + let idx = match (kept, before, after) { + // The corners stay live: the selection follows the corners its anchors come from, the + // outline's anchors after the new one numbered one higher. + (Some(idx), Some(before), Some(after)) => { + let new = after.get(si).and_then(|v| v.get(idx)).copied().unwrap_or(usize::MAX); + let before: Vec> = before.iter().map(|v| v.iter().map(|k| if *k >= new { k + 1 } else { *k }).collect()).collect(); + let segments = sel.segments.get(&id).cloned().unwrap_or_default(); + // The ends of selected segments follow the segments, not their whole corners. + let ends = segment_ends(&segments, &before); + let mut held = BTreeSet::new(); + if let Some(set) = sel.anchors.get_mut(&id) { + held = set.intersection(&ends).copied().collect(); + set.retain(|r| !ends.contains(r)); + } + remap_corner_anchors(sel, id, &before, &after); + remap_corner_segments(sel, id, &segments, &held, &before, &after, (si, seg), new); + idx + } + _ => { + let path = path_mut(d, id)?; + let sp = path.subpaths.get_mut(si).ok_or_else(|| EngineError::Other("no such subpath".into()))?; + let idx = sp.insert_anchor(seg, t); + renumber_after_insert(sel, id, si, idx); + idx + } + }; + let expanded = cut && kept.is_none(); // A path that wasn't selected becomes the selection, its new anchor direct-selected, so // the point added shows and can be edited at once (#4237). `selectAnchor` does the same // for a path that is selected. @@ -2659,11 +2775,19 @@ fn insert_anchor(s: &mut Session, p: &Value) -> Result { sel.add(id); sel.anchors.entry(id).or_default().insert((si, idx)); } - Ok(idx) + Ok((idx, expanded)) })?; - Ok(json!({ "anchor": idx })) + let mut out = json!({ "anchor": idx }); + if expanded { + out["warning"] = json!(CORNERS_EXPANDED); + } + Ok(out) } +/// The status when adding an anchor point turned a path's Live Corners into plain anchor points. +/// Anchors added on a straight or curved side keep them; one added on a corner's curve does not. +const CORNERS_EXPANDED: &str = "Live Corners were expanded: the rounded corners are now plain anchor points"; + fn cut_at_anchors(s: &mut Session, _: &Value) -> Result { const C: &str = "path.cutAtAnchors"; let st = s.doc()?; diff --git a/crates/engine/src/tests/livecorners.rs b/crates/engine/src/tests/livecorners.rs index 46a4ace011..0d4e4a46ca 100644 --- a/crates/engine/src/tests/livecorners.rs +++ b/crates/engine/src/tests/livecorners.rs @@ -7,7 +7,7 @@ use std::collections::BTreeSet; use serde_json::{Value, json}; use vectorcraft_doc::{AnchorRef, LiveCorners, LiveShape, NodeKind}; use vectorcraft_geom::shapes::CornerKind; -use vectorcraft_geom::{Affine, Point}; +use vectorcraft_geom::{Affine, ParamCurve, Point}; use crate::*; @@ -1582,3 +1582,174 @@ fn a_nudge_the_pixel_grid_takes_back_with_an_object_selected_whole_records_no_un assert!(matches!(s.doc().unwrap().doc.node(id).unwrap().live_shape(), Some(LiveShape::Rectangle { .. }))); assert_eq!(s.doc().unwrap().doc, doc); } + +/// The segment of path `id` as drawn that runs from a cut of corner `a` of its uncut outline to +/// a cut of corner `b` (the same corner twice: that corner's curve). +fn segment_between(s: &Session, id: NodeId, a: usize, b: usize) -> usize { + let lc = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap(); + let from = &lc.sources()[0]; + (0..from.len()).find(|&i| from[i] == a && from[(i + 1) % from.len()] == b).unwrap_or_else(|| panic!("no segment {a} -> {b} in {from:?}")) +} + +/// The anchors of path `id` as drawn that come from `corners` of its uncut outline. +fn corner_anchors(s: &Session, id: NodeId, corners: &[usize]) -> BTreeSet { + let lc = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap(); + lc.anchors_of(&corners.iter().copied().collect()) +} + +/// Adding an anchor point on a side of a rounded rectangle puts it on that side and keeps every +/// corner live at its radius, in one undo step, with the direct-selected anchors still on their +/// corner. Delete Anchor Point on it leaves the rectangle's outline with its corners still live. +#[test] +fn adding_and_deleting_an_anchor_on_a_side_keeps_the_corners_live() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let before = node_path(&s, id).0; + let picked: Vec<[usize; 2]> = corner_anchors(&s, id, &[2]).into_iter().map(|(si, ai)| [si, ai]).collect(); + s.execute("select.anchors", &json!({"id": id.0, "anchors": picked, "mode": "set"})).unwrap(); + let seg = segment_between(&s, id, 0, 1); + let want = before.subpaths[0].segment(seg).eval(0.3); + let undo = s.doc().unwrap().history.undo.len(); + let r = s.execute("path.insertAnchor", &json!({"id": id.0, "segment": seg, "t": 0.3})).unwrap(); + assert!(r.get("warning").is_none(), "{r}"); + let ai = usize::try_from(r["anchor"].as_u64().unwrap()).unwrap(); + let (path, live) = node_path(&s, id); + assert!(matches!(live, Some(LiveShape::Path { .. })), "{live:?}"); + assert_eq!(live_radii(&s, id), Some(vec![10.0; 4])); + assert_eq!(path.anchor_count(), 9); + assert!(path.subpaths[0].anchors[ai].p.distance(want) < 1e-9, "{:?} vs {want:?}", path.subpaths[0].anchors[ai].p); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1); + // The new anchor is the outline's anchor 1, so the corner that was 2 is 3 now. + assert_eq!(selected_anchors(&s, id), Some(corner_anchors(&s, id, &[3]))); + + let r = s.execute("path.removeAnchor", &json!({"id": id.0, "anchor": ai})).unwrap(); + assert_eq!(r["removedObject"], false); + assert_eq!(live_radii(&s, id), Some(vec![10.0; 4])); + let after = node_path(&s, id).0; + assert_eq!(after.anchor_count(), 8); + for (_, _, a) in before.anchors() { + assert!(after.anchors().any(|(_, _, b)| b.p.distance(a.p) < 1e-9), "{:?} is still drawn", a.p); + } + s.execute("edit.undo", &json!({})).unwrap(); + s.execute("edit.undo", &json!({})).unwrap(); + assert_eq!(corners(&s, id), ([10.0; 4], [CornerKind::Round; 4], 8)); +} + +/// Selected segments of a rounded rectangle stay selected when an anchor point is added on a +/// side: a selected side that is split gives both its halves and the new anchor, and the other +/// selected segments stay on the same sides and curves. +#[test] +fn adding_an_anchor_keeps_the_selected_segments_on_their_sides() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let (top, curve, bottom) = (segment_between(&s, id, 0, 1), segment_between(&s, id, 2, 2), segment_between(&s, id, 2, 3)); + s.execute("select.segments", &json!({"id": id.0, "segments": [[0, top], [0, curve], [0, bottom]], "mode": "set"})).unwrap(); + let r = s.execute("path.insertAnchor", &json!({"id": id.0, "segment": top, "t": 0.5})).unwrap(); + let ai = usize::try_from(r["anchor"].as_u64().unwrap()).unwrap(); + // The new anchor is the outline's anchor 1, so corners 1, 2 and 3 are 2, 3 and 4 now. + let want: BTreeSet<_> = + [segment_between(&s, id, 0, 1), segment_between(&s, id, 1, 2), segment_between(&s, id, 3, 3), segment_between(&s, id, 3, 4)] + .map(|g| (0, g)) + .into(); + let st = s.doc().unwrap(); + assert_eq!(st.selection.segments.get(&id), Some(&want)); + assert!(st.selection.anchors.get(&id).is_some_and(|a| a.contains(&(0, ai))), "{:?}", st.selection.anchors); +} + +/// The anchors selected as the ends of selected segments stay just those ends when an anchor +/// point is added on another side: the far anchors of the corners at a selected side's ends are +/// not selected, so an arrow-key nudge does not move them. +#[test] +fn adding_an_anchor_selects_only_the_ends_of_the_selected_segments() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let (top, curve, bottom) = (segment_between(&s, id, 0, 1), segment_between(&s, id, 2, 2), segment_between(&s, id, 2, 3)); + s.execute("select.segments", &json!({"id": id.0, "segments": [[0, top], [0, curve]], "mode": "set"})).unwrap(); + s.execute("path.insertAnchor", &json!({"id": id.0, "segment": bottom, "t": 0.5})).unwrap(); + let n = node_path(&s, id).0.subpaths[0].anchors.len(); + // The new anchor is the outline's anchor 3, after the corners at the selected segments' ends. + let (top, curve) = (segment_between(&s, id, 0, 1), segment_between(&s, id, 2, 2)); + let want: BTreeSet = [top, (top + 1) % n, curve, (curve + 1) % n].map(|a| (0, a)).into(); + let st = s.doc().unwrap(); + assert_eq!(st.selection.anchors.get(&id), Some(&want)); + assert_eq!(st.selection.segments.get(&id), Some(&[(0, top), (0, curve)].into())); +} + +/// An anchor point added on a corner's curve turns the corners into plain anchor points, as +/// before, and the status bar says so. +#[test] +fn adding_an_anchor_on_a_corners_curve_expands_the_corners_and_warns() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let seg = segment_between(&s, id, 1, 1); + let r = s.execute("path.insertAnchor", &json!({"id": id.0, "segment": seg, "t": 0.5})).unwrap(); + assert!(r["warning"].as_str().is_some_and(|w| w.contains("Live Corners")), "{r}"); + let (path, live) = node_path(&s, id); + assert_eq!((path.anchor_count(), live), (9, None)); +} + +/// Delete Anchor Point on either anchor of a cut corner removes that corner from the outline, and +/// the other corners stay live at their radii. +#[test] +fn deleting_an_anchor_of_a_cut_corner_removes_the_corner_and_keeps_the_rest_live() { + for end in 0..2 { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let (_, ai) = corner_anchors(&s, id, &[1]).into_iter().nth(end).unwrap(); + let undo = s.doc().unwrap().history.undo.len(); + s.execute("path.removeAnchor", &json!({"id": id.0, "anchor": ai})).unwrap(); + assert_eq!(s.doc().unwrap().history.undo.len(), undo + 1); + let lc = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap(); + assert_eq!(lc.base.anchor_count(), 3, "end {end}"); + assert!(lc.corners.iter().all(|c| c.at.distance(Point::new(110.0, 10.0)) > 1.0), "the top-right corner went"); + assert_eq!(live_radii(&s, id), Some(vec![10.0; 3]), "end {end}"); + assert_eq!(node_path(&s, id).0.anchor_count(), 6); + } +} + +/// Remove Anchor Points on a cut corner of a rounded rectangle keeps the other corners live and +/// selects an anchor of the next corner along, so the next Remove Anchor Points goes on there. +#[test] +fn remove_anchor_points_on_a_cut_corner_selects_the_next_corner() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let picked: Vec<[usize; 2]> = corner_anchors(&s, id, &[1]).into_iter().map(|(si, ai)| [si, ai]).collect(); + s.execute("select.anchors", &json!({"id": id.0, "anchors": picked, "mode": "set"})).unwrap(); + s.execute("path.removeAnchors", &json!({})).unwrap(); + assert_eq!(live_radii(&s, id), Some(vec![10.0; 3])); + let lc = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap(); + // The bottom-right corner, which followed the removed one, is the outline's anchor 1 now. + assert!(lc.base.subpaths[0].anchors[1].p.distance(Point::new(110.0, 70.0)) < 1e-9); + assert_eq!(selected_anchors(&s, id), lc.drawn_anchor((0, 1)).map(|a| BTreeSet::from([a]))); +} + +/// Remove Anchor Points with one anchor of every cut corner selected removes every corner, so the +/// path goes, as a plain path with all its anchors removed does. +#[test] +fn removing_an_anchor_of_every_corner_removes_the_path() { + let (mut s, id) = session(); + run(&mut s, json!({"radius": 10})); + let lc = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap(); + let picked: Vec<[usize; 2]> = (0..4).filter_map(|k| lc.drawn_anchor((0, k))).map(|(si, ai)| [si, ai]).collect(); + assert_eq!(picked.len(), 4); + s.execute("select.anchors", &json!({"id": id.0, "anchors": picked, "mode": "set"})).unwrap(); + assert_eq!(s.execute("path.removeAnchors", &json!({})).unwrap()["removedObjects"], 1); + assert!(s.doc().unwrap().doc.node(id).is_none()); +} + +/// A relative radius keeps the length it is drawn at when an added anchor shortens the side its +/// corner's largest radius depends on. +#[test] +fn an_added_anchor_keeps_a_relative_radius_at_its_length() { + let (mut s, id) = session(); + run(&mut s, json!({"relativeRadii": true})); + let max = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap().corner(0).unwrap().max_radius(); + run(&mut s, json!({"radius": 0.25 * max})); + let drawn = LiveCorners::of(s.doc().unwrap().doc.node(id).unwrap()).unwrap().drawn_radius(0); + let seg = segment_between(&s, id, 0, 1); + s.execute("path.insertAnchor", &json!({"id": id.0, "segment": seg, "t": 0.5})).unwrap(); + let n = s.doc().unwrap().doc.node(id).unwrap(); + assert!(matches!(n.live_shape(), Some(LiveShape::Path { radii_relative: true, .. })), "{:?}", n.live_shape()); + let lc = LiveCorners::of(n).unwrap(); + assert!((lc.drawn_radius(0) - drawn).abs() < 1e-9, "{} vs {drawn}", lc.drawn_radius(0)); +} diff --git a/docs/mcp.md b/docs/mcp.md index 4407509e2b..93ebea938b 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9572,6 +9572,17 @@ unevenly scaled, when an arrow-key nudge's selected curved segments bend or hold direct-selected anchors is other than a move. A nudge that changes nothing, including one that the pixel-grid snap of a pixel-aligned path takes back (objects selected whole beside the anchors included), records no undo step and leaves Live Corners as they are: a live rectangle stays a live rectangle. These fallbacks edit the drawn anchors rather than recutting the uncut outline. +Adding and removing anchors keeps such corners live as well: `path.insertAnchor` on a straight or curved side puts the +new anchor on that side of the uncut outline, at the point the drawn segment has at `t`, with no radius. `path.removeAnchor`, +`path.removeAnchors` and the Delete key with `deleteKeepsPathsJoined` on remove the uncut corner each removed anchor +belongs to, so removing either end of a corner's arc removes that corner. The other corners are cut again at their radii +and kinds; a relative radius keeps the length it is drawn at, up to the corner's new largest radius. On `path.insertAnchor` +the selected anchors follow their corners, the selected segments stay on their sides with only their own ends selected, +and a selected segment that the new anchor splits stays selected as its two halves with the new anchor. Removing anchors +clears the path's selected anchors and segments, and `path.removeAnchors` then selects the first anchor of the next +anchor of the uncut outline along (a corner, or an anchor added on a side), or the anchor before the removed one at an open path's end. An anchor added on a corner's +arc, or on a path the fallbacks above apply to, makes the shape a plain path, and when the path had rounded corners +`path.insertAnchor` answers with a `warning`, which the status bar shows. `path.setHandle` with `symmetric: true` also places the anchor's other handle opposite the moved one at the same length, and the anchor keeps its kind. At an open end, where no segment leaves the anchor on the other side, `symmetric` has no effect and the handle moves as it would without it. Both `symmetric` and `independent` default to false, and a call with both true is @@ -10661,8 +10672,9 @@ the corners holding a Direct-Selected anchor, or every corner of a path selected hold no corner is left out. The pop-up has the corner kind, the radius (blank while the picked corners differ) and the rounding, Relative or Absolute (`relativeRadii`, which applies to each path as a whole; neither is chosen while the paths differ). A path without Live Corners is Absolute: Relative leaves it, an ellipse or a line as it is, with no -undo step. Moving a path's anchors with `path.moveAnchor`, `path.moveAnchors` or the arrow keys keeps Live Corners and -the radius mode under the rules above. An anchor edit that makes the shape a plain path ends Live Corners and resets +undo step. Moving a path's anchors with `path.moveAnchor`, `path.moveAnchors` or the arrow keys, and adding or removing +anchors with `path.insertAnchor`, `path.removeAnchor` or `path.removeAnchors`, keeps Live Corners and the radius mode +under the rules above. An anchor edit that makes the shape a plain path ends Live Corners and resets the radius mode to Absolute. With Relative rounding, a radius is compared as the fraction it stores (its share of the corner's maximum, at most all of it), so typing the radius diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 89a82c2607..983eb10a0b 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -869,6 +869,7 @@ since 2026-10-01. - **Shift-click on corner widgets (#5188):** with Direct Selection, when every corner of every selected path is selected (the paths selected whole), a Shift-click on a corner widget picks that corner alone, so the next drag rounds just it. When another selected path has only some corners picked, a Shift-click on a widget of a path selected whole deselects that corner and keeps the other picks. The other corners' widgets then show as not picked; a Shift-click on another corner's anchor or widget adds that corner, and a Shift-click on a picked widget deselects its corner. Corner widgets are chosen by clicking one and Shift-clicking the others ([a tutorial on rounded corners](https://logosbynick.com/?p=15787)). Test: `corners::tests::a_shift_click_on_a_widget_of_a_whole_path_picks_its_corner`. - **Picking corner widgets (#1232):** with Direct Selection, every corner's widget shows while some corners are picked: a picked corner's widget has a dot at its center and the others are hollow. A click on a widget that is not picked picks its corner alone, a Shift-click adds or removes a corner across selected paths, and a double-click on a picked widget opens Corners for the picked corners of its path ([Live Corners help page, archived](https://web.archive.org/web/2019/https://helpx.adobe.com/illustrator/using/reshape-with-live-corners.html)). As VectorCraft's own rules, a plain click on a picked widget keeps the picks (while every corner of every selected path is picked, it picks that corner alone, and a double-click then opens Corners for that corner), a drag or Alt-click on a widget that is not picked edits its corner together with the picked ones, and over a widget that is not picked, a selected anchor's handle end or a nearer anchor takes the press. Tests: `corners::tests::a_press_on_a_widget_not_picked_edits_it_with_the_picked_corners`, `corners::tests::widgets_are_picked_across_paths`, `corners::tests::a_handle_end_over_a_widget_not_picked_takes_the_press`, `corners::tests::a_nearer_anchor_over_a_widget_not_picked_takes_the_press`, `corners::tests::a_shift_click_toggles_a_rounded_corner_whole`, `corners::tests::a_path_with_hidden_widgets_keeps_its_picks`, `tests::corner_widgets_pick_corners_across_paths_through_the_session`. - **Anchor edits keep Live Corners (#10545):** moving an anchor of a path with rounded corners (Direct Selection drag, arrow keys, `path.moveAnchor`) moves its uncut corner by the drag delta and recuts it at its radius. A grabbed arc end can finish away from a snap target. A live rectangle or polygon becomes a path with live corners. When the anchor layout changes, the path's whole anchor selection is remapped and its segment selection is cleared. A corner that a move straightens keeps its radius and rounds again when a later move bends it. An anchor edit makes the shape a plain path when no anchor stores a radius above 0 (a straightened corner's stored radius keeps the path live), a live rectangle is sheared or unevenly scaled, an arrow-key nudge bends selected curved segments or holds their anchors, or direct-selected anchors receive a transform other than a move. A nudge that changes nothing, including one that the pixel-grid snap of pixel-aligned paths takes back (with objects selected whole too), records no undo step and leaves Live Corners as they are: a live rectangle stays a live rectangle. These are VectorCraft's own rules. Tests: `tests::livecorners::moving_an_anchor_keeps_the_corners_live`, `tests::livecorners::dragging_selected_anchors_keeps_the_corners_live`, `tests::livecorners::moving_an_anchor_of_a_distorted_rectangle_edits_the_drawn_path`, `tests::livecorners::a_recut_remaps_the_whole_anchor_selection`, `tests::livecorners::a_recut_clears_segments_even_when_selected_anchor_indices_stay_the_same`, `tests::livecorners::an_unchanged_corner_layout_keeps_the_selection`, `corners::tests::a_straightened_corner_rounds_again_when_it_bends_back`. +- **Adding and removing anchors keeps Live Corners (#10545):** the Pen, Add Anchor Point and Delete Anchor Point tools, Object › Path › Remove Anchor Points and the Delete key with Delete Removes Anchor Points and Keeps Paths Joined on (`path.insertAnchor`, `path.removeAnchor`, `path.removeAnchors`) edit the uncut outline of a path with rounded corners and cut its corners again at their radii and kinds, so the corner widgets stay. An anchor added on a side has no radius; removing either end of a corner's arc removes that corner; a relative radius keeps its drawn length, up to the corner's new largest radius. When an anchor is added, selected anchors follow their corners and selected segments their sides, with only the segments' own ends selected; removing anchors clears the path's selected anchors and segments, and Remove Anchor Points then selects the first anchor of the next anchor of the uncut outline (a corner, or an anchor added on a side), or the anchor before the removed one at an open path's end. An anchor added on a corner's arc makes the path plain, and the status bar says the corners were expanded. These are VectorCraft's own rules. Tests: `tests::livecorners::adding_and_deleting_an_anchor_on_a_side_keeps_the_corners_live`, `tests::livecorners::adding_an_anchor_keeps_the_selected_segments_on_their_sides`, `tests::livecorners::adding_an_anchor_selects_only_the_ends_of_the_selected_segments`, `tests::livecorners::adding_an_anchor_on_a_corners_curve_expands_the_corners_and_warns`, `tests::livecorners::deleting_an_anchor_of_a_cut_corner_removes_the_corner_and_keeps_the_rest_live`, `tests::livecorners::remove_anchor_points_on_a_cut_corner_selects_the_next_corner`, `tests::livecorners::an_added_anchor_keeps_a_relative_radius_at_its_length`. - **TIFF in screen and asset export:** both format menus expose the existing TIFF encoder and Format Settings. Headless UI regressions choose TIFF and check scaled dimensions, artboard selection, filenames, encoding options, saved settings and collected-asset output. Public reference: [Export for Screens](https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/export-for-screens.html), updated 2026-09-28, lists TIFF for both artboards and assets. Adobe staff [confirmed support in 30.2.1](https://illustrator.uservoice.com/forums/333657-illustrator-desktop-feature-requests/suggestions/49081034-add-tiff-format-into-export-for-screens-assets-d) on 2026-02-19; the older 2025 Collect assets guide omits TIFF. - **Lossy WebP with a Quality setting:** WebP Options has a Compression menu (Lossless, Lossy) and a Quality slider from 0 to 100 that is enabled for Lossy. Lossy writes a `VP8 ` WebP file, with an `ALPH` chunk that keeps the alpha exactly when some pixels are not opaque. `document.export`, `document.serialize` and Export for Screens take `lossless: false` with `quality` (default 90, VectorCraft's own value), in a format row or in `settings.webp`; Format Settings for WebP keeps both. Lossless stays the default, and a quality above 100 or one that is not a whole number is refused. Public reference: [export file format options](https://helpx.adobe.com/illustrator/desktop/save-and-export/export-files-to-different-formats/export-file-format-options-in-illustrator.html) describes Lossless and Lossy WebP and a Quality setting for Lossy (`webp_is_lossless_by_default_and_lossy_when_asked`, `lossy_webp_keeps_translucent_pixels`, `webp_quality_out_of_its_range_is_refused` in `crates/engine/src/cmd/fileio/tests_text.rs`, `webp_options_choose_lossless_or_lossy_at_a_quality`). - **Export for Screens of the selected artboards:** while the Artboard tool is in use, File › Export › Export for Screens… (`file.exportForScreens`) opens with the artboards the tool has selected checked on its Artboards tab, and Export Artboard writes only those. Shift-clicks on the canvas, or Shift- or Ctrl/Cmd-clicks on the Artboards panel's rows, select several. The other fields show the settings the document last exported with. With another tool in use, the dialog takes its artboard choice from those settings too. Public reference: [Export selected artboards](https://helpx.adobe.com/illustrator/desktop/create-manage-artboards/organize-manage-artboards/export-artboards.html).