int rasterWidth = tileMatrix.matrixWidth * tileWidth; int rasterHeight = tileMatrix.matrixHeight * tileHeight; double matrixMaxLat = tileMatrix.sector.maxLatitude(); double matrixMinLon = tileMatrix.sector.minLongitude(); double matrixDeltaLat = tileMatrix.sector.deltaLatitude(); double matrixDeltaLon = tileMatrix.sector.deltaLongitude(); Sector intersection = new Sector(tileMatrix.sector); intersection.intersect(sector); double sMin = (intersection.minLongitude() - matrixMinLon) / matrixDeltaLon; double sMax = (intersection.maxLongitude() - matrixMinLon) / matrixDeltaLon; double uMin = Math.floor(rasterWidth * sMin); double uMax = Math.ceil(rasterWidth * sMax); int colMax = iMax / tileWidth; double tMin = (matrixMaxLat - intersection.maxLatitude()) / matrixDeltaLat; double tMax = (matrixMaxLat - intersection.minLatitude()) / matrixDeltaLat; double vMin = Math.floor(rasterHeight * tMin); double vMax = Math.ceil(rasterHeight * tMax);
@Test public void testIntersects_Empty() throws Exception { Sector a = Sector.fromDegrees(30, 100, 3.0, 3.0); assertFalse("empty", a.intersects(new Sector())); assertFalse("no dimension", a.intersects(new Sector(31.0, 101.0, 0d, 0d))); assertFalse("no dimension from union", a.intersects(new Sector().union(31.0, 101.0))); assertFalse("no lat", a.intersects(new Sector(Double.NaN, 101.0, 5d, 5d))); assertFalse("no lon", a.intersects(new Sector(31.0, Double.NaN, 5d, 5d))); assertFalse("no width", a.intersects(new Sector(31.0, 101.0, 5d, 0d))); assertFalse("no height", a.intersects(new Sector(31.0, 101.0, 0d, 5d))); }
public Sector tileSector(int row, int column) { double deltaLat = this.sector.deltaLatitude() / this.matrixHeight; double deltaLon = this.sector.deltaLongitude() / this.matrixWidth; double minLat = this.sector.maxLatitude() - deltaLat * (row + 1); double minLon = this.sector.minLongitude() + deltaLon * column; return new Sector(minLat, minLon, deltaLat, deltaLon); } }
/** * Returns the coordinates of the sector as an array of values in radians, in the order minLat, maxLat, minLon, * maxLon. * * @return the array of sector coordinates. */ public double[] asRadiansArray() { return new double[] { this.getMinLatitude().radians, this.getMaxLatitude().radians, this.getMinLongitude().radians, this.getMaxLongitude().radians }; }
@Test public void testUnion_Sector() throws Exception { Sector a = Sector.fromDegrees(-30, -100, 1.0, 1.0); Sector b = a.union(new Sector(40, 110, 1.0, 1.0)); assertFalse(a.isEmpty()); assertEquals("min lat", -30, a.minLatitude(), 0); assertEquals("min lon", -100, a.minLongitude(), 0); assertEquals("max lat", 41, a.maxLatitude(), 0); assertEquals("max lon", 111, a.maxLongitude(), 0); assertSame(a, b); } }
protected boolean addImage() { // Create an image source with a unique factory instance. This pattern is used in order to force WorldWind to // allocate a new OpenGL texture object for each surface image from a single bitmap instance. ImageSource imageSource = ImageSource.fromBitmapFactory(new ImageSource.BitmapFactory() { @Override public Bitmap createBitmap() { return bitmap; } }); // Add the surface image to this test's layer. this.layer.addRenderable(new SurfaceImage(new Sector(this.sector), imageSource)); this.getWorldWindow().requestRedraw(); // Advance to the next surface image's location. if (this.sector.maxLongitude() < this.firstSector.minLongitude() + this.firstSector.deltaLongitude() * 20) { this.sector.set( this.sector.minLatitude(), this.sector.minLongitude() + this.sector.deltaLongitude() + 0.1, this.sector.deltaLatitude(), this.sector.deltaLongitude()); } else { this.sector.set( this.sector.minLatitude() + this.sector.deltaLatitude() + 0.1, this.firstSector.minLongitude(), this.sector.deltaLatitude(), this.sector.deltaLongitude()); } // Add another image after the configured delay. return this.handler.sendEmptyMessageDelayed(ADD_IMAGE, ADD_IMAGE_DELAY); }
@Test public void testIntersect_AdjacentEast() throws Exception { Sector a = Sector.fromDegrees(30, 100, 3.0, 3.0); Sector adjacentEast = Sector.fromDegrees(31, 103, 1.0, 1.0); Sector copy = new Sector(a); boolean intersected = a.intersect(adjacentEast); assertFalse("adjacent, no intersection", intersected); assertEquals("adjacent, no changed", a, copy); }
@Test public void testIntersects() throws Exception { Sector a = Sector.fromDegrees(30, 100, 3.0, 3.0); Sector copy = new Sector(a); assertTrue("inside", a.intersects(new Sector(31.0, 101.0, 1d, 1d))); assertTrue("overlap east", a.intersects(new Sector(31.0, 102.0, 1d, 2d))); assertTrue("overlap west", a.intersects(new Sector(31.0, 99.0, 1d, 2d))); assertTrue("overlap north", a.intersects(new Sector(32.0, 101.0, 2d, 1d))); assertTrue("overlap south", a.intersects(new Sector(29.0, 101.0, 2d, 1d))); assertEquals("no mutation", copy, a); }
@Test public void testEquals() throws Exception { double lat = 34.2; double lon = -119.2; double dLat = 1.0; double dLon = 2.0; Sector sector1 = Sector.fromDegrees(lat, lon, dLat, dLon); Sector sector2 = Sector.fromDegrees(lat, lon, dLat, dLon); assertEquals("minLatitude", sector2.minLatitude(), sector1.minLatitude(), 0); assertEquals("minLongitude", sector2.minLongitude(), sector1.minLongitude(), 0); assertEquals("maxLatitude", sector2.maxLatitude(), sector1.maxLatitude(), 0); assertEquals("maxLongitude", sector2.maxLongitude(), sector1.maxLongitude(), 0); assertEquals("deltaLatitude", sector2.deltaLatitude(), sector1.deltaLatitude(), 0); assertEquals("deltaLongitude", sector2.deltaLongitude(), sector1.deltaLongitude(), 0); assertEquals(sector1, sector1); assertEquals(sector1, sector2); }
public static Sector fromDegrees(double latitudeDegrees, double longitudeDegrees, double deltaLatitudeDegrees, double deltaLongitudeDegrees) { return new Sector( latitudeDegrees, longitudeDegrees, deltaLatitudeDegrees, deltaLongitudeDegrees); }
@Test public void testIntersect() throws Exception { Sector a = Sector.fromDegrees(30, 100, 2.0, 2.0); Sector b = Sector.fromDegrees(31, 101, 2.0, 2.0); Sector northeast = Sector.fromDegrees(31, 101, 1.0, 1.0); boolean intersected = a.intersect(b); assertTrue("intersecting", intersected); assertEquals("intersection", northeast, a); }
@Test public void testContains_Sector() throws Exception { Sector a = Sector.fromDegrees(30, 100, 3.0, 3.0); assertTrue("coincident", a.contains(new Sector(30, 100, 3.0, 3.0))); assertTrue("inside", a.contains(new Sector(31, 101, 1.0, 1.0))); }
int rasterWidth = tileBlock.tileMatrix.matrixWidth * tileWidth; int rasterHeight = tileBlock.tileMatrix.matrixHeight * tileHeight; double matrixMinLat = tileBlock.tileMatrix.sector.minLatitude(); double matrixMaxLat = tileBlock.tileMatrix.sector.maxLatitude(); double matrixMinLon = tileBlock.tileMatrix.sector.minLongitude(); double matrixMaxLon = tileBlock.tileMatrix.sector.maxLongitude(); double matrixDeltaLat = tileBlock.tileMatrix.sector.deltaLatitude(); double matrixDeltaLon = tileBlock.tileMatrix.sector.deltaLongitude(); double sMin = 1.0 / (2.0 * rasterWidth); double sMax = 1.0 - sMin; int ridx = 0; double lat = gridSector.minLatitude(); double deltaLat = gridSector.deltaLatitude() / (gridHeight - 1); for (int hidx = 0; hidx < gridHeight; hidx++, lat += deltaLat) { if (hidx == gridHeight - 1) { lat = gridSector.maxLatitude(); // explicitly set the last lat to the max latitude to ensure alignment double lon = gridSector.minLongitude(); double deltaLon = gridSector.deltaLongitude() / (gridWidth - 1); for (int widx = 0; widx < gridWidth; widx++, lon += deltaLon) { if (widx == gridWidth - 1) { lon = gridSector.maxLongitude(); // explicitly set the last lon to the max longitude to ensure alignment double u; int i0, i1; if (tileBlock.tileMatrix.sector.isFullSphere()) {
@Test public void testHashCode() throws Exception { Sector a = new Sector(); Sector b = Sector.fromDegrees(34.2, -119.2, 1.0, 2.0); Sector c = Sector.fromDegrees(33.94, -118.4, 1.0, 2.0); int aHash = a.hashCode(); int bHash = b.hashCode(); int cHash = c.hashCode(); assertNotEquals("a hash vs b hash", bHash, aHash); assertNotEquals("b hash vs c hash", cHash, bHash); }
@Test public void testIsEmpty() throws Exception { Sector empty = new Sector(); Sector noDim = Sector.fromDegrees(34.2, -119.2, 0, 0); Sector noWidth = Sector.fromDegrees(34.2, -119.2, 1.0, 0); Sector noHeight = Sector.fromDegrees(34.2, -119.2, 0, 1.0); Sector noLat = Sector.fromDegrees(Double.NaN, -119.2, 1.0, 1.0); Sector noLon = Sector.fromDegrees(34.2, Double.NaN, 1.0, 1.0); Sector typical = Sector.fromDegrees(34.2, -119.2, 1.0, 1.0); assertTrue("default is empty", empty.isEmpty()); assertTrue("no dimension is empty", noDim.isEmpty()); assertTrue("no width is empty", noWidth.isEmpty()); assertTrue("no height is empty", noHeight.isEmpty()); assertTrue("no latitude is empty", noLat.isEmpty()); assertTrue("no longitude is empty", noLon.isEmpty()); assertFalse("typical is not empty", typical.isEmpty()); }
@Test public void testContains() throws Exception { Sector a = Sector.fromDegrees(30, 100, 1.0, 1.0); assertTrue("inside", a.contains(30.5, 100.5)); assertTrue("northeast point", a.contains(31, 101)); assertTrue("northwest point", a.contains(31, 100)); assertTrue("southwest point", a.contains(30, 100)); assertTrue("southeast point", a.contains(30, 101)); assertFalse("outside", a.contains(-30, -100)); }
if (sector.contains(latitude, longitude)) { double s = (longitude - sector.minLongitude()) / sector.deltaLongitude() * (tileWidth - 1); double t = (latitude - sector.minLatitude()) / sector.deltaLatitude() * (tileHeight - 1); double sf = (s < tileWidth - 1) ? WWMath.fract(s) : 1; double tf = (t < tileHeight - 1) ? WWMath.fract(t) : 1;
@Test public void testEquals_Inequality() throws Exception { Sector empty = new Sector(); Sector other = new Sector(); Sector typical = Sector.fromDegrees(34.2, -119.2, 1.0, 2.0); Sector another = Sector.fromDegrees(33.94, -118.4, 1.0, 2.0); assertNotEquals(empty, empty); assertNotEquals(empty, other); assertNotEquals(empty, typical); assertNotEquals(empty, null); assertNotEquals(typical, another); assertNotEquals(typical, null); }
@Test public void testFromRadians() throws Exception { double lat = 34.2; double lon = -119.2; double dLat = 1.0; double dLon = 2.0; double latRad = Math.toRadians(lat); double lonRad = Math.toRadians(lon); double dLatRad = Math.toRadians(dLat); double dLonRad = Math.toRadians(dLon); Sector sector = Sector.fromRadians(latRad, lonRad, dLatRad, dLonRad); assertNotNull(sector); assertEquals("minLatitude", lat, sector.minLatitude(), TOLERANCE); assertEquals("minLongitude", lon, sector.minLongitude(), TOLERANCE); assertEquals("maxLatitude", lat + dLat, sector.maxLatitude(), TOLERANCE); assertEquals("maxLongitude", lon + dLon, sector.maxLongitude(), TOLERANCE); assertEquals("deltaLatitude", dLat, sector.deltaLatitude(), TOLERANCE); assertEquals("deltaLongitude", dLon, sector.deltaLongitude(), TOLERANCE); }