Transform panel: the Shear field takes -359 to 359 and shows the error for an angle Shear refuses

The Shear field stopped at -89 and dropped any value of 90 or more without a word.
It now sends every typed, stepped or picked value to `object.shear`, which shears by
the tangent of an angle from -359 to 359. For ±90, ±270 and an angle outside that
range the status bar shows the command's error; the art is unchanged and no undo step
is recorded.
This commit is contained in:
dotCooCoo
2026-11-17 16:25:32 -08:00
parent b4d5d192ba
commit fc294d56b6
3 changed files with 84 additions and 7 deletions
+14 -6
View File
@@ -126,7 +126,12 @@ const PATTERN_MODES: [(&str, &str); 3] = [("object", "Transform Object Only"), (
/// Only (the pattern tiles alone) or Transform Both. Until one is chosen (`default`, or any other
/// value) neither is passed: patterns follow General › Transform Pattern Tiles. Errors are
/// dropped, as the panels' fields have always done.
pub fn run_transform(app: &mut VectorcraftApp, cmd: &str, mut params: serde_json::Value) {
pub fn run_transform(app: &mut VectorcraftApp, cmd: &str, params: serde_json::Value) {
try_transform(app, cmd, params).ok();
}
/// [`run_transform`] that returns the command's result, for a field that shows its error.
fn try_transform(app: &mut VectorcraftApp, cmd: &str, mut params: serde_json::Value) -> Result<serde_json::Value, String> {
let switches = match app.session.prefs.transform_panel_patterns.as_str() {
"object" => Some((true, false)),
"pattern" => Some((false, true)),
@@ -137,7 +142,7 @@ pub fn run_transform(app: &mut VectorcraftApp, cmd: &str, mut params: serde_json
params["objects"] = json!(objects);
params["patterns"] = json!(patterns);
}
app.run(cmd, params).ok();
app.run(cmd, params)
}
/// The panel menu's checked choice of [`PATTERN_MODES`]: the one chosen, else (`default`) what
@@ -323,12 +328,15 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
ui.add_space(4.0);
let icon = icons::icon(ui, "dc-shear", 16.0, t.icon).on_hover_text(tl!("Shear"));
crate::scrub::note_label(ui, icon.rect);
// Shear is relative: the field rests at 0° and a new value shears by it.
if let Some(a) = widgets::spin_plain_named(ui, "xfp-shear", Some(tl!("Shear")), 0.0, "°", 2, 96.0, 15.0, -89.0, &SHEAR_PRESETS)
// Shear is relative: the field rests at 0° and a new value from -359° to 359° shears
// by it. The field has no minimum, so `object.shear` checks every value: it refuses
// ±90°, ±270° and a value outside -359° to 359°, and the status bar shows its error.
if let Some(a) =
widgets::spin_plain_named(ui, "xfp-shear", Some(tl!("Shear")), 0.0, "°", 2, 96.0, 15.0, f64::NEG_INFINITY, &SHEAR_PRESETS)
&& a != 0.0
&& a.abs() < 90.0
&& let Err(e) = try_transform(app, "object.shear", json!({"angle": a, "axis": "horizontal", "origin": origin, "copy": copy}))
{
run_transform(app, "object.shear", json!({"angle": a, "axis": "horizontal", "origin": origin, "copy": copy}));
app.status(e);
}
});
});
@@ -524,6 +524,75 @@ fn rotate_and_shear_fields_are_named() {
let _ = h.get_by_role_and_label(egui::accesskit::Role::TextInput, "Shear");
}
/// A 100 × 60 rectangle at (100, 40), selected, in a new app.
fn shear_app() -> VectorcraftApp {
let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
app.run("shape.rectangle", json!({"x": 100, "y": 40, "width": 100, "height": 60})).unwrap();
app
}
/// Types `value` into the panel's Shear field (the second field showing "0°") and presses Enter.
fn type_shear(app: &mut VectorcraftApp, value: &str) {
use crate::panels::tests_appearance::{click, frame_events};
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let texts = frame_events(&ctx, app, vec![], show);
let at = texts.iter().filter(|(t, _)| t == "0°").nth(1).unwrap_or_else(|| panic!("no Shear field in {texts:?}")).1.center();
click(&ctx, app, at, show);
let key = |key, modifiers| egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers };
frame_events(&ctx, app, vec![key(egui::Key::A, egui::Modifiers::COMMAND)], show);
frame_events(&ctx, app, vec![egui::Event::Text(value.into())], show);
frame_events(&ctx, app, vec![key(egui::Key::Enter, egui::Modifiers::NONE)], show);
frame_events(&ctx, app, vec![], show);
}
/// The Shear field takes -359° to 359°: a typed 120 and -359 shear about the reference point (the
/// centre) as `object.shear` does with that angle, and 120 slants as -60 does.
#[test]
fn the_shear_field_takes_angles_from_minus_359_to_359() {
for (typed, angle, like) in [("120", 120.0, Some(-60.0)), ("-359", -359.0, None), ("45", 45.0, None)] {
let mut app = shear_app();
let before = app.selection_box().unwrap();
type_shear(&mut app, typed);
assert_eq!(app.ui.status, "", "{typed}: no error");
let got = app.selection_box().unwrap();
assert_ne!(got, before, "{typed}: sheared");
let mut want = shear_app();
want.run("object.shear", json!({"angle": angle, "axis": "horizontal", "origin": [150, 70]})).unwrap();
assert_eq!(got, want.selection_box().unwrap(), "{typed}");
if let Some(like) = like {
let mut same = shear_app();
same.run("object.shear", json!({"angle": like, "axis": "horizontal", "origin": [150, 70]})).unwrap();
let (a, b) = (got.rect, same.selection_box().unwrap().rect);
assert!(
(a.x0 - b.x0).abs() < 1e-6 && (a.x1 - b.x1).abs() < 1e-6 && (a.y0 - b.y0).abs() < 1e-6 && (a.y1 - b.y1).abs() < 1e-6,
"{typed}: {a:?} like {b:?}"
);
}
}
}
/// A typed ±90 or ±270, which have no shear, and a typed 400 or -400, outside -359 to 359, leave
/// the rectangle as it is, record no undo step and show `object.shear`'s error in the status bar.
#[test]
fn the_shear_field_shows_the_error_for_an_angle_with_no_shear() {
let none = |v: &str| format!("invalid parameters for `object.shear`: `angle` cannot be {v}: ±90 and ±270 degrees have no shear");
let range = |v: &str| format!("invalid parameters for `object.shear`: `angle` must be from -359 to 359 degrees, not {v}");
for (typed, msg) in
[("90", none("90")), ("-90", none("-90")), ("270", none("270")), ("-270", none("-270")), ("400", range("400")), ("-400", range("-400"))]
{
let mut app = shear_app();
let (before, revision) = (app.selection_box().unwrap(), app.session.active().unwrap().revision);
let undo = app.session.doc().unwrap().history.undo.len();
type_shear(&mut app, typed);
assert_eq!(app.ui.status, msg, "{typed}");
assert_eq!(app.selection_box().unwrap(), before, "{typed}: nothing moved");
assert_eq!(app.session.active().unwrap().revision, revision, "{typed}: unchanged");
assert_eq!(app.session.doc().unwrap().history.undo.len(), undo, "{typed}: no undo step");
}
}
/// The Align to Pixel Grid checkbox turns the selected paths' pixel-aligned property on, shows a
/// dash when they differ (a click then turns it on for both), turns it off when it is on for all,
/// and is unavailable with type selected.
+1 -1
View File
@@ -1277,7 +1277,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
The settled part of that outline is kept in paths of up to 64 pieces each. A path is shared from one frame to the next until a piece in it changes, and the canvas keeps the triangles it drew the path with while the view stays the same, so a frame does not copy, flatten or tessellate a settled path again; a pan, zoom or rotation draws each one once more. This is VectorCraft's own rule. The line that a drag of more than 64 segments shows with a round Eraser tip, the Knife, the Path Eraser or the Pencil with Live preview off is kept the same way, in pieces of 64 segments: a frame builds again only the last piece, and the Knife's dashes run on from one piece to the next. With the Eraser's Size set to a mode that follows the pen, each step of such a drag is kept as its own path and a frame builds only a new step. A smoothing drag's band is kept until it changes. The canvas still copies the kept triangles of every piece into each frame.
- **Transform:** Rotate, Reflect, Scale, Shear (click or Alt-click snaps the reference point to anchors and centres; Alt-click opens the tool's dialog, and a drag with Alt down at the release, from the press or pressed mid-drag, transforms a copy), Reshape, Free Transform (free and perspective distort and shear, switched by the keys held during a handle drag).
A Reshape drag stretches part of a path from the dragged point without losing the path's general form, as [Adjust path segments](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/modify-paths/adjust-path-segments.html) has it. On an open path the stretch reaches both ends: the end anchors stay in place, each anchor between moves less the nearer it lies to an end, and the handles of a smooth anchor stay in line (`path.reshape`; the reach and the shares are VectorCraft's own rule, in `docs/mcp.md`). A click sets a focal point and a click on a segment adds a highlighted anchor there; Shift-click adds more, and a drag from any of them moves them all. The anchors that are not direct-selected stay in place and a closed path selected whole moves whole (VectorCraft's own rule, in `docs/mcp.md`).
Align, Distribute, Distribute Spacing, Reflect and Shear return an error for any `horizontal`, `vertical`, `to`, `axis`, `bounds` or `spacing` value they don't take, listing the choices, and Align returns one when a call gives neither `horizontal` nor `vertical`; nothing moves and no undo step is recorded. Shear takes an angle from -359° to 359° and shears by its tangent, so 120° slants as -60°; an angle outside that range, and ±90° and ±270° (VectorCraft's own rule), return an error ([shear objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/shear-objects.html); `shear_angles_slant_by_their_tangent`, `shear_rejects_angles_with_no_shear_or_out_of_range`). Align and Distribute act on the anchor points selected with Direct Selection: the points of one path align to each other, not to the artboard, and Distribute spaces them (#1641, fixes #1636; aligning to a key anchor is still missing).
Align, Distribute, Distribute Spacing, Reflect and Shear return an error for any `horizontal`, `vertical`, `to`, `axis`, `bounds` or `spacing` value they don't take, listing the choices, and Align returns one when a call gives neither `horizontal` nor `vertical`; nothing moves and no undo step is recorded. Shear takes an angle from -359° to 359° and shears by its tangent, so 120° slants as -60°; an angle outside that range, and ±90° and ±270° (VectorCraft's own rule), return an error ([shear objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/shear-objects.html); `shear_angles_slant_by_their_tangent`, `shear_rejects_angles_with_no_shear_or_out_of_range`). The Transform panel's Shear field takes the same range, and the status bar shows the error for an angle Shear refuses, as VectorCraft's own rule ([shear objects with the Transform panel](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/shear-objects.html); `panels::transform::tests::the_shear_field_takes_angles_from_minus_359_to_359`, `the_shear_field_shows_the_error_for_an_angle_with_no_shear`). Align and Distribute act on the anchor points selected with Direct Selection: the points of one path align to each other, not to the artboard, and Distribute spaces them (#1641, fixes #1636; aligning to a key anchor is still missing).
Transform Each opens on the scale, move, rotate, reflect, Random, reference point, Transform Objects and Preview it was last confirmed with (kept with the UI state; Copy never is), and its Copy button, left of Cancel, transforms a copy of each object as the [Scale multiple objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/scale-multiple-objects.html) help page has it; the Copy checkbox is gone (#1732; the remembered values follow a maintainer comment on the issue, not the help page). Its Scale section has the Relative and Absolute radio buttons the same page describes: percentages of each object's size, or the width and height it becomes (`object.transformEach` `relative`, which Transform Again repeats); Absolute measures each object's own box, and the scales act along its axes about that box's reference point, so a turned shape keeps its shape and objects of different sizes come out alike; the fields show the width and height the selected objects share and read "Mixed" when they differ or a side is 0 (a line's), each object measured by its own box, rotated with it, as the Transform panel and the Control bar show it (sizes they show alike count as the same), and a size typed into them sets every object to it (a side left Mixed keeps its size), our choices where the page leaves them open; a live Repeat scales its spacing by the geometric mean of the two factors, so its Absolute size is approximate. The link beside the two scales keeps them in proportion, as the shape dialogs' Width and Height link does (`__constrain`, kept with the dialog's values; where it sits is our choice, the public pages don't establish it). The panel lists Scale, Move and Rotate, then the Options in two columns (Transform Objects, Transform Patterns, Scale Strokes & Effects, Scale Corners; Reflect X, Reflect Y, Random), the Reference Point, and Preview at the left of the button row, level with Copy, Cancel and OK.
Transform Again uses the Copy, Transform Patterns, Scale Strokes & Effects and Scale Corners choices of the transform it repeats; after a bounding-box handle drag on area type, it resizes the type area again and the type keeps its size (`object.transformAgain`). With anchors selected with Direct Selection, Move, Rotate, Scale, Reflect, Shear and Transform Again (the commands, their dialogs and the four tools' drags) transform only those anchors, their handles with them, about the centre of the box around them unless a point was clicked; a copy still copies the whole object (#1408; behaviour reference: [adjust path segments](https://helpx.adobe.com/illustrator/using/adjust-path-segments.html); the default reference point and the copy are our choices). The Move, Rotate, Scale, Reflect and Shear dialogs have a Preview checkbox, off when they open: while it is on the canvas follows the values, Cancel rolls it back and OK is still one undo step; Up/Down step the Rotate and Shear angles and the Scale percentages by 1, Shift by 10 (#1412). The five dialogs and Transform Each have Transform Objects beside Transform Patterns: off, the art stays and only its pattern tiles transform (`objects` on the transform commands), and Transform Again repeats the choice (#1448; behaviour reference: [scale objects](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/scale-objects.html); the checkboxes are always enabled and the Scale page's pair is applied to all of them, our choices). Reflect's axis is Horizontal, Vertical or an angle (#1460; [reflect objects along an axis](https://helpx.adobe.com/illustrator/desktop/manage-objects/arrange-objects/reflect-objects-along-an-axis.html)).
- **Pen:** Alt pressed in the middle of dragging out an anchor splits its handles and keeps the curve already shaped into it (only the outgoing handle follows the pointer); Space held while dragging out an anchor moves it, handles and all. A press on the first anchor of the path being drawn closes it whatever the drag then does: the drag shapes the closing curve and the release closes the path wherever it ends (#501). The first anchor's incoming handle mirrors the pointer, and a click leaves it retracted and the anchor a corner. Its outgoing handle stays where it is on a corner, so the first segment keeps its shape, and on a smooth anchor it turns to stay in line at its own length; Alt makes the anchor a corner and leaves the outgoing handle where it was when Alt went down. The Smart Pen's closing drag does the same (fixes #6634; `path.close`'s `in` and `out`; behavior reference: [draw with the Pen, Curvature, or Pencil tool](https://web.archive.org/web/20220614224656/https://helpx.adobe.com/illustrator/using/drawing-pen-curvature-or-pencil.html), where a click or drag on the first anchor closes the path and Alt breaks the pairing of the closing anchor's handles; which handles the drag sets are our choices). Space held during the Pen's closing drag moves the first anchor, handles and all, as that page also describes (`path.close`'s `at`). Clicking the last anchor of the path being drawn retracts its outgoing handle (convert cursor), and dragging from it pulls out a new one on its own. Auto Add/Delete: over a selected path, a click on a segment adds an anchor and a click on an anchor deletes it (add and delete cursors); Shift held, or Preferences › General › Disable Auto Add/Delete, starts a new path instead. Alt held over a handle end or an anchor of a selected path (the one being drawn too) works as the Anchor Point tool, with its convert cursor: dragging a handle moves it alone, clicking a smooth anchor makes it a corner, dragging an anchor pulls out new symmetric handles, dragging a segment reshapes it; drawing then goes on. Cmd (Ctrl) held drags with the selection tool chosen last, Direct Selection until one is (handles, anchors and segments of the path being drawn or another), and the Pen then goes on drawing its path while that stays selected; the pointer shows that tool's while Cmd is held. The same holds for agents (`pointer_gesture` with `mods.cmd`), as the borrowing now lives in the engine (#494). A drag's preview (the Pen's, the Anchor Point tool's, Direct Selection's handles and anchors) follows every position the pointer is seen at (#834): the canvas sends the tool a drag whenever the pointer's document position differs from the last one it sent, not only when egui's frame delta is non-zero (zero when a compositor coalesces motion and in the frame the pointer comes back into the window after leaving it), and a move that arrives in the release's own frame shapes the preview before the release commits it, once the press has dragged. With the Pen, a press that moves under 3 screen pixels is a click (a corner without handles), and a Precise Cursors command toggles the existing preference and can take a shortcut (#1663).