|
| 1 | +package geoscript.index |
| 2 | + |
| 3 | +import geoscript.geom.Bounds |
| 4 | +import geoscript.geom.Point |
| 5 | +import org.junit.Test |
| 6 | + |
| 7 | +import static org.junit.Assert.assertEquals |
| 8 | +import static org.junit.Assert.assertTrue |
| 9 | + |
| 10 | +/** |
| 11 | + * The HPRtreeTestCase |
| 12 | + */ |
| 13 | +class HPRtreeTestCase { |
| 14 | + |
| 15 | + @Test void index() { |
| 16 | + |
| 17 | + def spatialIndex = new HPRtree() |
| 18 | + spatialIndex.insert(new Bounds(0,0,10,10), new Point(5,5)) |
| 19 | + spatialIndex.insert(new Bounds(2,2,6,6), new Point(4,4)) |
| 20 | + spatialIndex.insert(new Bounds(20,20,60,60), new Point(30,30)) |
| 21 | + spatialIndex.insert(new Bounds(22,22,44,44), new Point(32,32)) |
| 22 | + |
| 23 | + assertEquals 4, spatialIndex.size |
| 24 | + |
| 25 | + def results = spatialIndex.query(new Bounds(1,1,5,5)) |
| 26 | + assertEquals 2, results.size() |
| 27 | + assertTrue(results[0].toString() == 'POINT (4 4)' || results[0].toString() == 'POINT (5 5)') |
| 28 | + assertTrue(results[1].toString() == 'POINT (4 4)' || results[1].toString() == 'POINT (5 5)') |
| 29 | + |
| 30 | + results = spatialIndex.query(new Bounds(25,25,50,55)) |
| 31 | + assertEquals 2, results.size() |
| 32 | + assertTrue(results[0].toString() == 'POINT (30 30)' || results[0].toString() == 'POINT (32 32)') |
| 33 | + assertTrue(results[1].toString() == 'POINT (30 30)' || results[1].toString() == 'POINT (32 32)') |
| 34 | + } |
| 35 | +} |
| 36 | + |
0 commit comments