public boolean covers(final Rectangle bound) { boolean covers = false; for (final Polygon outer : this.boundary.outers()) { if (outer.fullyGeometricallyEncloses(bound)) { covers = true; break; } if (outer.overlaps(bound)) { covers = true; break; } } return covers; }
public Function<Shard, Optional<Atlas>> getAtlasFetcher() { // Here, make sure to not load outside the bounds. return shard -> { if (this.maximumBounds.overlaps(shard.bounds())) { try { return this.atlasFetcher.apply(shard); } catch (final Throwable error) { logger.error("Could not load shard {}, skipping.", shard.getName(), error); } } else { logger.debug( "Skipping atlasFetcher for {} because shard bounds are outside the policy's maximumBounds", shard.getName()); } return Optional.empty(); }; }
/** * Iterate through outers of country boundary to avoid unnecessary overlap checks * * @param zoom * The zoom level of slippy tiles * @return A set of slippy tiles */ public Set<SlippyTile> tiles(final int zoom) { final Set<SlippyTile> validTiles = new HashSet<>(); for (final Polygon subBoundary : this.boundary.outers()) { final List<SlippyTile> tiles = Iterables .asList(SlippyTile.allTiles(zoom, subBoundary.bounds())); validTiles.addAll(tiles.stream().filter(tile -> subBoundary.overlaps(tile.bounds())) .collect(Collectors.toList())); } return validTiles; } }
/** * @param polyLine * A {@link PolyLine} item * @return True if the {@link MultiPolygon} contains the provided {@link PolyLine}. */ @Override public boolean fullyGeometricallyEncloses(final PolyLine polyLine) { for (final Polygon outer : outers()) { if (outer.fullyGeometricallyEncloses(polyLine)) { return this.getOuterToInners().get(outer).stream() .noneMatch(inner -> inner.overlaps(polyLine)); } } return false; }
@Override public boolean overlaps(final MultiPolygon multiPolygon) { for (final Polygon outer : multiPolygon.outers()) { final List<Polygon> inners = multiPolygon.innersOf(outer); if (this.overlaps(outer)) { boolean result = true; for (final Polygon inner : inners) { if (inner.fullyGeometricallyEncloses(this)) { // The feature is fully inside an inner polygon, hence not overlapped result = false; break; } } if (result) { return true; } } } return false; }
@Override public Iterable<Edge> edgesIntersecting(final Polygon polygon) { return Iterables.stream(this.getEdgeSpatialIndex().get(polygon.bounds())).filter(edge -> { final PolyLine polyline = edge.asPolyLine(); return polygon.overlaps(polyline); }); }
@Override public Iterable<Area> areasIntersecting(final Polygon polygon) { return Iterables.stream(this.getAreaSpatialIndex().get(polygon.bounds())).filter(area -> { final Polygon areaPolygon = area.asPolygon(); return polygon.overlaps(areaPolygon); }); }
boolean areaCovered(final Area area) { final Polygon polygon = area.asPolygon(); final MultiPolygon initialShardsBounds = this.policy.getInitialShardsBounds(); if (!this.policy.isExtendIndefinitely() && !(polygon.overlaps(initialShardsBounds) || initialShardsBounds.overlaps(polygon))) { // If the policy is to not extend indefinitely, then assume that the loading is not // necessary. return true; } final Iterable<? extends Shard> neededShards = this.sharding.shards(polygon); for (final Shard neededShard : neededShards) { if (!this.loadedShards.containsKey(neededShard)) { newPolygon(polygon, area); return false; } } return true; }
@Override public Iterable<Line> linesIntersecting(final Polygon polygon) { return Iterables.stream(this.getLineSpatialIndex().get(polygon.bounds())).filter(line -> { final PolyLine polyline = line.asPolyLine(); return polygon.overlaps(polyline); }); }
for (final Polygon outer : this.outers()) if (polygon.overlaps(outer))
private void verifyOverlapExists(final Atlas atlas) { Assert.assertTrue(atlas.area(1).asPolygon().overlaps(atlas.area(2).asPolygon())); } }
/** * This function only puts the part of the multipolygon with outers intersecting with the * shard * * @param item * to add * @param collection * to add to * @param shard * shard associated with the collection * @return whether it was added successfully */ @Override protected boolean addFunction(final MultiPolygon item, final ArrayList<MultiPolygon> collection, final Shard shard) { final Rectangle shardBounds = shard.bounds(); final MultiMap<Polygon, Polygon> newMultiPolygon = new MultiMap<>(); item.outers().forEach(outer -> { if (outer.overlaps(shardBounds)) { newMultiPolygon.put(outer, item.innersOf(outer)); } }); return collection.add(new MultiPolygon(newMultiPolygon)); }
private void verifyNoOverlap(final Atlas atlas) { Assert.assertFalse(atlas.area(1).asPolygon().overlaps(atlas.area(2).asPolygon())); }
@Override public boolean overlaps(final PolyLine other) { if (other instanceof Rectangle) { final Rectangle otherRectangle = (Rectangle) other; return !(otherRectangle.lowerLeft.getLongitude() .isGreaterThan(this.upperRight.getLongitude()) || otherRectangle.upperRight.getLongitude() .isLessThan(this.lowerLeft.getLongitude()) || otherRectangle.upperRight.getLatitude() .isLessThan(this.lowerLeft.getLatitude()) || otherRectangle.lowerLeft.getLatitude() .isGreaterThan(this.upperRight.getLatitude())); } else { return super.overlaps(other); } }
Location.forString("22.648164, 50.364465")); logger.info("coveringPolygon: {}", coveringPolygon.toWkt()); Assert.assertTrue(coveringPolygon.overlaps(multiPolygon)); Location.forString("19.247746, 23.339148")); logger.info("insideInnerPolygon: {}", insideInnerPolygon.toWkt()); Assert.assertFalse(insideInnerPolygon.overlaps(multiPolygon)); Location.forString("27.156014, 30.298381")); logger.info("intersectingInnerPolygon: {}", intersectingInnerPolygon.toWkt()); Assert.assertTrue(intersectingInnerPolygon.overlaps(multiPolygon)); Location.forString("27.156014, 30.298381")); logger.info("intersectingOuterPolygon: {}", intersectingOuterPolygon.toWkt()); Assert.assertTrue(intersectingOuterPolygon.overlaps(multiPolygon));
for (final Polygon outer : outerToInners.keySet()) if (outer.overlaps(inner))