mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-15 22:28:10 +08:00
Refactor transform decomposition API with skew support, add 'Decompose Skew' node, and fix stroke transform interpolation (#3973)
* Refactor transform decomposition API with skew support, add Decompose Skew node, and fix stroke transform interpolation * Fix bug in master with skew changing Area node calculated value * Code review simplification * More code review fixes * Rename cases where "shear" terminology was used in place of "skew"
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use core::f64;
|
||||
use core_types::color::Color;
|
||||
use core_types::table::Table;
|
||||
use core_types::transform::{ApplyTransform, Transform};
|
||||
use core_types::transform::{ApplyTransform, ScaleType, Transform};
|
||||
use core_types::{CloneVarArgs, Context, Ctx, ExtractAll, InjectFootprint, ModifyFootprint, OwnedContextImpl};
|
||||
use glam::{DAffine2, DMat2, DVec2};
|
||||
use graphic_types::Graphic;
|
||||
@@ -77,7 +77,7 @@ fn reset_transform<T>(
|
||||
row.transform.matrix2 = DMat2::IDENTITY;
|
||||
}
|
||||
(true, false) => {
|
||||
let scale = row.transform.decompose_scale();
|
||||
let scale = row.transform.scale_magnitudes();
|
||||
row.transform.matrix2 = DMat2::from_diagonal(scale);
|
||||
}
|
||||
(false, true) => {
|
||||
@@ -143,15 +143,24 @@ fn decompose_translation(_: impl Ctx, transform: DAffine2) -> DVec2 {
|
||||
}
|
||||
|
||||
/// Extracts the rotation component (in degrees) from the input transform.
|
||||
/// This, together with the "Decompose Scale" node, also may jointly represent any shear component in the original transform.
|
||||
#[node_macro::node(category("Math: Transform"))]
|
||||
fn decompose_rotation(_: impl Ctx, transform: DAffine2) -> f64 {
|
||||
transform.decompose_rotation().to_degrees()
|
||||
}
|
||||
|
||||
/// Extracts the scale component from the input transform.
|
||||
/// This, together with the "Decompose Rotation" node, also may jointly represent any shear component in the original transform.
|
||||
/// **Magnitude** returns the visual length of each axis (always positive, includes any skew contribution).
|
||||
/// **Pure** returns the isolated scale factors with rotation and skew stripped away (can be negative for flipped axes).
|
||||
#[node_macro::node(category("Math: Transform"))]
|
||||
fn decompose_scale(_: impl Ctx, transform: DAffine2) -> DVec2 {
|
||||
transform.decompose_scale()
|
||||
fn decompose_scale(_: impl Ctx, transform: DAffine2, scale_type: ScaleType) -> DVec2 {
|
||||
match scale_type {
|
||||
ScaleType::Magnitude => transform.scale_magnitudes(),
|
||||
ScaleType::Pure => transform.decompose_scale(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Extracts the skew angle (in degrees) from the input transform.
|
||||
#[node_macro::node(category("Math: Transform"))]
|
||||
fn decompose_skew(_: impl Ctx, transform: DAffine2) -> f64 {
|
||||
transform.decompose_skew().atan().to_degrees()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user