scaleRadii method Null safety

RRect scaleRadii()

Scales all radii so that on each side their sum will not exceed the size of the width/height.

Skia already handles RRects with radii that are too large in this way. Therefore, this method is only needed for RRect use cases that require the appropriately scaled radii values.

See the Skia scaling implementation for more details.

Implementation

RRect scaleRadii() {
  double scale = 1.0;
  scale = _getMin(scale, blRadiusY, tlRadiusY, height);
  scale = _getMin(scale, tlRadiusX, trRadiusX, width);
  scale = _getMin(scale, trRadiusY, brRadiusY, height);
  scale = _getMin(scale, brRadiusX, blRadiusX, width);

  if (scale < 1.0) {
    return RRect._raw(
      top: top,
      left: left,
      right: right,
      bottom: bottom,
      tlRadiusX: tlRadiusX * scale,
      tlRadiusY: tlRadiusY * scale,
      trRadiusX: trRadiusX * scale,
      trRadiusY: trRadiusY * scale,
      blRadiusX: blRadiusX * scale,
      blRadiusY: blRadiusY * scale,
      brRadiusX: brRadiusX * scale,
      brRadiusY: brRadiusY * scale,
    );
  }

  return RRect._raw(
    top: top,
    left: left,
    right: right,
    bottom: bottom,
    tlRadiusX: tlRadiusX,
    tlRadiusY: tlRadiusY,
    trRadiusX: trRadiusX,
    trRadiusY: trRadiusY,
    blRadiusX: blRadiusX,
    blRadiusY: blRadiusY,
    brRadiusX: brRadiusX,
    brRadiusY: brRadiusY,
  );
}