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

Fixed computation of sub-tiles crossings.

parent ad6fcf95
No related branches found
No related tags found
No related merge requests found
...@@ -220,9 +220,11 @@ public class MinMaxTreeTile extends SimpleTile { ...@@ -220,9 +220,11 @@ public class MinMaxTreeTile extends SimpleTile {
final int rows = 1 << ((start.length - level) / 2); final int rows = 1 << ((start.length - level) / 2);
if (row1 <= row2) { if (row1 <= row2) {
return buildCrossings(rows * (row1 / rows + 1), row2, rows); final int nextMultiple = row1 + rows - (row1 % rows);
return buildCrossings(nextMultiple, row2, rows);
} else { } else {
return buildCrossings(rows * ((row1 - 1) / rows), row2, -rows); final int previousMultiple = row1 - 1 - ((row1 - 1) % rows);
return buildCrossings(previousMultiple, row2, -rows);
} }
} }
...@@ -245,9 +247,11 @@ public class MinMaxTreeTile extends SimpleTile { ...@@ -245,9 +247,11 @@ public class MinMaxTreeTile extends SimpleTile {
final int columns = 1 << ((start.length + 1 - level) / 2);; final int columns = 1 << ((start.length + 1 - level) / 2);;
if (column1 <= column2) { if (column1 <= column2) {
return buildCrossings(columns * (column1 / columns + 1), column2, columns); final int nextMultiple = column1 + columns - (column1 % columns);
return buildCrossings(nextMultiple, column2, columns);
} else { } else {
return buildCrossings(columns * ((column1 - 1) / columns), column2, -columns); final int previousMultiple = column1 - 1 - ((column1 - 1) % columns);
return buildCrossings(previousMultiple, column2, -columns);
} }
} }
...@@ -261,7 +265,8 @@ public class MinMaxTreeTile extends SimpleTile { ...@@ -261,7 +265,8 @@ public class MinMaxTreeTile extends SimpleTile {
private int[] buildCrossings(final int begin, final int end, final int step) { private int[] buildCrossings(final int begin, final int end, final int step) {
// allocate array // allocate array
final int[] crossings = new int[FastMath.max(0, (end - begin) / step)]; final int n = FastMath.max(0, (end - begin + step + ((step > 0) ? -1 : +1)) / step);
final int[] crossings = new int[n];
// fill it up // fill it up
int crossing = begin; int crossing = begin;
......
...@@ -192,34 +192,24 @@ public class MinMaxTreeTileTest { ...@@ -192,34 +192,24 @@ public class MinMaxTreeTileTest {
MinMaxTreeTile tile = createTile(nbRows, nbColumns); MinMaxTreeTile tile = createTile(nbRows, nbColumns);
for (int level = 0; level < tile.getLevels(); ++level) { for (int level = 0; level < tile.getLevels(); ++level) {
int[] neighbors = neighbors(0, 0, nbRows, nbColumns, tile.getLevels() - level);
int subTileRows = neighbors[1] - neighbors[0];
int subTileCols = neighbors[3] - neighbors[2];
for (int i1 = 0; i1 < nbRows; ++i1) { for (int i1 = 0; i1 < nbRows; ++i1) {
for (int i2 = 0; i2 < nbRows; ++i2) { for (int i2 = 0; i2 < nbRows; ++i2) {
int[] crossings = tile.getCrossedBoundaryRows(i1, i2, level); int[] crossings = tile.getCrossedBoundaryRows(i1, i2, level);
if (FastMath.abs(i2 - i1) < 2) { int[] ref = multiples(i1, i2, subTileRows);
Assert.assertEquals(0, crossings.length); Assert.assertArrayEquals(ref, crossings);
}
for (int crossed : crossings) {
Assert.assertNotEquals(i1, crossed);
Assert.assertNotEquals(i2, crossed);
int[] neighbors1 = neighbors(crossed - 1, 0, nbRows, nbColumns, tile.getLevels() - level);
int[] neighbors2 = neighbors(crossed, 0, nbRows, nbColumns, tile.getLevels() - level);
Assert.assertEquals(neighbors1[1], neighbors2[0]);
}
} }
for (int j1 = 0; j1 < nbColumns; ++j1) { }
for (int j2 = 0; j2 < nbColumns; ++j2) { for (int j1 = 0; j1 < nbColumns; ++j1) {
int[] crossings = tile.getCrossedBoundaryColumns(j1, j2, level); for (int j2 = 0; j2 < nbColumns; ++j2) {
if (FastMath.abs(j2 - j1) < 2) { int[] crossings = tile.getCrossedBoundaryColumns(j1, j2, level);
Assert.assertEquals(0, crossings.length); int[] ref = multiples(j1, j2, subTileCols);
} if (ref.length != crossings.length) {
for (int crossed : crossings) { crossings = tile.getCrossedBoundaryColumns(j1, j2, level);
Assert.assertNotEquals(j1, crossed);
Assert.assertNotEquals(j2, crossed);
int[] neighbors1 = neighbors(0, crossed - 1, nbRows, nbColumns, tile.getLevels() - level);
int[] neighbors2 = neighbors(0, crossed, nbRows, nbColumns, tile.getLevels() - level);
Assert.assertEquals(neighbors1[3], neighbors2[2]);
}
} }
Assert.assertArrayEquals(ref, crossings);
} }
} }
} }
...@@ -260,6 +250,41 @@ public class MinMaxTreeTileTest { ...@@ -260,6 +250,41 @@ public class MinMaxTreeTileTest {
} }
private int[] multiples(int k1, int k2, int n) {
// poor man identification of rows/columns crossings
// this identification is intentionally independent of the MinMaxTreeTile class,
// for testing purposes
// intentionally dumb way of counting multiples of n
int count = 0;
for (int k = FastMath.min(k1, k2) + 1; k < FastMath.max(k1, k2); ++k) {
if (k % n == 0) {
++count;
}
}
int[] multiples = new int[count];
int index = 0;
for (int k = FastMath.min(k1, k2) + 1; k < FastMath.max(k1, k2); ++k) {
if (k % n == 0) {
multiples[index++] = k;
}
}
if (k1 > k2) {
// revert the array
for (int i = 0; i < count / 2; ++i) {
int tmp = multiples[i];
multiples[i] = multiples[count - 1 - i];
multiples[count - 1 - i] = tmp;
}
}
return multiples;
}
private MinMaxTreeTile createTile(int nbRows, int nbColumns) throws RuggedException { private MinMaxTreeTile createTile(int nbRows, int nbColumns) throws RuggedException {
MinMaxTreeTile tile = new MinMaxTreeTileFactory().createTile(); MinMaxTreeTile tile = new MinMaxTreeTileFactory().createTile();
tile.setGeometry(1.0, 2.0, 0.1, 0.2, nbRows, nbColumns); tile.setGeometry(1.0, 2.0, 0.1, 0.2, nbRows, nbColumns);
......
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