LongitudeDefinition extends BasicDimensionDefinition { @Override public BinRange[] getNormalizedRanges(final NumericData range) { if (range == null) { return new BinRange[0]; } if (FloatCompareUtils.checkDoublesEqual(range.getMin(), range.getMax())) { return super.getNormalizedRanges(range); } final double normalizedMin = getNormalizedLongitude(range.getMin()); final double normalizedMax = getNormalizedLongitude(range.getMax()); if ((normalizedMax < normalizedMin) && !((FloatCompareUtils.checkDoublesEqual(normalizedMax, -1) && (FloatCompareUtils.checkDoublesEqual(normalizedMin, 0))))) { return new BinRange[] {new BinRange(-180, normalizedMax), new BinRange(normalizedMin, 180)}; } return new BinRange[] {new BinRange(normalizedMin, normalizedMax)}; } LongitudeDefinition(); @Override BinRange[] getNormalizedRanges(final NumericData range); static double getNormalizedLongitude(final double lon); @Override byte[] toBinary(); @Override void fromBinary(final byte[] bytes);  }
@Test public void testNormalizeWithinBoundsRanges() { final double minRange = 10; final double maxRange = 100; final BinRange[] binRange = getNormalizedRanges(minRange, maxRange); Assert.assertEquals(minRange, binRange[0].getNormalizedMin(), DELTA); Assert.assertEquals(maxRange, binRange[0].getNormalizedMax(), DELTA); }
@Test public void testNormalizeDateLineCrossingEast() { final double minRange = 150; final double maxRange = 200; final int expectedBinCount = 2; final BinRange[] expectedBinRanges = new BinRange[] {new BinRange(-180, -160), new BinRange(150, 180)}; final BinRange[] binRange = getNormalizedRanges(minRange, maxRange); Assert.assertEquals(expectedBinCount, binRange.length); for (int i = 0; i < binRange.length; i++) { Assert.assertEquals( expectedBinRanges[i].getNormalizedMin(), binRange[i].getNormalizedMin(), DELTA); Assert.assertEquals( expectedBinRanges[i].getNormalizedMax(), binRange[i].getNormalizedMax(), DELTA); } }
@Test public void testNormalizeDateLineCrossingWest() { final double minRange = -200; final double maxRange = -170; final int expectedBinCount = 2; final BinRange[] expectedBinRanges = new BinRange[] {new BinRange(-180, -170), new BinRange(160, 180)}; final BinRange[] binRange = getNormalizedRanges(minRange, maxRange); Assert.assertEquals(expectedBinCount, binRange.length); for (int i = 0; i < binRange.length; i++) { Assert.assertEquals( expectedBinRanges[i].getNormalizedMin(), binRange[i].getNormalizedMin(), DELTA); Assert.assertEquals( expectedBinRanges[i].getNormalizedMax(), binRange[i].getNormalizedMax(), DELTA); } }