private static double snapScaleToSingleDigitPrecision(double scaleRaw) { // if the rounding error is not nudged, snapping can "stick" at some values double pow10 = Math.floor(MathUtil.log10(scaleRaw) + ROUND_ERROR_REMOVAL); double nearestLowerPow10 = Math.pow(10, pow10); int scaleDigit = (int) (scaleRaw / nearestLowerPow10); double scale = scaleDigit * nearestLowerPow10; //System.out.println("requested scale = " + scaleRaw + " scale = " + scale + " Pow10 = " + pow10); return scale; }
/** * Not used - scaling to multiples of 10,5,2 is too coarse. * * * @param scaleRaw * @return */ private static double snapScaleTo_10_2_5(double scaleRaw) { // if the rounding error is not nudged, snapping can "stick" at some values double pow10 = Math.floor(MathUtil.log10(scaleRaw) + ROUND_ERROR_REMOVAL); double scaleRoundedToPow10 = Math.pow(10, pow10); double scale = scaleRoundedToPow10; // rounding to a power of 10 is too coarse, so allow some finer gradations //* if (3.5 * scaleRoundedToPow10 <= scaleRaw) scale = 5 * scaleRoundedToPow10; else if (2 * scaleRoundedToPow10 <= scaleRaw) scale = 2 * scaleRoundedToPow10; //*/ //System.out.println("requested scale = " + scaleRaw + " scale = " + scale + " Pow10 = " + pow10); return scale; }
private void setScaleNoUpdate(double scale) { this.scale = snapScale(scale); scalePM = new PrecisionModel(this.scale); scaleFormat = NumberFormat.getInstance(); int fracDigits = (int) (MathUtil.log10(this.scale)); if (fracDigits < 0) fracDigits = 0; //System.out.println("scale = " + this.scale); //System.out.println("fracdigits = " + fracDigits); scaleFormat.setMaximumFractionDigits(fracDigits); // don't show commas scaleFormat.setGroupingUsed(false); }
private int maxVisibleMagnitude() { double visibleExtentModel = viewport.getModelEnv().maxExtent(); // if input is bogus then just return something reasonable if (visibleExtentModel <= 0.0) return 1; double log10 = MathUtil.log10(visibleExtentModel); return (int) log10; }
/** * Gets the magnitude (power of 10) * for the basic grid size. * * @return the magnitude */ public int gridMagnitudeModel() { double pixelSizeModel = toModel(1); double pixelSizeModelLog = MathUtil.log10(pixelSizeModel); int gridMag = (int) Math.ceil(pixelSizeModelLog); /** * Check if grid size is too small and if so increase it one magnitude */ double gridSizeModel = Math.pow(10, gridMag); double gridSizeView = toView(gridSizeModel); // System.out.println("\ncand gridSizeView= " + gridSizeView); if (gridSizeView <= MIN_GRID_RESOLUTION_PIXELS ) gridMag += 1; // System.out.println("pixelSize= " + pixelSize + " pixelLog10= " + pixelSizeLog); return gridMag; }