/** * An edge intersecting with a building that doesn't have the proper tags is only valid if it * intersects at one single node and that node is shared with an edge that has the proper tags * and it is not enclosed in the building * * @param building * the building being processed * @param edge * the edge being examined * @return true if the intersection is valid, false otherwise */ private static boolean isValidIntersection(final Area building, final Edge edge) { final Node edgeStart = edge.start(); final Node edgeEnd = edge.end(); final Set<Location> intersections = building.asPolygon().intersections(edge.asPolyLine()); return intersections.size() == 1 && !building.asPolygon().fullyGeometricallyEncloses(edge.asPolyLine()) && (intersections.contains(edgeStart.getLocation()) || intersections.contains(edgeEnd.getLocation())); }
/** * Checks if an {@link Edge} intersects a {@link Polygon} and is either fully inside it or * intersecting at a point other than one of its {@link Node}s. * * @param polygon * {@link Polygon} to check against * @param edge * the {@link Edge} to check * @return true if some part of the {@link Edge} is inside the {@link Polygon} and doesn't just * have touching {@link Node}s. */ private boolean intersectsWithEnclosedGeometry(final Polygon polygon, final Edge edge) { final PolyLine polyline = edge.asPolyLine(); return polygon.intersections(polyline).stream() .anyMatch(intersection -> !(edge.start().getLocation().equals(intersection) || edge.end().getLocation().equals(intersection)) || polygon.fullyGeometricallyEncloses(polyline)); }
/** * Tests if this {@link Polygon} wraps (geometrically contains) a {@link Segment} * * @param segment * The {@link Segment} to test * @return True if this {@link Polygon} wraps (geometrically contains) the provided * {@link Segment} */ public boolean fullyGeometricallyEncloses(final Segment segment) { final Set<Location> intersections = this.intersections(segment); for (final Location intersection : intersections) { if (!intersection.equals(segment.start()) && !intersection.equals(segment.end())) { // This is a non-end intersection return false; } } return this.fullyGeometricallyEncloses(segment.middle()); }
@Test public void testIntersects() { final Set<Location> intersection = this.quadrant.intersections(new Segment(Location.TEST_5, new Location(Location.TEST_3.getLatitude(), Location.TEST_5.getLongitude()))); Assert.assertEquals(2, intersection.size()); final Set<Location> intersections = this.quadrant.intersections(this.rectangle); Assert.assertEquals(3, intersections.size()); Assert.assertTrue(this.quadrant.intersects(this.rectangle)); }
@Test public void testArea() { final Area area1 = this.atlas.area(45); final Area area2 = this.atlas.area(54); logger.trace(area1.toString()); logger.trace(area2.toString()); Assert.assertTrue(area1.asPolygon().intersects(area2.asPolygon())); Assert.assertEquals(Location.TEST_6, area1.asPolygon().intersections(area2.asPolygon()).iterator().next()); Assert.assertEquals("golf_course", area1.getTags().get("leisure")); Assert.assertEquals("grassland", area1.getTags().get("natural")); Assert.assertFalse(AerowayTag.get(area1).isPresent()); Assert.assertEquals(LeisureTag.GOLF_COURSE, LeisureTag.get(area1).orElseThrow(CoreException.supplier("No tag"))); Assert.assertEquals(NaturalTag.GRASSLAND, NaturalTag.get(area1).orElseThrow(CoreException.supplier("No tag"))); Assert.assertFalse(WaterTag.get(area1).isPresent()); Assert.assertFalse(AerowayTag.get(area2).isPresent()); Assert.assertEquals(LeisureTag.SWIMMING_POOL, LeisureTag.get(area2).orElseThrow(CoreException.supplier("No tag"))); Assert.assertEquals(SportTag.SWIMMING, SportTag.get(area2).orElseThrow(CoreException.supplier("No tag"))); Assert.assertFalse(NaturalTag.get(area2).isPresent()); Assert.assertFalse(WaterTag.get(area2).isPresent()); }