@Override public final boolean contains(final Object object) { if (object instanceof Location) { return contains((Location) object); } if (object instanceof Segment) { return contains((Segment) object); } throw new IllegalAccessError( "A polyline can contain a Segment or Location only. Maybe you meant \"covers\"?"); }
/** * Checks whether given {@link PolyLine}s can cross each other. * * @param edgeAsPolyLine * {@link PolyLine} being crossed * @param edgeLayer * {@link Optional} layer value for edge being crossed * @param crossingEdgeAsPolyLine * Crossing {@link PolyLine} * @param crossingEdgeLayer * {@link Optional} layer value for crossing edge * @param intersection * Intersection {@link Location} * @return {@code true} if given {@link PolyLine}s can cross each other */ private static boolean canCross(final PolyLine edgeAsPolyLine, final Optional<Long> edgeLayer, final PolyLine crossingEdgeAsPolyLine, final Optional<Long> crossingEdgeLayer, final Location intersection) { // If crossing edges have nodes at intersections points, then crossing is valid return edgeAsPolyLine.contains(intersection) && crossingEdgeAsPolyLine.contains(intersection) // Otherwise, if crossing edges has valid, but different tag values // Then that is still a valid crossing || edgeLayer.isPresent() && crossingEdgeLayer.isPresent() && !edgeLayer.get().equals(crossingEdgeLayer.get()); }
@Override public Iterable<Edge> edgesContaining(final Location location) { return Iterables.stream(this.getEdgeSpatialIndex().get(location.bounds())).filter(edge -> { final PolyLine polyline = edge.asPolyLine(); return polyline.contains(location); }); }
@Override public Iterable<Line> linesContaining(final Location location) { return Iterables.stream(this.getLineSpatialIndex().get(location.bounds())).filter(line -> { final PolyLine polyline = line.asPolyLine(); return polyline.contains(location); }); }
@Test public void testContains() { final PolyLine line = PolyLine .wkt("LINESTRING (10.5553105 48.3419094, 10.5552096 48.3417501, 10.5551312 48.3416583, " + "10.5551027 48.341611, 10.5550183 48.3415143, 10.5549357 48.3414668, " + "10.5548325 48.3414164, 10.5548105 48.3415201, 10.5548015 48.3415686, " + "10.5548925 48.3416166, 10.5550334 48.3416375, 10.5551312 48.3416583)"); Assert.assertTrue("Verifying PolyLine contains Location", line.contains(Location.forString("48.3419094, 10.5553105"))); Assert.assertFalse("Verifying PolyLine doesn't contain Location", line.contains(Location.COLOSSEUM)); Assert.assertTrue("Verifying PolyLine contains Segment", line.contains(new Segment(Location.forString("48.3419094, 10.5553105"), Location.forString("48.3417501, 10.5552096")))); Assert.assertFalse("Verifying PolyLine doesn't contain Segment", line.contains(new Segment(Location.TEST_2, Location.COLOSSEUM))); }
/** * Determines whether the given {@link Line} has any intersecting {@link Line}s, with the same * layer tag value that meet the definition of an {@link Edge}, running through it at the given * {@link Location}. * * @param location * The {@link Location} to use * @param line * The {@link Line} to use * @return {@code true} if there is at least one {@link Edge} with the same layer tag value * intersecting the given line at the given location */ private boolean locationIsPartOfAnIntersectingEdgeOfTheSameLayer(final Location location, final Line line) { final long targetLayerValue = LayerTag.getTaggedOrImpliedValue(line, 0L); return Iterables // Find all intersecting edges .stream(this.rawAtlas.linesContaining(location, target -> target.getIdentifier() != line.getIdentifier() && isAtlasEdge(target) && target.asPolyLine().contains(location))) // Check whether that edge has the same layer value as the line we're looking at .anyMatch(candidate -> { final long layerValue = LayerTag.getTaggedOrImpliedValue(candidate, 0L); return targetLayerValue == layerValue; }); }
&& isAtlasEdge(target) && target.asPolyLine().contains(location)))