Merge main into feat/corners-link-popup

This commit is contained in:
dotCooCoo committed 2026-11-26 06:37:26 -08:00
commit b0241804b7
373 files changed
+29442 -2020

No files matched your search

+3 -3
View File
@@ -34,8 +34,8 @@ pub fn specs() -> Vec<CommandSpec> {
"Rotate…",
["Object", "Transform"],
None,
"{ids?: [id…] (selected first; default: the selection), angle: deg (counter-clockwise), absolute?: bool (angle is the bounding box's new angle, not an amount), origin?: [x,y] (default: the bounding box centre), copy?, objects?: bool (Transform Objects, default true; false: the art stays and, with patterns, only its pattern tiles transform), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size)} → {ids}. With anchors selected with Direct Selection (and no copy), only those anchors and their handles transform, about the centre of their own box.",
has_selection,
"{ids?: [id…] (selected first; default: the selection), angle: deg (counter-clockwise), absolute?: bool (angle is the bounding box's new angle, not an amount), origin?: [x,y] (default: the bounding box centre), copy?, objects?: bool (Transform Objects, default true; false: the art stays and, with patterns, only its pattern tiles transform), patterns?: bool (Transform Patterns: pattern fills and strokes transform with the art; default: prefs transformPatternTiles), typeAreas?: bool (area type: the frame is reshaped and the text reflows at its size)} → {ids}. With anchors selected with Direct Selection (and no copy), only those anchors and their handles transform, about the centre of their own box. Selected ruler guides that can be edited rotate too (without ids), each as the line view.guides.release makes of it, and the default origin is the center of the objects' box and those lines together: a guide that ends up vertical or horizontal stays a ruler guide, and one at any other angle becomes a selected guide path along its line. absolute with only ruler guides selected is an error.",
has_selection_or_guides,
rotate
),
cmd!(
@@ -71,7 +71,7 @@ pub fn specs() -> Vec<CommandSpec> {
["Object", "Transform"],
Some("Cmd+D"),
"{copy?, strokes?, corners?, patterns?, typeAreas?, interpolate?: bool (as object.transform's; default: the value the transform it repeats used, else object.transform's default)} the last transform's matrix on the selection (after a perspective move or scale: that plane-space transform, without these params)",
has_selection,
has_selection_or_guides,
transform_again
),
cmd!(
+45 -6
View File
@@ -16,7 +16,27 @@ fn origin_of(s: &Session, p: &Value, ids: &[NodeId]) -> Result<Point> {
{
return Ok(b.center());
}
s.transform_box(ids).map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()))
// Selected ruler guides transform with the selection (not with objects named by `ids`, nor
// with Transform Objects off), so the center is that of the objects' box and the guides'
// lines together.
let guides = if p.get("ids").is_none_or(Value::is_null) && transforms_objects(p) { editable_guides(s)? } else { vec![] };
let boxed = s.transform_box(ids);
if guides.is_empty() {
return boxed.map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()));
}
let objects = boxed.map(|b| {
let c = b.corners();
c.iter().fold(Rect::from_points(c[0], c[0]), |r, p| r.union_pt(*p))
});
let lines = guides.into_iter().filter_map(|g| st.doc.guide_line(&g)).map(|(a, b)| Rect::from_points(a, b));
let b = lines.fold(objects, |acc, r| Some(acc.map_or(r, |acc| acc.union(r))));
b.map(|b| b.center()).ok_or_else(|| EngineError::Other("selection has no bounds".into()))
}
/// The selected ruler guides that a transform changes: those that can be edited.
fn editable_guides(s: &Session) -> Result<Vec<vectorcraft_doc::Guide>> {
let st = s.doc()?;
Ok(st.selection.guides.iter().filter_map(|id| st.doc.ruler_guide(*id)).filter(|g| st.doc.guide_editable(g)).collect())
}
/// What a transform command scales besides geometry: Scale Strokes & Effects and Scale Corners from
@@ -125,8 +145,18 @@ fn apply_transform_moving_guides(
let c = xf.as_coeffs();
let is_translation = (c[0] - 1.0).abs() < 1e-9 && c[1].abs() < 1e-9 && c[2].abs() < 1e-9 && (c[3] - 1.0).abs() < 1e-9;
let delta = guides.unwrap_or(Vec2::new(c[4], c[5]));
let with_guides = objects && p.get("ids").is_none_or(Value::is_null) && is_translation;
let has_guides = with_guides && !s.doc()?.selection.guides.is_empty();
// The selected ruler guides transform with the selection: a move moves them, and any other
// transform maps the line each one stands for ([`Document::transform_ruler_guides`]).
let with_guides = objects && p.get("ids").is_none_or(Value::is_null);
// A transform that leaves every guide where it is (a scale of a guide along its own line)
// changes no guide; with a copy, the guides are copied all the same.
let has_guides = with_guides && {
let d = &s.doc()?.doc;
let same = |g: &vectorcraft_doc::Guide| {
d.transformed_guide(g, xf) == Some(vectorcraft_doc::GuideTransform::Ruler { vertical: g.vertical, pos: g.pos })
};
editable_guides(s)?.iter().any(|g| is_translation || copy || !same(g))
};
// A transform of ids that name no object, or an identity transform without a copy, moves
// nothing: the document and its undo history stay as they are, and Transform Again repeats it.
// With a copy, the reply lists the copies, and there are none.
@@ -142,8 +172,9 @@ fn apply_transform_moving_guides(
if c[..4] == [1.0, 0.0, 0.0, 1.0] {
interpolate = Some(crate::cmd::path::interpolates_handles(s, p, label)?);
}
let mut ids = ids;
if xf != Affine::IDENTITY {
crate::cmd::path::transform_anchors(s, label, xf, sc, interpolate.unwrap_or(false))?;
ids.extend(crate::cmd::path::transform_anchors(s, label, xf, sc, interpolate.unwrap_or(false))?);
}
ids
} else if none || (!copy && xf == Affine::IDENTITY) {
@@ -151,7 +182,7 @@ fn apply_transform_moving_guides(
} else {
let kept = if copy { preview_copies(s, &ids, with_guides, below)? } else { None };
s.edit(label, |d, sel| {
let targets = match &kept {
let mut targets = match &kept {
// The document becomes the snapshot with the kept copies, untransformed, and the
// loop below transforms only the copies.
Some(k) => {
@@ -196,10 +227,14 @@ fn apply_transform_moving_guides(
crate::cmd::patterncmds::move_tile_with_art(d, &targets, before);
}
}
if with_guides && (delta.x != 0.0 || delta.y != 0.0) {
if with_guides && is_translation && (delta.x != 0.0 || delta.y != 0.0) {
for i in sel.guides.clone() {
d.edit_ruler_guide(i, |g| *g = g.moved(delta));
}
} else if with_guides && !is_translation {
// The guide paths are made already transformed, so they join the reply after the
// loop above.
targets.extend(d.transform_ruler_guides(sel, xf));
}
Ok(targets)
})?
@@ -388,6 +423,10 @@ pub(super) fn rotate(s: &mut Session, p: &Value) -> Result<Value> {
check_switches(p, &TRANSFORM_SWITCHES, "object.rotate")?;
check_switches(p, &["absolute"], "object.rotate")?;
let ids = selected_roots_to_transform(s)?;
// A bounding box angle is that of objects; ruler guides selected alone have none.
if bool_or(p, "absolute", false) && ids.is_empty() {
return Err(bad("object.rotate", "absolute needs objects selected: ruler guides have no bounding box angle"));
}
let o = origin_of(s, p, &ids)?;
let mut angle = f64_or(p, "angle", 0.0);
if bool_or(p, "absolute", false) {