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 @@
*/
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
*/
public class SimpleTile implements Tile {
/** Reference latitude. */
private double referenceLatitude;
/** Minimum latitude. */
private double minLatitude;
/** Reference longitude. */
private double referenceLongitude;
/** Minimum longitude. */
private double minLongitude;
/** Step in latitude (size of one raster element). */
private double latitudeStep;
......@@ -54,16 +54,16 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */
@Override
public void setGeometry(final double referenceLatitude, final double referenceLongitude,
final double latitudeStep, final double longitudeStep,
final int latitudeRows, final int longitudeColumns) {
this.referenceLatitude = referenceLatitude;
this.referenceLongitude = referenceLongitude;
this.latitudeStep = latitudeStep;
this.longitudeStep = longitudeStep;
this.latitudeRows = latitudeRows;
this.longitudeColumns = longitudeColumns;
this.elevations = new double[latitudeRows * longitudeColumns];
public void setGeometry(final double minLatitude, final double minLongitude,
final double latitudeStep, final double longitudeStep,
final int latitudeRows, final int longitudeColumns) {
this.minLatitude = minLatitude;
this.minLongitude = minLongitude;
this.latitudeStep = latitudeStep;
this.longitudeStep = longitudeStep;
this.latitudeRows = latitudeRows;
this.longitudeColumns = longitudeColumns;
this.elevations = new double[latitudeRows * longitudeColumns];
}
/** {@inheritDoc} */
......@@ -76,14 +76,14 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */
@Override
public double getReferenceLatitude() {
return referenceLatitude;
public double getMinimumLatitude() {
return minLatitude;
}
/** {@inheritDoc} */
@Override
public double getReferenceLongitude() {
return referenceLongitude;
public double getMinimumLongitude() {
return minLongitude;
}
/** {@inheritDoc} */
......@@ -118,6 +118,15 @@ public class SimpleTile implements Tile {
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.
* @param latitudeIndex
* @param longitudeIndex
......@@ -125,7 +134,7 @@ public class SimpleTile implements Tile {
*/
private void checkIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException {
if (latitudeIndex < 0 || latitudeIndex >= latitudeRows ||
if (latitudeIndex < 0 || latitudeIndex >= latitudeRows ||
longitudeIndex < 0 || longitudeIndex >= longitudeColumns) {
throw new IllegalArgumentException();
}
......
......@@ -23,15 +23,15 @@ import org.orekit.rugged.api.UpdatableTile;
*/
public interface Tile extends UpdatableTile {
/** Get reference latitude.
* @return reference latitude
/** Get minimum latitude.
* @return minimum latitude
*/
double getReferenceLatitude();
double getMinimumLatitude();
/** Get reference longitude.
* @return reference longitude
/** Get minimum longitude.
* @return minimum longitude
*/
double getReferenceLongitude();
double getMinimumLongitude();
/** Get step in latitude (size of one raster element).
* @return step in latitude
......@@ -62,4 +62,11 @@ public interface Tile extends UpdatableTile {
double getElevationAtIndices(int latitudeIndex, int longitudeIndex)
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 {
@Test
public void testEmpty() {
SimpleTile tile = new SimpleTile();
Assert.assertEquals(0, tile.getReferenceLatitude(), 1.0e-10);
Assert.assertEquals(0, tile.getReferenceLongitude(), 1.0e-10);
Assert.assertEquals(0, tile.getMinimumLatitude(), 1.0e-10);
Assert.assertEquals(0, tile.getMinimumLongitude(), 1.0e-10);
Assert.assertEquals(0, tile.getLatitudeStep(), 1.0e-10);
Assert.assertEquals(0, tile.getLongitudeStep(), 1.0e-10);
Assert.assertEquals(0, tile.getLatitudeRows());
......@@ -44,13 +44,18 @@ public class SimpleTileTest {
}
}
Assert.assertEquals(1.0, tile.getReferenceLatitude(), 1.0e-10);
Assert.assertEquals(2.0, tile.getReferenceLongitude(), 1.0e-10);
Assert.assertEquals(1.0, tile.getMinimumLatitude(), 1.0e-10);
Assert.assertEquals(2.0, tile.getMinimumLongitude(), 1.0e-10);
Assert.assertEquals(0.1, tile.getLatitudeStep(), 1.0e-10);
Assert.assertEquals(0.2, tile.getLongitudeStep(), 1.0e-10);
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));
for (int i = 0; i < tile.getLatitudeRows(); ++i) {
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