asPointTransformer method

ShapePointTransformer asPointTransformer()

Returns a ShapePointTransformer that applies this matrix.

This is the bridge between the transformation types Flutter already uses and the shape transformation methods, so that a matrix built with the usual Matrix3 helpers can be passed straight to RoundedPolygon.transformed, Morph, PolygonFeature.transformed or CubicBezier.transformed:

final RoundedPolygon rotated = polygon.transformed(
  Matrix3.rotationZ(math.pi / 4).asPointTransformer(),
);

Only the X and Y components of the result are used, so the Z translation of the matrix has no effect.

Implementation

ShapePointTransformer asPointTransformer() {
  final m = storage;
  final m00 = m[0];
  final m10 = m[1];
  final m01 = m[3];
  final m11 = m[4];
  final m02 = m[6];
  final m12 = m[7];
  return (x, y) => (m00 * x + m01 * y + m02, m10 * x + m11 * y + m12);
}