transform method
When a Gradient creates its Shader, it will call this method to determine what transform to apply to the shader for the given Rect and TextDirection.
Implementers may return null from this method, which achieves the same final effect as returning Matrix4.identity.
Implementation
@override
vm.Matrix4? transform(Rect bounds, {TextDirection? textDirection}) {
final double cx = bounds.left + atX * bounds.width;
final double cy = bounds.top + atY * bounds.height;
final double left = bounds.left;
final double top = bounds.top;
final double right = bounds.right;
final double bottom = bounds.bottom;
final double dxL = (cx - left).abs();
final double dxR = (right - cx).abs();
final double dyT = (cy - top).abs();
final double dyB = (bottom - cy).abs();
final double rx = dxL > dxR ? dxL : dxR; // max horizontal reach
final double ry = dyT > dyB ? dyT : dyB; // max vertical reach
// Scale Y so that a unit circle becomes an ellipse matching rx:ry.
// Using sy = ry/rx makes the circle appear stretched vertically to ellipse ratio.
final double sx = 1.0;
final double sy = (rx == 0) ? 1.0 : (ry / rx);
final vm.Matrix4 m = vm.Matrix4.identity();
m.translate(cx, cy);
m.scale(sx, sy, 1.0);
m.translate(-cx, -cy);
return m;
}