@SuppressWarnings("MismatchedReadAndWriteOfArray") @Test public void testGetCircleNeighbors() { final TileBoundsRTree treeForZ1 = new TileBoundsRTree(z, Arrays.asList(getTileBounds(0, z), getTileBounds(1, z))); final TileBoundsRTree treeForZ2 = new TileBoundsRTree(2.0, buildListForZ(2.0)); final TileBoundsRTree treeForZ3 = new TileBoundsRTree(3.0, buildListForZ(3.0)); final List<TileBoundsRTree> neighborTrees = Arrays.asList(treeForZ2, treeForZ3); final List<TileBounds> sourceTileBoundsList = treeForZ1.getTileBoundsList(); final Set<OrderedCanvasIdPair> neighborPairs = treeForZ1.getCircleNeighbors(sourceTileBoundsList, neighborTrees, 1.1, null, false, false, false); final String[] expectedPairs = { "z1-0,z1-1", "z1-0,z2-0", "z1-0,z2-1", "z1-0,z2-3", "z1-0,z2-4", "z1-0,z3-0", "z1-0,z3-1", "z1-0,z3-3", "z1-0,z3-4", "z1-1,z2-0", "z1-1,z2-1", "z1-1,z2-2", "z1-1,z2-3", "z1-1,z2-4", "z1-1,z2-5", "z1-1,z3-0", "z1-1,z3-1", "z1-1,z3-2", "z1-1,z3-3", "z1-1,z3-4", "z1-1,z3-5" }; Assert.assertEquals("invalid number of pairs found, pairs are " + new TreeSet<>(neighborPairs), expectedPairs.length, neighborPairs.size()); final Double explicitRadius = 1.0; final Set<OrderedCanvasIdPair> neighborPairsWithExplicitRadius = treeForZ1.getCircleNeighbors(sourceTileBoundsList, neighborTrees, 1.1, explicitRadius, false, false, false); final String[] expectedPairsForExplicitRadius = { "z1-0,z2-0", "z1-0,z3-0", "z1-1,z2-1", "z1-1,z3-1" }; Assert.assertEquals("invalid number of pairs found, pairs are " + new TreeSet<>(neighborPairsWithExplicitRadius), expectedPairsForExplicitRadius.length, neighborPairsWithExplicitRadius.size()); }
public Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList, final List<TileBoundsRTree> neighborTrees, final double neighborRadiusFactor, final Double explicitRadius, final boolean excludeCornerNeighbors, final boolean excludeSameLayerNeighbors, final boolean excludeSameSectionNeighbors) { String firstTileId = null; if (sourceTileBoundsList.size() > 0) { firstTileId = sourceTileBoundsList.get(0).getTileId(); } LOG.debug("getCircleNeighbors: entry, checking {} tiles with z {}, {} neighborTrees, firstTileId is {}", sourceTileBoundsList.size(), z, neighborTrees.size(), firstTileId); final Set<OrderedCanvasIdPair> neighborTileIdPairs = new HashSet<>(50000); double tileWidth; double tileHeight; double centerX; double centerY; double radius; Circle circle; List<TileBounds> searchResults; for (final TileBounds tileBounds : sourceTileBoundsList) { tileWidth = tileBounds.getDeltaX(); tileHeight = tileBounds.getDeltaY(); centerX = tileBounds.getMinX() + (tileWidth / 2); centerY = tileBounds.getMinY() + (tileHeight / 2); if (explicitRadius == null) { radius = Math.max(tileWidth, tileHeight) * neighborRadiusFactor; } else { radius = explicitRadius; } circle = Geometries.circle(centerX, centerY, radius); if (! excludeSameLayerNeighbors) { searchResults = findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, true)); } for (final TileBoundsRTree neighborTree : neighborTrees) { searchResults = neighborTree.findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, false)); } } LOG.debug("getCircleNeighbors: exit, returning {} pairs", neighborTileIdPairs.size()); return neighborTileIdPairs; }
TileBoundsRTree { public Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList, final List<TileBoundsRTree> neighborTrees, final double neighborRadiusFactor, final Double explicitRadius, final boolean excludeCornerNeighbors, final boolean excludeSameLayerNeighbors, final boolean excludeSameSectionNeighbors) { String firstTileId = null; if (sourceTileBoundsList.size() > 0) { firstTileId = sourceTileBoundsList.get(0).getTileId(); } LOG.debug("getCircleNeighbors: entry, checking {} tiles with z {}, {} neighborTrees, firstTileId is {}", sourceTileBoundsList.size(), z, neighborTrees.size(), firstTileId); final Set<OrderedCanvasIdPair> neighborTileIdPairs = new HashSet<>(50000); double tileWidth; double tileHeight; double centerX; double centerY; double radius; Circle circle; List<TileBounds> searchResults; for (final TileBounds tileBounds : sourceTileBoundsList) { tileWidth = tileBounds.getDeltaX(); tileHeight = tileBounds.getDeltaY(); centerX = tileBounds.getMinX() + (tileWidth / 2); centerY = tileBounds.getMinY() + (tileHeight / 2); if (explicitRadius == null) { radius = Math.max(tileWidth, tileHeight) * neighborRadiusFactor; } else { radius = explicitRadius; } circle = Geometries.circle(centerX, centerY, radius); if (! excludeSameLayerNeighbors) { searchResults = findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, true)); } for (final TileBoundsRTree neighborTree : neighborTrees) { searchResults = neighborTree.findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, false)); } } LOG.debug("getCircleNeighbors: exit, returning {} pairs", neighborTileIdPairs.size()); return neighborTileIdPairs; } }
TileBoundsRTree { public Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList, final List<TileBoundsRTree> neighborTrees, final double neighborRadiusFactor, final Double explicitRadius, final boolean excludeCornerNeighbors, final boolean excludeSameLayerNeighbors, final boolean excludeSameSectionNeighbors) { String firstTileId = null; if (sourceTileBoundsList.size() > 0) { firstTileId = sourceTileBoundsList.get(0).getTileId(); } LOG.debug("getCircleNeighbors: entry, checking {} tiles with z {}, {} neighborTrees, firstTileId is {}", sourceTileBoundsList.size(), z, neighborTrees.size(), firstTileId); final Set<OrderedCanvasIdPair> neighborTileIdPairs = new HashSet<>(50000); double tileWidth; double tileHeight; double centerX; double centerY; double radius; Circle circle; List<TileBounds> searchResults; for (final TileBounds tileBounds : sourceTileBoundsList) { tileWidth = tileBounds.getDeltaX(); tileHeight = tileBounds.getDeltaY(); centerX = tileBounds.getMinX() + (tileWidth / 2); centerY = tileBounds.getMinY() + (tileHeight / 2); if (explicitRadius == null) { radius = Math.max(tileWidth, tileHeight) * neighborRadiusFactor; } else { radius = explicitRadius; } circle = Geometries.circle(centerX, centerY, radius); if (! excludeSameLayerNeighbors) { searchResults = findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, true)); } for (final TileBoundsRTree neighborTree : neighborTrees) { searchResults = neighborTree.findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, false)); } } LOG.debug("getCircleNeighbors: exit, returning {} pairs", neighborTileIdPairs.size()); return neighborTileIdPairs; } TileBoundsRTree(final Double z,
                           final List<TileBounds> tileBoundsList); }
TileBoundsRTree { public Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList, final List<TileBoundsRTree> neighborTrees, final double neighborRadiusFactor, final Double explicitRadius, final boolean excludeCornerNeighbors, final boolean excludeSameLayerNeighbors, final boolean excludeSameSectionNeighbors) { String firstTileId = null; if (sourceTileBoundsList.size() > 0) { firstTileId = sourceTileBoundsList.get(0).getTileId(); } LOG.debug("getCircleNeighbors: entry, checking {} tiles with z {}, {} neighborTrees, firstTileId is {}", sourceTileBoundsList.size(), z, neighborTrees.size(), firstTileId); final Set<OrderedCanvasIdPair> neighborTileIdPairs = new HashSet<>(50000); double tileWidth; double tileHeight; double centerX; double centerY; double radius; Circle circle; List<TileBounds> searchResults; for (final TileBounds tileBounds : sourceTileBoundsList) { tileWidth = tileBounds.getDeltaX(); tileHeight = tileBounds.getDeltaY(); centerX = tileBounds.getMinX() + (tileWidth / 2); centerY = tileBounds.getMinY() + (tileHeight / 2); if (explicitRadius == null) { radius = Math.max(tileWidth, tileHeight) * neighborRadiusFactor; } else { radius = explicitRadius; } circle = Geometries.circle(centerX, centerY, radius); if (! excludeSameLayerNeighbors) { searchResults = findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, true)); } for (final TileBoundsRTree neighborTree : neighborTrees) { searchResults = neighborTree.findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, false)); } } LOG.debug("getCircleNeighbors: exit, returning {} pairs", neighborTileIdPairs.size()); return neighborTileIdPairs; } TileBoundsRTree(final Double z,
                           final List<TileBounds> tileBoundsList); int size(); List<TileBounds> getTileBoundsList(); void addTile(final TileBounds tileBounds); List<TileBounds> findTilesInBox(final double minX,
                                           final double minY,
                                           final double maxX,
                                           final double maxY); List<TileBounds> findCompletelyObscuredTiles(); List<TileBounds> findVisibleTiles(); List<TileBounds> findTilesNearestToBox(final double minX,
                                                  final double minY,
                                                  final double maxX,
                                                  final double maxY,
                                                  final double maxDistance,
                                                  final int maxCount); Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList,
                                                       final List<TileBoundsRTree> neighborTrees,
                                                       final double neighborRadiusFactor,
                                                       final Double explicitRadius,
                                                       final boolean excludeCornerNeighbors,
                                                       final boolean excludeSameLayerNeighbors,
                                                       final boolean excludeSameSectionNeighbors); static Set<OrderedCanvasIdPair> getDistinctPairs(final TileBounds fromTile,
                                                            final List<TileBounds> toTiles,
                                                            final boolean excludeCornerNeighbors,
                                                            final boolean excludeSameSectionNeighbors,
                                                            final boolean includeRelativePosition); }
TileBoundsRTree { public Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList, final List<TileBoundsRTree> neighborTrees, final double neighborRadiusFactor, final Double explicitRadius, final boolean excludeCornerNeighbors, final boolean excludeSameLayerNeighbors, final boolean excludeSameSectionNeighbors) { String firstTileId = null; if (sourceTileBoundsList.size() > 0) { firstTileId = sourceTileBoundsList.get(0).getTileId(); } LOG.debug("getCircleNeighbors: entry, checking {} tiles with z {}, {} neighborTrees, firstTileId is {}", sourceTileBoundsList.size(), z, neighborTrees.size(), firstTileId); final Set<OrderedCanvasIdPair> neighborTileIdPairs = new HashSet<>(50000); double tileWidth; double tileHeight; double centerX; double centerY; double radius; Circle circle; List<TileBounds> searchResults; for (final TileBounds tileBounds : sourceTileBoundsList) { tileWidth = tileBounds.getDeltaX(); tileHeight = tileBounds.getDeltaY(); centerX = tileBounds.getMinX() + (tileWidth / 2); centerY = tileBounds.getMinY() + (tileHeight / 2); if (explicitRadius == null) { radius = Math.max(tileWidth, tileHeight) * neighborRadiusFactor; } else { radius = explicitRadius; } circle = Geometries.circle(centerX, centerY, radius); if (! excludeSameLayerNeighbors) { searchResults = findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, true)); } for (final TileBoundsRTree neighborTree : neighborTrees) { searchResults = neighborTree.findTilesInCircle(circle); neighborTileIdPairs.addAll( getDistinctPairs(tileBounds, searchResults, excludeCornerNeighbors, excludeSameSectionNeighbors, false)); } } LOG.debug("getCircleNeighbors: exit, returning {} pairs", neighborTileIdPairs.size()); return neighborTileIdPairs; } TileBoundsRTree(final Double z,
                           final List<TileBounds> tileBoundsList); int size(); List<TileBounds> getTileBoundsList(); void addTile(final TileBounds tileBounds); List<TileBounds> findTilesInBox(final double minX,
                                           final double minY,
                                           final double maxX,
                                           final double maxY); List<TileBounds> findCompletelyObscuredTiles(); List<TileBounds> findVisibleTiles(); List<TileBounds> findTilesNearestToBox(final double minX,
                                                  final double minY,
                                                  final double maxX,
                                                  final double maxY,
                                                  final double maxDistance,
                                                  final int maxCount); Set<OrderedCanvasIdPair> getCircleNeighbors(final List<TileBounds> sourceTileBoundsList,
                                                       final List<TileBoundsRTree> neighborTrees,
                                                       final double neighborRadiusFactor,
                                                       final Double explicitRadius,
                                                       final boolean excludeCornerNeighbors,
                                                       final boolean excludeSameLayerNeighbors,
                                                       final boolean excludeSameSectionNeighbors); static Set<OrderedCanvasIdPair> getDistinctPairs(final TileBounds fromTile,
                                                            final List<TileBounds> toTiles,
                                                            final boolean excludeCornerNeighbors,
                                                            final boolean excludeSameSectionNeighbors,
                                                            final boolean includeRelativePosition);  }