From 52d95636e404afc541de2422730792ec780ea28a Mon Sep 17 00:00:00 2001
From: Luc Maisonobe <luc@orekit.org>
Date: Tue, 21 Apr 2015 15:35:34 +0200
Subject: [PATCH] Avoid ArrayxIndexOutOfBoundException in cells dumps.

---
 .../duvenhage/MinMaxTreeTile.java             | 24 ++++++++++++++-----
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/orekit/rugged/intersection/duvenhage/MinMaxTreeTile.java b/src/main/java/org/orekit/rugged/intersection/duvenhage/MinMaxTreeTile.java
index cc44b6e0..1cda5b8b 100644
--- a/src/main/java/org/orekit/rugged/intersection/duvenhage/MinMaxTreeTile.java
+++ b/src/main/java/org/orekit/rugged/intersection/duvenhage/MinMaxTreeTile.java
@@ -178,9 +178,15 @@ public class MinMaxTreeTile extends SimpleTile {
             final int[] min = locateMin(i, j, level);
             final int index = min[0] * getLongitudeColumns() + min[1];
             DumpManager.dumpTileCell(this, min[0],     min[1],     raw[index]);
-            DumpManager.dumpTileCell(this, min[0] + 1, min[1],     raw[index + getLongitudeColumns()]);
-            DumpManager.dumpTileCell(this, min[0],     min[1] + 1, raw[index + 1]);
-            DumpManager.dumpTileCell(this, min[0] + 1, min[1] + 1, raw[index + getLongitudeColumns() + 1]);
+            if (index + getLongitudeColumns() < raw.length) {
+                DumpManager.dumpTileCell(this, min[0] + 1, min[1],     raw[index + getLongitudeColumns()]);
+            }
+            if (index + 1 < raw.length) {
+                DumpManager.dumpTileCell(this, min[0],     min[1] + 1, raw[index + 1]);
+            }
+            if (index + getLongitudeColumns() + 1 < raw.length) {
+                DumpManager.dumpTileCell(this, min[0] + 1, min[1] + 1, raw[index + getLongitudeColumns() + 1]);
+            }
         }
 
         return minTree[start[level] + levelI * levelC + levelJ];
@@ -232,9 +238,15 @@ public class MinMaxTreeTile extends SimpleTile {
             final int[] max = locateMax(i, j, level);
             final int index = max[0] * getLongitudeColumns() + max[1];
             DumpManager.dumpTileCell(this, max[0],     max[1],     raw[index]);
-            DumpManager.dumpTileCell(this, max[0] + 1, max[1],     raw[index + getLongitudeColumns()]);
-            DumpManager.dumpTileCell(this, max[0],     max[1] + 1, raw[index + 1]);
-            DumpManager.dumpTileCell(this, max[0] + 1, max[1] + 1, raw[index + getLongitudeColumns() + 1]);
+            if (index + getLongitudeColumns() < raw.length) {
+                DumpManager.dumpTileCell(this, max[0] + 1, max[1],     raw[index + getLongitudeColumns()]);
+            }
+            if (index + 1 < raw.length) {
+                DumpManager.dumpTileCell(this, max[0],     max[1] + 1, raw[index + 1]);
+            }
+            if (index + getLongitudeColumns() + 1 < raw.length) {
+                DumpManager.dumpTileCell(this, max[0] + 1, max[1] + 1, raw[index + getLongitudeColumns() + 1]);
+            }
         }
 
         return maxTree[start[level] + levelI * levelC + levelJ];
-- 
GitLab