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

Added method to check ground point coverage.

parent 1bf3060f
No related branches found
No related tags found
No related merge requests found
...@@ -16,18 +16,18 @@ ...@@ -16,18 +16,18 @@
*/ */
package org.orekit.rugged.core.dem; package org.orekit.rugged.core.dem;
import org.orekit.rugged.api.UpdatableTile; import org.apache.commons.math3.util.FastMath;
/** Simple implementation of a {@link UpdatableTile}. /** Simple implementation of a {@link Tile}.
* @author Luc Maisonobe * @author Luc Maisonobe
*/ */
public class SimpleTile implements Tile { public class SimpleTile implements Tile {
/** Reference latitude. */ /** Minimum latitude. */
private double referenceLatitude; private double minLatitude;
/** Reference longitude. */ /** Minimum longitude. */
private double referenceLongitude; private double minLongitude;
/** Step in latitude (size of one raster element). */ /** Step in latitude (size of one raster element). */
private double latitudeStep; private double latitudeStep;
...@@ -54,16 +54,16 @@ public class SimpleTile implements Tile { ...@@ -54,16 +54,16 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public void setGeometry(final double referenceLatitude, final double referenceLongitude, public void setGeometry(final double minLatitude, final double minLongitude,
final double latitudeStep, final double longitudeStep, final double latitudeStep, final double longitudeStep,
final int latitudeRows, final int longitudeColumns) { final int latitudeRows, final int longitudeColumns) {
this.referenceLatitude = referenceLatitude; this.minLatitude = minLatitude;
this.referenceLongitude = referenceLongitude; this.minLongitude = minLongitude;
this.latitudeStep = latitudeStep; this.latitudeStep = latitudeStep;
this.longitudeStep = longitudeStep; this.longitudeStep = longitudeStep;
this.latitudeRows = latitudeRows; this.latitudeRows = latitudeRows;
this.longitudeColumns = longitudeColumns; this.longitudeColumns = longitudeColumns;
this.elevations = new double[latitudeRows * longitudeColumns]; this.elevations = new double[latitudeRows * longitudeColumns];
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -76,14 +76,14 @@ public class SimpleTile implements Tile { ...@@ -76,14 +76,14 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double getReferenceLatitude() { public double getMinimumLatitude() {
return referenceLatitude; return minLatitude;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public double getReferenceLongitude() { public double getMinimumLongitude() {
return referenceLongitude; return minLongitude;
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
...@@ -118,6 +118,15 @@ public class SimpleTile implements Tile { ...@@ -118,6 +118,15 @@ public class SimpleTile implements Tile {
return elevations[latitudeIndex * longitudeColumns + longitudeIndex]; return elevations[latitudeIndex * longitudeColumns + longitudeIndex];
} }
/** {@inheritDoc} */
@Override
public boolean covers(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;
}
/** Check indices. /** Check indices.
* @param latitudeIndex * @param latitudeIndex
* @param longitudeIndex * @param longitudeIndex
...@@ -125,7 +134,7 @@ public class SimpleTile implements Tile { ...@@ -125,7 +134,7 @@ public class SimpleTile implements Tile {
*/ */
private void checkIndices(int latitudeIndex, int longitudeIndex) private void checkIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException { throws IllegalArgumentException {
if (latitudeIndex < 0 || latitudeIndex >= latitudeRows || if (latitudeIndex < 0 || latitudeIndex >= latitudeRows ||
longitudeIndex < 0 || longitudeIndex >= longitudeColumns) { longitudeIndex < 0 || longitudeIndex >= longitudeColumns) {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }
......
...@@ -23,15 +23,15 @@ import org.orekit.rugged.api.UpdatableTile; ...@@ -23,15 +23,15 @@ import org.orekit.rugged.api.UpdatableTile;
*/ */
public interface Tile extends UpdatableTile { public interface Tile extends UpdatableTile {
/** Get reference latitude. /** Get minimum latitude.
* @return reference latitude * @return minimum latitude
*/ */
double getReferenceLatitude(); double getMinimumLatitude();
/** Get reference longitude. /** Get minimum longitude.
* @return reference longitude * @return minimum longitude
*/ */
double getReferenceLongitude(); double getMinimumLongitude();
/** Get step in latitude (size of one raster element). /** Get step in latitude (size of one raster element).
* @return step in latitude * @return step in latitude
...@@ -62,4 +62,11 @@ public interface Tile extends UpdatableTile { ...@@ -62,4 +62,11 @@ public interface Tile extends UpdatableTile {
double getElevationAtIndices(int latitudeIndex, int longitudeIndex) double getElevationAtIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException; throws IllegalArgumentException;
/** 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
*/
boolean covers(double latitude, double longitude);
} }
...@@ -25,8 +25,8 @@ public class SimpleTileTest { ...@@ -25,8 +25,8 @@ public class SimpleTileTest {
@Test @Test
public void testEmpty() { public void testEmpty() {
SimpleTile tile = new SimpleTile(); SimpleTile tile = new SimpleTile();
Assert.assertEquals(0, tile.getReferenceLatitude(), 1.0e-10); Assert.assertEquals(0, tile.getMinimumLatitude(), 1.0e-10);
Assert.assertEquals(0, tile.getReferenceLongitude(), 1.0e-10); Assert.assertEquals(0, tile.getMinimumLongitude(), 1.0e-10);
Assert.assertEquals(0, tile.getLatitudeStep(), 1.0e-10); Assert.assertEquals(0, tile.getLatitudeStep(), 1.0e-10);
Assert.assertEquals(0, tile.getLongitudeStep(), 1.0e-10); Assert.assertEquals(0, tile.getLongitudeStep(), 1.0e-10);
Assert.assertEquals(0, tile.getLatitudeRows()); Assert.assertEquals(0, tile.getLatitudeRows());
...@@ -44,13 +44,18 @@ public class SimpleTileTest { ...@@ -44,13 +44,18 @@ public class SimpleTileTest {
} }
} }
Assert.assertEquals(1.0, tile.getReferenceLatitude(), 1.0e-10); Assert.assertEquals(1.0, tile.getMinimumLatitude(), 1.0e-10);
Assert.assertEquals(2.0, tile.getReferenceLongitude(), 1.0e-10); Assert.assertEquals(2.0, tile.getMinimumLongitude(), 1.0e-10);
Assert.assertEquals(0.1, tile.getLatitudeStep(), 1.0e-10); Assert.assertEquals(0.1, tile.getLatitudeStep(), 1.0e-10);
Assert.assertEquals(0.2, tile.getLongitudeStep(), 1.0e-10); Assert.assertEquals(0.2, tile.getLongitudeStep(), 1.0e-10);
Assert.assertEquals(100, tile.getLatitudeRows()); Assert.assertEquals(100, tile.getLatitudeRows());
Assert.assertEquals(200, tile.getLongitudeColumns()); 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));
for (int i = 0; i < tile.getLatitudeRows(); ++i) { for (int i = 0; i < tile.getLatitudeRows(); ++i) {
for (int j = 0; j < tile.getLongitudeColumns(); ++j) { for (int j = 0; j < tile.getLongitudeColumns(); ++j) {
......
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