docs: private static void tryLayout(
              final Graphics2D graphics2D, final DistanceUnit scaleUnit, final double scaleDenominator,
              final double intervalLengthInWorldUnits, final ScaleBarRenderSettings settings,
              final int tryNumber) {
          if (tryNumber > MAX_NUMBER_LAYOUTING_TRIES) {
              // if no good layout can be found, stop. an empty scalebar graphic will be shown.
              LOGGER.error("layouting the scalebar failed (unit: {}, scale: {})", scaleUnit, scaleDenominator);
              return;
          }
  
          final ScalebarAttributeValues scalebarParams = settings.getParams();
          final DistanceUnit intervalUnit =
                  bestUnit(scaleUnit, intervalLengthInWorldUnits, scalebarParams.lockUnits);
          final float intervalLengthInPixels = (float) scaleUnit.convertTo(
                  intervalLengthInWorldUnits / scaleDenominator, DistanceUnit.PX);
  
          //compute the label positions
          final List<Label> labels = new ArrayList<>(scalebarParams.intervals + 1);
          final float leftLabelMargin;
          final float rightLabelMargin;
          final float topLabelMargin;
          final float bottomLabelMargin;
  
          final Font font = new Font(scalebarParams.font, Font.PLAIN, getFontSize(settings));
          final FontRenderContext frc = new FontRenderContext(null, true, true);
  
          if (scalebarParams.intervals > 1 || scalebarParams.subIntervals) {
              //the label will be centered under each tick mark
              for (int i = 0; i <= scalebarParams.intervals; i++) {
                  String labelText = createLabelText(scaleUnit, intervalLengthInWorldUnits * i, intervalUnit);
                  if (i == scalebarParams.intervals) {
                      // only show unit for the last label
                      labelText += intervalUnit;
                  }
                  TextLayout labelLayout = new TextLayout(labelText, font, frc);
                  labels.add(new Label(intervalLengthInPixels * i, labelLayout, graphics2D));
              }
              leftLabelMargin = labels.get(0).getRotatedWidth(scalebarParams.getLabelRotation()) / 2.0f;
              rightLabelMargin =
                      labels.get(labels.size() - 1).getRotatedWidth(scalebarParams.getLabelRotation()) / 2.0f;
              topLabelMargin = labels.get(0).getRotatedHeight(scalebarParams.getLabelRotation()) / 2.0f;
              bottomLabelMargin =
                      labels.get(labels.size() - 1).getRotatedHeight(scalebarParams.getLabelRotation()) / 2.0f;
          } else {
              //if there is only one interval, place the label centered between the two tick marks
              String labelText =
                      createLabelText(scaleUnit, intervalLengthInWorldUnits, intervalUnit) + intervalUnit;
              TextLayout labelLayout = new TextLayout(labelText, font, frc);
              final Label label = new Label(intervalLengthInPixels / 2.0f, labelLayout, graphics2D);
              labels.add(label);
              rightLabelMargin = 0;
              leftLabelMargin = 0;
              topLabelMargin = 0;
              bottomLabelMargin = 0;
          }
  
          if (fitsAvailableSpace(scalebarParams, intervalLengthInPixels,
                                 leftLabelMargin, rightLabelMargin, topLabelMargin, bottomLabelMargin,
                                 settings)) {
              //the layout fits the maxSize
              settings.setLabels(labels);
              settings.setScaleUnit(scaleUnit);
              settings.setIntervalLengthInPixels(intervalLengthInPixels);
              settings.setIntervalLengthInWorldUnits(intervalLengthInWorldUnits);
              settings.setIntervalUnit(intervalUnit);
              settings.setLeftLabelMargin(leftLabelMargin);
              settings.setRightLabelMargin(rightLabelMargin);
              settings.setTopLabelMargin(topLabelMargin);
              settings.setBottomLabelMargin(bottomLabelMargin);
  
              doLayout(graphics2D, scalebarParams, settings);
          } else {
              //not enough room because of the labels, try a smaller bar
              double nextIntervalDistance = getNearestNiceValue(
                      intervalLengthInWorldUnits * 0.9, scaleUnit, scalebarParams.lockUnits);
              tryLayout(graphics2D, scaleUnit, scaleDenominator, nextIntervalDistance, settings,
                        tryNumber + 1);
          }
      }