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

Use new specialized exceptions.

parent 6a1118ea
No related branches found
No related tags found
No related merge requests found
......@@ -30,7 +30,9 @@ public interface TileUpdater {
* @param latitude latitude that must be covered by the tile
* @param longitude longitude that must be covered by the tile
* @param tile to update
* @exception RuggedException if tile cannot be updated
*/
void updateTile(double latitude, double longitude, UpdatableTile tile);
void updateTile(double latitude, double longitude, UpdatableTile tile)
throws RuggedException;
}
......@@ -37,9 +37,9 @@ public interface UpdatableTile {
* @param latitudeIndex index of latitude (row index)
* @param longitudeIndex index of longitude (column index)
* @param elevation elevation (m)
* @exception IllegalArgumentException if indices are out of bound
* @exception RuggedException if indices are out of bound
*/
void setElevation(int latitudeIndex, int longitudeIndex, double elevation)
throws IllegalArgumentException;
throws RuggedException;
}
......@@ -17,6 +17,8 @@
package org.orekit.rugged.core.dem;
import org.apache.commons.math3.util.FastMath;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.RuggedMessages;
/** Simple implementation of a {@link Tile}.
* @author Luc Maisonobe
......@@ -69,7 +71,7 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */
@Override
public void setElevation(final int latitudeIndex, final int longitudeIndex,
final double elevation) throws IllegalArgumentException {
final double elevation) throws RuggedException {
checkIndices(latitudeIndex, longitudeIndex);
elevations[latitudeIndex * longitudeColumns + longitudeIndex] = elevation;
}
......@@ -113,7 +115,7 @@ public class SimpleTile implements Tile {
/** {@inheritDoc} */
@Override
public double getElevationAtIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException {
throws RuggedException {
checkIndices(latitudeIndex, longitudeIndex);
return elevations[latitudeIndex * longitudeColumns + longitudeIndex];
}
......@@ -133,10 +135,12 @@ public class SimpleTile implements Tile {
* @exception IllegalArgumentException if indices are out of bound
*/
private void checkIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException {
throws RuggedException {
if (latitudeIndex < 0 || latitudeIndex >= latitudeRows ||
longitudeIndex < 0 || longitudeIndex >= longitudeColumns) {
throw new IllegalArgumentException();
throw new RuggedException(RuggedMessages.OUT_OF_TILE_INDICES,
latitudeIndex, longitudeIndex,
latitudeRows - 1, longitudeColumns - 1);
}
}
......
......@@ -16,6 +16,7 @@
*/
package org.orekit.rugged.core.dem;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.UpdatableTile;
/** Interface representing a raster tile.
......@@ -57,10 +58,10 @@ public interface Tile extends UpdatableTile {
* @param latitudeIndex
* @param longitudeIndex
* @return elevation
* @exception IllegalArgumentException if indices are out of bound
* @exception RuggedException if indices are out of bound
*/
double getElevationAtIndices(int latitudeIndex, int longitudeIndex)
throws IllegalArgumentException;
throws RuggedException;
/** Check if a tile covers a ground point.
* @param latitude ground point latitude
......
......@@ -23,6 +23,7 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.TileUpdater;
/** Cache for Digital Elevation Model {@link Tile tiles}.
......@@ -68,8 +69,10 @@ public class TilesCache<T extends Tile> {
* @param latitude ground point latitude
* @param longitude ground point longitude
* @return tile covering the ground point
* @exception RuggedException if newly created tile cannot be updated
*/
public T getTile(final double latitude, final double longitude) {
public T getTile(final double latitude, final double longitude)
throws RuggedException {
return getStrip(latitude, longitude).getTile(latitude, longitude);
}
......@@ -77,8 +80,10 @@ public class TilesCache<T extends Tile> {
* @param latitude latitude of the point
* @param longitude longitude of the point
* @return new tile covering the point
* @exception RuggedException if tile cannot be updated
*/
private T createTile(final double latitude, final double longitude) {
private T createTile(final double latitude, final double longitude)
throws RuggedException {
if (evictionCache[next] != null) {
// the tile we are creating will evict this older tile
......@@ -106,8 +111,10 @@ public class TilesCache<T extends Tile> {
* @param latitude ground point latitude
* @param longitude ground point longitude
* @return strip covering the ground point
* @exception RuggedException if tile cannot be updated
*/
private TilesStrip getStrip(final double latitude, final double longitude) {
private TilesStrip getStrip(final double latitude, final double longitude)
throws RuggedException {
// look for a strip at the specified latitude
final int index = Collections.binarySearch(searchCache, new BasicLatitudeProvider(latitude),
......@@ -238,8 +245,10 @@ public class TilesCache<T extends Tile> {
* @param latitude ground point latitude
* @param longitude ground point longitude
* @return strip covering the ground point
* @exception RuggedException if tile cannot be updated
*/
public T getTile(final double latitude, final double longitude) {
public T getTile(final double latitude, final double longitude)
throws RuggedException {
// look for a tile at the specified longitude
final int index = Collections.binarySearch(tiles, new BasicLongitudeProvider(longitude),
......
......@@ -17,6 +17,7 @@
package orekit.rugged.core.dem;
import org.apache.commons.math3.util.FastMath;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.TileUpdater;
import org.orekit.rugged.api.UpdatableTile;
......@@ -32,7 +33,8 @@ public class ConstantElevationUpdater implements TileUpdater {
this.elevation = elevation;
}
public void updateTile(double latitude, double longitude, UpdatableTile tile) {
public void updateTile(double latitude, double longitude, UpdatableTile tile)
throws RuggedException {
tile.setGeometry(size * FastMath.floor(latitude / size),
size * FastMath.floor(longitude / size),
size / n, size / n, n, n);
......
......@@ -18,7 +18,10 @@ package orekit.rugged.core.dem;
import org.junit.Assert;
import org.junit.Test;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.api.RuggedMessages;
import org.orekit.rugged.core.dem.SimpleTile;
import org.orekit.rugged.core.dem.Tile;
public class SimpleTileTest {
......@@ -34,7 +37,7 @@ public class SimpleTileTest {
}
@Test
public void testUpdate() {
public void testUpdate() throws RuggedException {
SimpleTile tile = new SimpleTile();
tile.setGeometry(1.0, 2.0, 0.1, 0.2, 100, 200);
......@@ -65,4 +68,28 @@ public class SimpleTileTest {
}
@Test
public void testOutOfBounds() throws RuggedException {
SimpleTile tile = new SimpleTile();
tile.setGeometry(1.0, 2.0, 0.1, 0.2, 100, 200);
tile.setElevation(50, 100, 1000.0);
checkOutOfBound( -1, 100, tile);
checkOutOfBound(100, 100, tile);
checkOutOfBound( 50, -1, tile);
checkOutOfBound( 50, 200, tile);
}
private void checkOutOfBound(int i, int j, Tile tile) {
try {
tile.setElevation(i, j, 1000.0);
} catch (RuggedException re) {
Assert.assertEquals(RuggedMessages.OUT_OF_TILE_INDICES, re.getSpecifier());
Assert.assertEquals(i, ((Integer) re.getParts()[0]).intValue());
Assert.assertEquals(j, ((Integer) re.getParts()[1]).intValue());
Assert.assertEquals(tile.getLatitudeRows() - 1, ((Integer) re.getParts()[2]).intValue());
Assert.assertEquals(tile.getLongitudeColumns() - 1, ((Integer) re.getParts()[3]).intValue());
}
}
}
......@@ -21,13 +21,14 @@ import org.apache.commons.math3.random.Well19937a;
import org.apache.commons.math3.util.FastMath;
import org.junit.Assert;
import org.junit.Test;
import org.orekit.rugged.api.RuggedException;
import org.orekit.rugged.core.dem.SimpleTile;
import org.orekit.rugged.core.dem.TilesCache;
public class TilesCacheTest {
@Test
public void testSingleTile() {
public void testSingleTile() throws RuggedException {
CountingFactory factory = new CountingFactory();
TilesCache<SimpleTile> cache = new TilesCache<SimpleTile>(factory,
new ConstantElevationUpdater(FastMath.toRadians(3.0), 10, 10.0), 1000);
......@@ -40,7 +41,7 @@ public class TilesCacheTest {
}
@Test
public void testEviction() {
public void testEviction() throws RuggedException {
CountingFactory factory = new CountingFactory();
TilesCache<SimpleTile> cache = new TilesCache<SimpleTile>(factory,
new ConstantElevationUpdater(FastMath.toRadians(1.0), 10, 10.0), 12);
......@@ -85,7 +86,7 @@ public class TilesCacheTest {
}
@Test
public void testExactEnd() {
public void testExactEnd() throws RuggedException {
CountingFactory factory = new CountingFactory();
TilesCache<SimpleTile> cache =
new TilesCache<SimpleTile>(factory,
......@@ -109,7 +110,7 @@ public class TilesCacheTest {
}
@Test
public void testNonContiguousFill() {
public void testNonContiguousFill() throws RuggedException {
CountingFactory factory = new CountingFactory();
TilesCache<SimpleTile> cache =
new TilesCache<SimpleTile>(factory,
......
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