resizeShapesAlongWidth method

Map<MeasurementName, double> resizeShapesAlongWidth(
  1. Size shapeSize,
  2. double spaceBetweenShapes,
  3. Size canvasSize
)

This is used to resize the shapes and the space between the shapes to fit the screen width perfectly and proportionally.

This is done because if the original shapeSize.width + spaceBetweenShapes is not a factor of the screen width, then the shapes will not fit the screen width perfectly. The will be too close together or too far apart at the beginning and end of the loop. The measurements remain very close to the original measurements.

It returns a map:

{
  MeasurementName.shapeHeight: newShapeHeight,
  MeasurementName.shapeWeight: newShapeWeight,
  MeasurementName.spaceBetweenShapes: newSpaceBetweenShapes,
}

Implementation

Map<MeasurementName, double> resizeShapesAlongWidth(
  Size shapeSize,
  double spaceBetweenShapes,
  Size canvasSize,
) {
  final double shapeHeightAndWidthProportion =
      shapeSize.height / shapeSize.width;

  final Map<MeasurementName, double> resizedMeasurements = _resizeShapes(
    shapeSize.width,
    spaceBetweenShapes,
    canvasSize.width,
    MeasurementName.shapeWidth,
  );

  final double newShapeWidth =
      resizedMeasurements[MeasurementName.shapeWidth] ?? shapeSize.width;

  resizedMeasurements[MeasurementName.shapeHeight] =
      newShapeWidth * shapeHeightAndWidthProportion;

  return resizedMeasurements;
}