mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 15:08:40 +00:00
Merge fix/shear-angle-range into fix/transform-panel-shear-range
This commit is contained in:
@@ -61,7 +61,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
"Shear…",
|
||||
["Object", "Transform"],
|
||||
None,
|
||||
"{ids?: [id…] (selected first; default: the selection), angle: deg (-359 to 359, sheared by its tangent, so 120 slants as -60; ±90 and ±270 are an error; positive turns the vertical edges clockwise with the horizontal axis, the top to the right; the horizontal edges clockwise with the vertical axis, the right side down), axis?: \"horizontal\"|\"vertical\", origin?, 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)}. With anchors selected with Direct Selection (and no copy), only those anchors and their handles transform, about the centre of their own box.",
|
||||
"{ids?: [id…] (selected first; default: the selection), angle: deg (-359 to 359, sheared by its tangent, so 120 slants as -60; 0 and ±180 have no slant and, without copy, change nothing; ±90 and ±270 are an error; positive turns the vertical edges clockwise with the horizontal axis, the top to the right; the horizontal edges clockwise with the vertical axis, the right side down), axis?: \"horizontal\"|\"vertical\", origin?, 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)}. 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,
|
||||
shear
|
||||
),
|
||||
|
||||
@@ -414,8 +414,8 @@ pub(super) fn reflect(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
apply_transform(s, "Reflect", ids, about(o, m), p, true)
|
||||
}
|
||||
|
||||
/// Angles closer than this many degrees to ±90 or ±270 count as those angles. It is far above the
|
||||
/// rounding error of an angle up to 359° and below any angle a field shows.
|
||||
/// Angles closer than this many degrees to ±90 or ±270, or to 0 or ±180, count as those angles. It
|
||||
/// is far above the rounding error of an angle up to 359° and below any angle a field shows.
|
||||
const SHEAR_ANGLE_TOLERANCE: f64 = 1e-9;
|
||||
|
||||
pub(super) fn shear(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
@@ -431,7 +431,9 @@ pub(super) fn shear(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
}
|
||||
let ids = selected_roots_to_transform(s)?;
|
||||
let o = origin_of(s, p, &ids)?;
|
||||
let t = angle.to_radians().tan();
|
||||
// 0 and ±180 have no slant, but the tangent of ±180° in radians is about 1e-16, not 0.
|
||||
let flat = angle.rem_euclid(180.0);
|
||||
let t = if flat < SHEAR_ANGLE_TOLERANCE || 180.0 - flat < SHEAR_ANGLE_TOLERANCE { 0.0 } else { angle.to_radians().tan() };
|
||||
let vertical = choice(p, "object.shear", "axis", &["horizontal", "vertical"])? == Some("vertical");
|
||||
let m = if vertical { Affine::new([1.0, t, 0.0, 1.0, 0.0, 0.0]) } else { Affine::new([1.0, 0.0, -t, 1.0, 0.0, 0.0]) };
|
||||
apply_transform(s, "Shear", ids, about(o, m), p, true)
|
||||
|
||||
@@ -557,6 +557,23 @@ fn shear_rejects_angles_with_no_shear_or_out_of_range() {
|
||||
assert_eq!(undo_len(&s), n, "no undo step");
|
||||
}
|
||||
|
||||
/// Shear by 0, 180 or -180 degrees, along either axis, has no slant: the art keeps its exact
|
||||
/// coordinates and no undo step is recorded.
|
||||
#[test]
|
||||
fn shear_by_0_and_180_changes_nothing() {
|
||||
let mut s = session();
|
||||
let a = rect(&mut s, 10.0, 20.0, 30.0, 10.0);
|
||||
let before = bounds(&s, a);
|
||||
let n = undo_len(&s);
|
||||
for angle in [180.0, -180.0, 0.0, 180.0 + 1e-12, -180.0 - 1e-12] {
|
||||
for axis in ["horizontal", "vertical"] {
|
||||
s.execute("object.shear", &json!({"angle": angle, "axis": axis})).unwrap();
|
||||
assert_eq!(bounds(&s, a), before, "{angle} {axis}");
|
||||
assert_eq!(undo_len(&s), n, "{angle} {axis}: no undo step");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn distort_command_maps_corners() {
|
||||
let mut s = session();
|
||||
|
||||
+2
-1
@@ -6844,7 +6844,8 @@ an error that lists the choices of a `horizontal`, `vertical`, `to`, `axis` or `
|
||||
(`object.reflect` also takes an angle and names the value given), and one for a `spacing` that is not a number; nothing
|
||||
moves. `object.shear` takes an `angle` from -359 to 359 degrees, the range of the
|
||||
[Shear dialog](https://helpx.adobe.com/illustrator/desktop/manage-objects/reshape-transform-objects/shear-objects.html),
|
||||
and shears by its tangent, so 120 slants as -60. It returns an error for an angle outside that range, and, as
|
||||
and shears by its tangent, so 120 slants as -60. An angle of 0 or ±180 (within 1e-9 degrees) has no slant: without
|
||||
`copy`, nothing moves and no undo step is recorded, and with `copy` the copies keep the art's place. It returns an error for an angle outside that range, and, as
|
||||
VectorCraft's own rule, for ±90 and ±270 (within 1e-9 degrees), which have no finite shear; nothing moves and no undo
|
||||
step is recorded.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user