diff --git a/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java index 77bc7931288d5b7939b93138a477e463334df04a..6317f76bc624e50aca872c61d05392a45369dd06 100644 --- a/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java +++ b/rugged-core/src/main/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTile.java @@ -155,39 +155,49 @@ public class MinMaxTreeTile extends SimpleTile { } - /** Get the row at which the two sub-tiles of level+1 were merged to give current level sub-tile. + /** Get the row at which two sub-tiles at level l are merged to give one sub-tile at level l-1. + * <p> + * This method is expected to be called for levels for which {@link #isColumnMerging(int) + * isColumnMerging(level)} returns {@code false}. Calling it for other levels returns + * unspecified results. + * </p> * @param i row index of pixel in current sub-tile - * @param level tree level + * @param level tree level to be merged into a lower level * @return index of row at which higher level sub-tiles were merged - * (beware that this may be {@link #getLatitudeRows()} or more if the last row was not - * really merged because level+1 sub-tile was not complete) + * (beware that this may be {@link #getLatitudeRows()} or more if the last row is not + * really merged because only one pixel is available at this level) */ public int getMergingRow(final int i, final int level) { - final int k = start.length - level; + final int k = start.length + 1 - level; final int rowShift = k / 2; return (i & (-1 << rowShift)) + (1 << (rowShift - 1)); } - /** Get the column at which the two sub-tiles of level+1 were merged to give current level sub-tile. + /** Get the column at which two sub-tiles at level l are merged to give one sub-tile at level l-1. + * <p> + * This method is expected to be called for levels for which {@link #isColumnMerging(int) + * isColumnMerging(level)} returns {@code true}. Calling it for other levels returns + * unspecified results. + * </p> * @param j column index of pixel in current sub-tile - * @param level tree level + * @param level tree level to be merged into a lower level * @return index of column at which higher level sub-tiles were merged - * (beware that this may be {@link #getLongitudeColumns()} or more if the last columns was not - * really merged because level+1 sub-tile was not complete) + * (beware that this may be {@link #getLongitudeColumns()} or more if the last column is not + * really merged because only one pixel is available at this level) */ public int getMergingColumn(final int j, final int level) { - final int k = start.length - level; + final int k = start.length + 1 - level; final int colShift = (k + 1) / 2; return (j & (-1 << colShift)) + (1 << (colShift - 1)); } - /** Check if the merging operation between level and level+1 is a column merging. + /** Check if the merging operation between level and level-1 is a column merging. * @param level level to check - * @return true if the merging operation between level and level+1 is a column + * @return true if the merging operation between level and level-1 is a column * merging, false if is a row merging */ public boolean isColumnMerging(final int level) { - return (level & 0x1) != (start.length & 0x1); + return (level & 0x1) == (start.length & 0x1); } /** Recursive setting of tree levels. @@ -264,7 +274,7 @@ public class MinMaxTreeTile extends SimpleTile { final BivariateFunction f, final double[] base, final int first) { - if (isColumnMerging(level)) { + if (isColumnMerging(level + 1)) { // merge columns pairs int iTree = start[level]; diff --git a/rugged-core/src/test/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileTest.java b/rugged-core/src/test/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileTest.java index abfe7550e4aa0bdfa16cc06a3c038b9a72e256ff..be1e219410fc3de0d3bdd44bd0362a36827d6c22 100644 --- a/rugged-core/src/test/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileTest.java +++ b/rugged-core/src/test/java/org/orekit/rugged/core/duvenhage/MinMaxTreeTileTest.java @@ -22,8 +22,6 @@ 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.duvenhage.MinMaxTreeTile; -import org.orekit.rugged.core.duvenhage.MinMaxTreeTileFactory; public class MinMaxTreeTileTest { @@ -47,15 +45,15 @@ public class MinMaxTreeTileTest { Assert.assertEquals( 577, start[ 7]); Assert.assertEquals(1117, start[ 8]); - Assert.assertTrue(tile.isColumnMerging(8)); - Assert.assertFalse(tile.isColumnMerging(7)); - Assert.assertTrue(tile.isColumnMerging(6)); - Assert.assertFalse(tile.isColumnMerging(5)); - Assert.assertTrue(tile.isColumnMerging(4)); - Assert.assertFalse(tile.isColumnMerging(3)); - Assert.assertTrue(tile.isColumnMerging(2)); - Assert.assertFalse(tile.isColumnMerging(1)); - Assert.assertTrue(tile.isColumnMerging(0)); + Assert.assertTrue(tile.isColumnMerging(9)); + Assert.assertFalse(tile.isColumnMerging(8)); + Assert.assertTrue(tile.isColumnMerging(7)); + Assert.assertFalse(tile.isColumnMerging(6)); + Assert.assertTrue(tile.isColumnMerging(5)); + Assert.assertFalse(tile.isColumnMerging(4)); + Assert.assertTrue(tile.isColumnMerging(3)); + Assert.assertFalse(tile.isColumnMerging(2)); + Assert.assertTrue(tile.isColumnMerging(1)); Field minTreeField = MinMaxTreeTile.class.getDeclaredField("minTree"); minTreeField.setAccessible(true); @@ -81,10 +79,10 @@ public class MinMaxTreeTileTest { Assert.assertEquals( 6, start[ 2]); Assert.assertEquals(14, start[ 3]); - Assert.assertTrue(tile.isColumnMerging(3)); - Assert.assertFalse(tile.isColumnMerging(2)); - Assert.assertTrue(tile.isColumnMerging(1)); - Assert.assertFalse(tile.isColumnMerging(0)); + Assert.assertTrue(tile.isColumnMerging(4)); + Assert.assertFalse(tile.isColumnMerging(3)); + Assert.assertTrue(tile.isColumnMerging(2)); + Assert.assertFalse(tile.isColumnMerging(1)); Field minTreeField = MinMaxTreeTile.class.getDeclaredField("minTree"); minTreeField.setAccessible(true); @@ -195,14 +193,13 @@ public class MinMaxTreeTileTest { for (int i = 0; i < nbRows; i++) { for (int level = 0; level < tile.getLevels(); ++level) { - int iMerge = tile.getMergingRow(i, level); - if (iMerge < tile.getLatitudeRows()) { - int levelUp = tile.isColumnMerging(level) ? level + 2 : level + 1; - if (levelUp < tile.getLevels()) { - int[] neighbors1 = neighbors(iMerge - 1, 0, nbRows, nbColumns, tile.getLevels() - levelUp); - int[] neighbors2 = neighbors(iMerge, 0, nbRows, nbColumns, tile.getLevels() - levelUp); + if (!tile.isColumnMerging(level)) { + int iMerge = tile.getMergingRow(i, level); + if (iMerge < tile.getLatitudeRows()) { + int[] neighbors1 = neighbors(iMerge - 1, 0, nbRows, nbColumns, tile.getLevels() - level); + int[] neighbors2 = neighbors(iMerge, 0, nbRows, nbColumns, tile.getLevels() - level); Assert.assertEquals(neighbors1[1], neighbors2[0]); - } + } } } } @@ -219,14 +216,13 @@ public class MinMaxTreeTileTest { for (int j = 0; j < nbColumns; j++) { for (int level = 0; level < tile.getLevels(); ++level) { - int jMerge = tile.getMergingColumn(j, level); - if (jMerge < tile.getLongitudeColumns()) { - int levelUp = tile.isColumnMerging(level) ? level + 1 : level + 2; - if (levelUp < tile.getLevels()) { - int[] neighbors1 = neighbors(0, jMerge - 1, nbRows, nbColumns, tile.getLevels() - levelUp); - int[] neighbors2 = neighbors(0, jMerge, nbRows, nbColumns, tile.getLevels() - levelUp); + if (tile.isColumnMerging(level)) { + int jMerge = tile.getMergingColumn(j, level); + if (jMerge < tile.getLongitudeColumns()) { + int[] neighbors1 = neighbors(0, jMerge - 1, nbRows, nbColumns, tile.getLevels() - level); + int[] neighbors2 = neighbors(0, jMerge, nbRows, nbColumns, tile.getLevels() - level); Assert.assertEquals(neighbors1[3], neighbors2[2]); - } + } } } }