| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
package uk.me.parabola.util; |
| 14 |
|
| 15 |
import static org.junit.Assert.assertFalse; |
| 16 |
|
| 17 |
import org.junit.Test; |
| 18 |
|
| 19 |
import uk.me.parabola.imgfmt.app.Coord; |
| 20 |
import uk.me.parabola.mkgmap.general.MapPoint; |
| 21 |
|
| 22 |
public class KdTreeTest { |
| 23 |
|
| 24 |
@Test |
| 25 |
public void findNextPointTest(){ |
| 26 |
KdTree<MapPoint> t = new KdTree<>( ); |
| 27 |
|
| 28 |
int [][]test = {{70,20}, {50,40}, {90,60}, {20,30}, {40,70}, {80,10}, {-10,20}, {-30,-40} } ; |
| 29 |
Coord []testCoords = new Coord[test.length]; |
| 30 |
|
| 31 |
for( int i = 0; i < test.length; i++ ) |
| 32 |
{ |
| 33 |
MapPoint p = new MapPoint(); |
| 34 |
testCoords[i] = new Coord(test[i][0],test[i][1]); |
| 35 |
p.setLocation(testCoords[i]); |
| 36 |
t.add(p); |
| 37 |
} |
| 38 |
|
| 39 |
MapPoint toFind = new MapPoint(); |
| 40 |
for (int x = -100; x < 100; x++){ |
| 41 |
for (int y = -100; y < 100; y++){ |
| 42 |
Coord co = new Coord(x,y); |
| 43 |
double minDist = Double.MAX_VALUE; |
| 44 |
|
| 45 |
for (int i = 0; i<testCoords.length; i++){ |
| 46 |
Double dist = testCoords[i].distanceInDegreesSquared(co); |
| 47 |
if (dist < minDist){ |
| 48 |
minDist = dist; |
| 49 |
} |
| 50 |
} |
| 51 |
toFind.setLocation(co); |
| 52 |
MapPoint next = t.findNextPoint(toFind); |
| 53 |
double dist = next.getLocation().distanceInDegreesSquared(co); |
| 54 |
double delta = Math.abs(dist - minDist); |
| 55 |
|
| 56 |
assertFalse("delta should be 0.0: " + delta, delta != 0.0); |
| 57 |
} |
| 58 |
} |
| 59 |
} |
| 60 |
} |