normalized method

RoundedPolygon normalized()

Returns a new RoundedPolygon, moving and resizing this one, so it's completely inside the (0, 0) -> (1, 1) square, centered if there is extra space in one direction.

Implementation

RoundedPolygon normalized() {
  final bounds = calculateApproximateBounds();
  final side = math.max(bounds.width, bounds.height);

  if (side < distanceEpsilon) return this;

  // Center the shape if bounds are not a square.
  final offsetX = (side - bounds.width) / 2.0 - bounds.left;
  final offsetY = (side - bounds.height) / 2.0 - bounds.top;

  return transformed((x, y) => ((x + offsetX) / side, (y + offsetY) / side));
}