From b1b12bf8672826062e7f5df03a0b75dc9b63a85a Mon Sep 17 00:00:00 2001 From: Luc Maisonobe <luc@orekit.org> Date: Wed, 20 May 2015 16:44:51 +0200 Subject: [PATCH] Added a protection agains out of bounds indices. --- .../intersection/duvenhage/DuvenhageAlgorithm.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java index 474dd5f3..33c13a4a 100644 --- a/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java +++ b/src/main/java/org/orekit/rugged/intersection/duvenhage/DuvenhageAlgorithm.java @@ -286,7 +286,10 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { cN * entry.getAltitude() + cX * exit.getAltitude(), tile.getMinimumLongitude()); } - final int crossingLat = tile.getFloorLatitudeIndex(crossingGP.getLatitude()); + final int crossingLat = + FastMath.max(0, + FastMath.min(tile.getLatitudeRows() - 1, + tile.getFloorLatitudeIndex(crossingGP.getLatitude()))); // adjust indices as the crossing point is by definition between the sub-tiles final int crossingLonBefore = crossingLon - (entryLon <= exitLon ? 1 : 0); @@ -345,7 +348,10 @@ public class DuvenhageAlgorithm implements IntersectionAlgorithm { cN * entry.getAltitude() + cX * exit.getAltitude(), tile.getMinimumLongitude()); } - final int crossingLon = tile.getFloorLongitudeIndex(crossingGP.getLongitude()); + final int crossingLon = + FastMath.max(0, + FastMath.min(tile.getLongitudeColumns() - 1, + tile.getFloorLongitudeIndex(crossingGP.getLongitude()))); // adjust indices as the crossing point is by definition between the sub-tiles final int crossingLatBefore = crossingLat - (entryLat <= exitLat ? 1 : 0); -- GitLab