RSTransform.fromComponents constructor

RSTransform.fromComponents(
  1. {required double rotation,
  2. required double scale,
  3. required double anchorX,
  4. required double anchorY,
  5. required double translateX,
  6. required double translateY}
)

Creates an RSTransform from its individual components.

The rotation parameter gives the rotation in radians.

The scale parameter describes the uniform scale factor.

The anchorX and anchorY parameters give the coordinate of the point around which to rotate.

The translateX and translateY parameters give the coordinate of the offset by which to translate.

This constructor computes the arguments of the RSTransform.new constructor and then defers to that constructor to actually create the object. If many RSTransform objects are being created and there is a way to factor out the computations of the sine and cosine of the rotation (which are computed each time this constructor is called) and reuse them over multiple RSTransform objects, it may be more efficient to directly use the more direct RSTransform.new constructor instead.

Implementation

factory RSTransform.fromComponents({
  required double rotation,
  required double scale,
  required double anchorX,
  required double anchorY,
  required double translateX,
  required double translateY
}) {
  final double scos = math.cos(rotation) * scale;
  final double ssin = math.sin(rotation) * scale;
  final double tx = translateX + -scos * anchorX + ssin * anchorY;
  final double ty = translateY + -ssin * anchorX - scos * anchorY;
  return RSTransform(scos, ssin, tx, ty);
}