BasicTerrain implements Terrain { @Override public boolean surfacePoint(double latitude, double longitude, Vec3 result) { if (result == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BasicTerrain", "surfacePoint", "missingResult")); } for (int idx = 0, len = this.tiles.size(); idx < len; idx++) { TerrainTile tile = this.tiles.get(idx); Sector sector = tile.sector; if (sector.contains(latitude, longitude)) { int tileWidth = tile.level.tileWidth; int tileHeight = tile.level.tileHeight; 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; int si = (s < tileWidth - 1) ? (int) (s + 1) : (tileWidth - 1); int ti = (t < tileHeight - 1) ? (int) (t + 1) : (tileHeight - 1); int tileRowStride = tileWidth + 2; int i00 = (si + ti * tileRowStride) * 3; int i10 = i00 + 3; int i01 = (si + (ti + 1) * tileRowStride) * 3; int i11 = i01 + 3; double f00 = (1 - sf) * (1 - tf); double f10 = sf * (1 - tf); double f01 = (1 - sf) * tf; double f11 = sf * tf; float[] points = tile.points; result.x = (points[i00] * f00) + (points[i10] * f10) + (points[i01] * f01) + (points[i11] * f11); result.y = (points[i00 + 1] * f00) + (points[i10 + 1] * f10) + (points[i01 + 1] * f01) + (points[i11 + 1] * f11); result.z = (points[i00 + 2] * f00) + (points[i10 + 2] * f10) + (points[i01 + 2] * f01) + (points[i11 + 2] * f11); result.x += tile.origin.x; result.y += tile.origin.y; result.z += tile.origin.z; return true; } } return false; } BasicTerrain(); void addTile(TerrainTile tile); void clear(); void setTriStripElements(short[] elements); @Override Sector getSector(); @Override boolean intersect(Line line, Vec3 result); @Override boolean surfacePoint(double latitude, double longitude, Vec3 result);  }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NorthwestCorner() throws Exception { double lat = 1.0; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Northwest corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northwest corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northwest corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northwest corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NortheastCorner() throws Exception { double lat = 1.0; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Northeast corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northeast corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northeast corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northeast corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthEdge() throws Exception { double lat = 0.0; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint South edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint South edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint South edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint South edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NorthEdge() throws Exception { double lat = 1.0; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint North edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint North edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint North edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint North edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_WestEdge() throws Exception { double lat = 0.5; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint West edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint West edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint West edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint West edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_EastEdge() throws Exception { double lat = 0.5; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint East edge x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint East edge y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint East edge z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint East edge return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthwestCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.0, 0.0, 0.0); Vec3 se = officialWgs84Ecef(0.0, 0.25, 0.0); Vec3 nw = officialWgs84Ecef(0.25, 0.0, 0.0); Vec3 ne = officialWgs84Ecef(0.25, 0.25, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.125, 0.125, actual); assertEquals("surfacePoint Southwest cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southwest cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southwest cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southwest cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SoutheastCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.0, 0.75, 0.0); Vec3 se = officialWgs84Ecef(0.0, 1.0, 0.0); Vec3 nw = officialWgs84Ecef(0.25, 0.75, 0.0); Vec3 ne = officialWgs84Ecef(0.25, 1.0, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.125, 0.875, actual); assertEquals("surfacePoint Southeast cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southeast cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southeast cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southeast cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NorthwestCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.75, 0.0, 0.0); Vec3 se = officialWgs84Ecef(0.75, 0.25, 0.0); Vec3 nw = officialWgs84Ecef(1.0, 0.0, 0.0); Vec3 ne = officialWgs84Ecef(1.0, 0.25, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.875, 0.125, actual); assertEquals("surfacePoint Northwest cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northwest cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northwest cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northwest cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_NortheastCell() throws Exception { Vec3 sw = officialWgs84Ecef(0.75, 0.75, 0.0); Vec3 se = officialWgs84Ecef(0.75, 1.0, 0.0); Vec3 nw = officialWgs84Ecef(1.0, 0.75, 0.0); Vec3 ne = officialWgs84Ecef(1.0, 1.0, 0.0); Vec3 expected = worldWindEcef(bilinearCentroid(sw, se, nw, ne)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(0.875, 0.875, actual); assertEquals("surfacePoint Northeast cell x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Northeast cell y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Northeast cell z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Northeast cell return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_Centroid() throws Exception { double lat = 0.5; double lon = 0.5; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint centroid x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint centroid y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint centroid z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint centroid return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SouthwestCorner() throws Exception { double lat = 0.0; double lon = 0.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Southwest corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southwest corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southwest corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southwest corner return", expectedReturn, actualReturn); }
@SuppressWarnings("ConstantConditions") @Test public void testSurfacePoint_SoutheastCorner() throws Exception { double lat = 0.0; double lon = 1.0; double alt = 0.0; Vec3 expected = worldWindEcef(officialWgs84Ecef(lat, lon, alt)); boolean expectedReturn = true; Vec3 actual = new Vec3(); boolean actualReturn = this.terrain.surfacePoint(lat, lon, actual); assertEquals("surfacePoint Southeast corner x", expected.x, actual.x, TOLERANCE); assertEquals("surfacePoint Southeast corner y", expected.y, actual.y, TOLERANCE); assertEquals("surfacePoint Southeast corner z", expected.z, actual.z, TOLERANCE); assertEquals("surfacePoint Southeast corner return", expectedReturn, actualReturn); }