getBounds method

GRect getBounds(
  1. GMatrix matrix, [
  2. GRect? out
])

Returns the bounds of this GRect when transformed by the given matrix, optionally storing the result in the given out parameter.

The method first calculates the four corner points of the rectangle and then applies the matrix transformation to each of them. The bounding box of the transformed points is calculated and returned as the result.

If the out parameter is not null, it is used to store the calculated result.

Implementation

GRect getBounds(GMatrix matrix, [GRect? out]) {
  out ??= GRect();
  var minX = 10000000.0;
  var maxX = -10000000.0;
  var minY = 10000000.0;
  var maxY = -10000000.0;
  final positions = getPositions(_sHelperPositions);
  for (var point in positions) {
    matrix.transformCoords(point.x, point.y, _sHelperPoint);
    if (minX > _sHelperPoint.x) minX = _sHelperPoint.x;
    if (maxX < _sHelperPoint.x) maxX = _sHelperPoint.x;
    if (minY > _sHelperPoint.y) minY = _sHelperPoint.y;
    if (maxY < _sHelperPoint.y) maxY = _sHelperPoint.y;
  }
  return out.setTo(minX, minY, maxX - minX, maxY - minY);
}