@Test public void testGetNearestNiceValue() { ScalebarGraphic scalebar = new ScalebarGraphic(); assertEquals(10.0, scalebar.getNearestNiceValue(10.0, DistanceUnit.M, false), TOLERANCE); assertEquals(10.0, scalebar.getNearestNiceValue(13.0, DistanceUnit.M, false), TOLERANCE); assertEquals(50.0, scalebar.getNearestNiceValue(67.66871, DistanceUnit.M, false), TOLERANCE); assertEquals(0.02, scalebar.getNearestNiceValue(0.0315, DistanceUnit.M, false), TOLERANCE); assertEquals(1000000000.0, scalebar.getNearestNiceValue(1240005466, DistanceUnit.M, false), TOLERANCE); assertEquals(50.0, scalebar.getNearestNiceValue(98.66871, DistanceUnit.M, false), TOLERANCE); }
@VisibleForTesting protected static double getNearestNiceValue( final double value, final DistanceUnit scaleUnit, final boolean lockUnits) { DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits); double factor = scaleUnit.convertTo(1.0, bestUnit); int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10))); double pow10 = Math.pow(10, digits); double firstChar = value * factor / pow10; int barLen; if (firstChar >= 10.0) { barLen = 10; } else if (firstChar >= 5.0) { barLen = 5; } else if (firstChar >= 2.0) { barLen = 2; } else { barLen = 1; } return barLen * pow10 / factor; }
ScalebarGraphic { @VisibleForTesting protected static double getNearestNiceValue( final double value, final DistanceUnit scaleUnit, final boolean lockUnits) { DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits); double factor = scaleUnit.convertTo(1.0, bestUnit); int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10))); double pow10 = Math.pow(10, digits); double firstChar = value * factor / pow10; int barLen; if (firstChar >= 10.0) { barLen = 10; } else if (firstChar >= 5.0) { barLen = 5; } else if (firstChar >= 2.0) { barLen = 2; } else { barLen = 1; } return barLen * pow10 / factor; } }
ScalebarGraphic { @VisibleForTesting protected static double getNearestNiceValue( final double value, final DistanceUnit scaleUnit, final boolean lockUnits) { DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits); double factor = scaleUnit.convertTo(1.0, bestUnit); int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10))); double pow10 = Math.pow(10, digits); double firstChar = value * factor / pow10; int barLen; if (firstChar >= 10.0) { barLen = 10; } else if (firstChar >= 5.0) { barLen = 5; } else if (firstChar >= 2.0) { barLen = 2; } else { barLen = 1; } return barLen * pow10 / factor; }  }
ScalebarGraphic { @VisibleForTesting protected static double getNearestNiceValue( final double value, final DistanceUnit scaleUnit, final boolean lockUnits) { DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits); double factor = scaleUnit.convertTo(1.0, bestUnit); int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10))); double pow10 = Math.pow(10, digits); double firstChar = value * factor / pow10; int barLen; if (firstChar >= 10.0) { barLen = 10; } else if (firstChar >= 5.0) { barLen = 5; } else if (firstChar >= 2.0) { barLen = 2; } else { barLen = 1; } return barLen * pow10 / factor; }  final URI render(
            final MapfishMapContext mapContext,
            final ScalebarAttributeValues scalebarParams,
            final File tempFolder,
            final Template template); }
ScalebarGraphic { @VisibleForTesting protected static double getNearestNiceValue( final double value, final DistanceUnit scaleUnit, final boolean lockUnits) { DistanceUnit bestUnit = bestUnit(scaleUnit, value, lockUnits); double factor = scaleUnit.convertTo(1.0, bestUnit); int digits = (int) Math.floor((Math.log(value * factor) / Math.log(10))); double pow10 = Math.pow(10, digits); double firstChar = value * factor / pow10; int barLen; if (firstChar >= 10.0) { barLen = 10; } else if (firstChar >= 5.0) { barLen = 5; } else if (firstChar >= 2.0) { barLen = 2; } else { barLen = 1; } return barLen * pow10 / factor; }  final URI render(
            final MapfishMapContext mapContext,
            final ScalebarAttributeValues scalebarParams,
            final File tempFolder,
            final Template template);  }