public void testEncodeDecodeRoundsDown() throws Exception {
  int iters=atLeast(1000);
  for (int iter=0; iter < iters; iter++) {
    final double latBase=GeoTestUtil.nextLatitude();
    final double lonBase=GeoTestUtil.nextLongitude();
    double lat=latBase;
    double lon=lonBase;
    for (int i=0; i < 1000; i++) {
      lat=Math.min(90,Math.nextUp(lat));
      lon=Math.min(180,Math.nextUp(lon));
      GeoPoint point=new GeoPoint(PlanetModel.WGS84,toRadians(lat),toRadians(lon));
      GeoPoint pointEnc=new GeoPoint(Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.x)),Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.y)),Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.z)));
      assertTrue(pointEnc.x <= point.x);
      assertTrue(pointEnc.y <= point.y);
      assertTrue(pointEnc.z <= point.z);
    }
    lat=latBase;
    lon=lonBase;
    for (int i=0; i < 1000; i++) {
      lat=Math.max(-90,Math.nextDown(lat));
      lon=Math.max(-180,Math.nextDown(lon));
      GeoPoint point=new GeoPoint(PlanetModel.WGS84,toRadians(lat),toRadians(lon));
      GeoPoint pointEnc=new GeoPoint(Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.x)),Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.y)),Geo3DUtil.decodeValueFloor(Geo3DUtil.encodeValue(point.z)));
      assertTrue(pointEnc.x <= point.x);
      assertTrue(pointEnc.y <= point.y);
      assertTrue(pointEnc.z <= point.z);
    }
  }
}

public void testEncodeDecodeRoundsDown ( ) throws Exception { int iters = atLeast ( 1000 ) ; for ( int iter = 0 ; iter < iters ; iter ++ ) { final double latBase = GeoTestUtil . nextLatitude ( ) ; final double lonBase = GeoTestUtil . nextLongitude ( ) ; double lat = latBase ; double lon = lonBase ; for ( int i = 0 ; i < 1000 ; i ++ ) { lat = Math . min ( 90 , Math . nextUp ( lat ) ) ; lon = Math . min ( 180 , Math . nextUp ( lon ) ) ; GeoPoint point = new GeoPoint ( PlanetModel . WGS84 , toRadians ( lat ) , toRadians ( lon ) ) ; GeoPoint pointEnc = new GeoPoint ( Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . x ) ) , Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . y ) ) , Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . z ) ) ) ; assertTrue ( pointEnc . x <= point . x ) ; assertTrue ( pointEnc . y <= point . y ) ; assertTrue ( pointEnc . z <= point . z ) ; } lat = latBase ; lon = lonBase ; for ( int i = 0 ; i < 1000 ; i ++ ) { lat = Math . max ( - 90 , Math . nextDown ( lat ) ) ; lon = Math . max ( - 180 , Math . nextDown ( lon ) ) ; GeoPoint point = new GeoPoint ( PlanetModel . WGS84 , toRadians ( lat ) , toRadians ( lon ) ) ; GeoPoint pointEnc = new GeoPoint ( Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . x ) ) , Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . y ) ) , Geo3DUtil . decodeValueFloor ( Geo3DUtil . encodeValue ( point . z ) ) ) ; assertTrue ( pointEnc . x <= point . x ) ; assertTrue ( pointEnc . y <= point . y ) ; assertTrue ( pointEnc . z <= point . z ) ; } } }
make sure values always go down : this is important for edge case consistency
