normalized method

RoundedPolygon normalized()

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

Implementation

RoundedPolygon normalized() {
  final bounds = calculateBounds();
  final width = bounds[2] - bounds[0];
  final height = bounds[3] - bounds[1];
  final side = math.max(width, height);

  // Center the shape if bounds are not a square.
  final offsetX = (side - width) / 2 - bounds[0]; /* left */
  final offsetY = (side - height) / 2 - bounds[1]; /* top */

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