rotationDeg property
Derived rotation in degrees.
Note: for general affine transforms (shear), a unique decomposition into rotation+scale is not well-defined. This getter assumes a rotation+scale form and is intended as a convenience accessor.
This accessor is numerically robust for near-degenerate transforms and is designed to return a finite value for finite matrix components.
Implementation
double get rotationDeg {
final t = transform;
assert(
t.a.isFinite && t.b.isFinite && t.c.isFinite && t.d.isFinite,
'SceneNode.rotationDeg requires finite transform.',
);
final a = t.a;
final b = t.b;
final c = t.c;
final d = t.d;
final sx = math.sqrt(a * a + b * b);
final syAbs = math.sqrt(c * c + d * d);
if (!sx.isFinite || !syAbs.isFinite) return 0;
if (nearZero(sx) && nearZero(syAbs)) return 0;
final radians = (sx >= syAbs && !nearZero(sx))
? math.atan2(b, a)
: math.atan2(-c, d);
final degrees = radians * 180.0 / math.pi;
return degrees.isFinite ? degrees : 0;
}
Implementation
set rotationDeg(double value) {
_requireTrsTransformForConvenienceSetter(transform, 'rotationDeg');
transform = Transform2D.trs(
translation: position,
rotationDeg: value,
scaleX: scaleX,
scaleY: scaleY,
);
}