@Test public void quantize2() { assertThat(LogValueScale.quantize(1.2), equalTo(2)); }
static int quantize(double value) { if (value <= 1) { return 1; } int exp = MathUtil.orderOf(value); double order = Math.pow(10, exp); double normalizedValue = value / order; if (normalizedValue <= 1) { normalizedValue = 1; } else if (normalizedValue <= 2) { normalizedValue = 2; } else if (normalizedValue <= 5) { normalizedValue = 5; } else if (normalizedValue <= 10) { normalizedValue = 10; } else { throw new IllegalStateException("Logic error: this should be unreachable"); } return (int) (normalizedValue * order); }
LogValueScale implements ValueScale { static int quantize(double value) { if (value <= 1) { return 1; } int exp = MathUtil.orderOf(value); double order = Math.pow(10, exp); double normalizedValue = value / order; if (normalizedValue <= 1) { normalizedValue = 1; } else if (normalizedValue <= 2) { normalizedValue = 2; } else if (normalizedValue <= 5) { normalizedValue = 5; } else if (normalizedValue <= 10) { normalizedValue = 10; } else { throw new IllegalStateException("Logic error: this should be unreachable"); } return (int) (normalizedValue * order); } }
LogValueScale implements ValueScale { static int quantize(double value) { if (value <= 1) { return 1; } int exp = MathUtil.orderOf(value); double order = Math.pow(10, exp); double normalizedValue = value / order; if (normalizedValue <= 1) { normalizedValue = 1; } else if (normalizedValue <= 2) { normalizedValue = 2; } else if (normalizedValue <= 5) { normalizedValue = 5; } else if (normalizedValue <= 10) { normalizedValue = 10; } else { throw new IllegalStateException("Logic error: this should be unreachable"); } return (int) (normalizedValue * order); }  }
LogValueScale implements ValueScale { static int quantize(double value) { if (value <= 1) { return 1; } int exp = MathUtil.orderOf(value); double order = Math.pow(10, exp); double normalizedValue = value / order; if (normalizedValue <= 1) { normalizedValue = 1; } else if (normalizedValue <= 2) { normalizedValue = 2; } else if (normalizedValue <= 5) { normalizedValue = 5; } else if (normalizedValue <= 10) { normalizedValue = 10; } else { throw new IllegalStateException("Logic error: this should be unreachable"); } return (int) (normalizedValue * order); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double actualMinValue, double actualMaxValue, double scaleMinValue, double scaleMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs); }
LogValueScale implements ValueScale { static int quantize(double value) { if (value <= 1) { return 1; } int exp = MathUtil.orderOf(value); double order = Math.pow(10, exp); double normalizedValue = value / order; if (normalizedValue <= 1) { normalizedValue = 1; } else if (normalizedValue <= 2) { normalizedValue = 2; } else if (normalizedValue <= 5) { normalizedValue = 5; } else if (normalizedValue <= 10) { normalizedValue = 10; } else { throw new IllegalStateException("Logic error: this should be unreachable"); } return (int) (normalizedValue * order); }  @Override double scaleValue(double value, double minValue, double maxValue, double newMinValue, double newMaxValue); @Override double invScaleValue(double scaleValue, double actualMinValue, double actualMaxValue, double scaleMinValue, double scaleMaxValue); @Override ValueAxis references(Range range, int minRefs, int maxRefs);  }