calculateMiddleSegment function

int calculateMiddleSegment(
  1. int totalWidth,
  2. int segmentWidth
)

Implementation

int calculateMiddleSegment(int totalWidth, int segmentWidth) {
  int middleIndex = totalWidth ~/ 2;
  int middleSegment = middleIndex ~/ segmentWidth;
  int wastedSize = middleIndex - (segmentWidth * middleSegment);
  if (wastedSize > 10) {
    middleSegment++;
  }

  return middleSegment * 20;
}