hitTestMask method

bool hitTestMask(
  1. GPoint localPoint
)

Determines whether the localPoint specified in the local coordinates of this object lies inside its mask.

If the object has no mask or maskRect, this method returns true.

If the object has a maskRect, this method determines whether the point is inside the rectangle.

If the object has a $mask, this method transforms the point into the local coordinate system of the mask using the $mask's transformation matrix and then checks if the point is inside the mask's boundary. If maskInverted is true, the result is inverted.

Implementation

bool hitTestMask(GPoint localPoint) {
  if ($mask == null && maskRect == null) {
    return true;
  }
  if (maskRect != null) {
    final isHit = maskRect!.containsPoint(localPoint);
    return maskRectInverted ? !isHit : isHit;
  }
  if ($mask!.inStage) {
    getTransformationMatrix($mask, _sHelperMatrixAlt);
  } else {
    _sHelperMatrixAlt.copyFrom($mask!.transformationMatrix);
    _sHelperMatrixAlt.invert();
  }

  var helperPoint = localPoint == _sHelperPoint ? GPoint() : _sHelperPoint;
  _sHelperMatrixAlt.transformPoint(localPoint, helperPoint);

  final isHit = mask!.hitTest(helperPoint) != null;
  return maskInverted ? !isHit : isHit;
}