Skip to content
Snippets Groups Projects
Commit 734dd1ac authored by Luc Maisonobe's avatar Luc Maisonobe
Browse files

Improved identification of point location with respect to tile.

parent abf53860
No related branches found
No related tags found
No related merge requests found
......@@ -168,11 +168,34 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */
@Override
public boolean covers(final double latitude, final double longitude) {
public Location getLocation(final double latitude, final double longitude) {
final int latitudeIndex = (int) FastMath.floor((latitude - minLatitude) / latitudeStep);
final int longitudeIndex = (int) FastMath.floor((longitude - minLongitude) / longitudeStep);
return latitudeIndex >= 0 && latitudeIndex < latitudeRows &&
longitudeIndex >= 0 && longitudeIndex < longitudeColumns;
if (longitudeIndex < 0) {
if (latitudeIndex < 0) {
return Location.SOUTH_WEST;
} else if (latitudeIndex <= latitudeRows) {
return Location.WEST;
} else {
return Location.NORTH_WEST;
}
} else if (longitudeIndex <= longitudeColumns) {
if (latitudeIndex < 0) {
return Location.SOUTH;
} else if (latitudeIndex <= latitudeRows) {
return Location.IN_TILE;
} else {
return Location.NORTH;
}
} else {
if (latitudeIndex < 0) {
return Location.SOUTH_EAST;
} else if (latitudeIndex <= latitudeRows) {
return Location.EAST;
} else {
return Location.NORTH_EAST;
}
}
}
/** Check indices.
......
......@@ -24,6 +24,19 @@ import org.orekit.rugged.api.UpdatableTile;
*/
public interface Tile extends UpdatableTile {
/** Enumerate for point location with respect to tile. */
enum Location {
SOUTH_WEST,
WEST,
NORTH_WEST,
NORTH,
NORTH_EAST,
EAST,
SOUTH_EAST,
SOUTH,
IN_TILE
}
/** Hook called at the end of tile update completion.
* @exception RuggedException if something wrong occurs
* (missing data ...)
......@@ -82,8 +95,8 @@ public interface Tile extends UpdatableTile {
/** Check if a tile covers a ground point.
* @param latitude ground point latitude
* @param longitude ground point longitude
* @return true if the tile covers the ground point
* @return location of the ground point with respect to tile
*/
boolean covers(double latitude, double longitude);
Location getLocation(double latitude, double longitude);
}
......@@ -25,6 +25,7 @@ import java.util.List;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.TileUpdater;
import org.orekit.rugged.core.dem.Tile.Location;
/** Cache for Digital Elevation Model {@link Tile tiles}.
* <p>
......@@ -263,7 +264,7 @@ public class TilesCache<T extends Tile> {
if (insertionPoint < tiles.size()) {
final T tile = tiles.get(insertionPoint).getTile();
if (tile.covers(latitude, longitude)) {
if (tile.getLocation(latitude, longitude) == Location.IN_TILE) {
// we have found an existing tile
return tile;
}
......
......@@ -23,6 +23,7 @@ import org.orekit.rugged.api.RuggedMessages;
import org.orekit.rugged.core.dem.SimpleTile;
import org.orekit.rugged.core.dem.SimpleTileFactory;
import org.orekit.rugged.core.dem.Tile;
import org.orekit.rugged.core.dem.Tile.Location;
public class SimpleTileTest {
......@@ -76,12 +77,15 @@ public class SimpleTileTest {
Assert.assertEquals(100, tile.getLatitudeRows());
Assert.assertEquals(200, tile.getLongitudeColumns());
Assert.assertTrue(tile.covers( 6.0, 22.0));
Assert.assertFalse(tile.covers( 0.0, 22.0));
Assert.assertFalse(tile.covers(12.0, 22.0));
Assert.assertFalse(tile.covers( 6.0, 1.0));
Assert.assertFalse(tile.covers( 6.0, 43.0));
Assert.assertEquals(Location.SOUTH_WEST, tile.getLocation( 0.0, 1.0));
Assert.assertEquals(Location.WEST, tile.getLocation( 6.0, 1.0));
Assert.assertEquals(Location.NORTH_WEST, tile.getLocation(12.0, 1.0));
Assert.assertEquals(Location.SOUTH, tile.getLocation( 0.0, 22.0));
Assert.assertEquals(Location.IN_TILE, tile.getLocation( 6.0, 22.0));
Assert.assertEquals(Location.NORTH, tile.getLocation(12.0, 22.0));
Assert.assertEquals(Location.SOUTH_EAST, tile.getLocation( 0.0, 43.0));
Assert.assertEquals(Location.EAST, tile.getLocation( 6.0, 43.0));
Assert.assertEquals(Location.NORTH_EAST, tile.getLocation(12.0, 43.0));
for (int i = 0; i < tile.getLatitudeRows(); ++i) {
for (int j = 0; j < tile.getLongitudeColumns(); ++j) {
Assert.assertEquals(1000 * i + j, tile.getElevationAtIndices(i, j), 1.0e-10);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment