transformationMatrix property

GMatrix transformationMatrix

Gets the transformation matrix that represents the object's position, scale, rotation and skew.

If the transformation matrix has changed since the last time this method was called, a new matrix will be computed and cached until the next time this method is called.

Implementation

GMatrix get transformationMatrix {
  if (_transformationChanged || _transformationMatrix == null) {
    _transformationChanged = false;
    _transformationMatrix ??= GMatrix();
    $updateTransformationMatrices(
      x,
      y,
      pivotX,
      pivotY,
      scaleX,
      scaleY,
      skewX,
      skewY,
      rotation,
      _transformationMatrix!,
    );
  }
  return _transformationMatrix!;
}
void transformationMatrix=(GMatrix matrix)

Sets the transformation matrix that represents the object's position, scale, rotation and skew.

The object's position, scale, rotation, and skew values are updated to match the new transformation matrix.

Implementation

set transformationMatrix(GMatrix matrix) {
  const piQuarter = Math.PI / 4.0;
  requiresRedraw();
  _transformationChanged = false;
  _transformationMatrix ??= GMatrix();
  _transformationMatrix!.copyFrom(matrix);
  _pivotX = _pivotY = 0;
  _x = matrix.tx;
  _y = matrix.ty;
  _skewX = Math.atan(-matrix.c / matrix.d);
  _skewY = Math.atan(matrix.b / matrix.a);
  _scaleY = (_skewX > -piQuarter && _skewX < piQuarter)
      ? matrix.d / Math.cos(_skewX)
      : -matrix.c / Math.sin(_skewX);
  _scaleX = (_skewY > -piQuarter && _skewY < piQuarter)
      ? matrix.a / Math.cos(_skewY)
      : -matrix.b / Math.sin(_skewY);
  if (MathUtils.isEquivalent(_skewX, _skewY)) {
    _rotation = _skewX;
    _skewX = _skewY = 0;
  } else {
    _rotation = 0;
  }
}