private boolean hasPerfectMatch(final Edge edge, final Iterable<Edge> otherEdges) { if (this.withGeometryMatching) { final PolyLine source = edge.asPolyLine(); final List<PolyLine> candidates = Iterables.stream(otherEdges).map(Edge::asPolyLine) .collectToList(); final Optional<PolyLineRoute> match = source.costDistanceToOneWay(candidates) .match(Distance.ZERO); if (match.isPresent() && match.get().getCost().isLessThanOrEqualTo(Distance.ZERO)) { // The edge was probably split by way sectioning without changing itself. logger.trace("Edge {} from {} has no equal member but found a match with no cost.", edge, edge.getAtlas().getName()); return true; } } return false; } }
@Test public void testMatch() { final PolyLine source = new PolyLine(Location.CROSSING_85_280, Location.TEST_2, Location.TEST_1); final PolyLine candidate1 = new PolyLine(Location.CROSSING_85_280, Location.TEST_2, Location.TEST_5); final PolyLine candidate2 = new PolyLine(Location.CROSSING_85_17, Location.TEST_2, Location.TEST_1); final List<PolyLine> candidates = Iterables .asList(Iterables.iterable(candidate1, candidate2)); final PolyLineRoute route = source.costDistanceToOneWay(candidates) .match(Distance.ZERO, Duration.ONE_MINUTE) .orElseThrow(() -> new CoreException("Did not find a route!")); logger.info("{}", route); Assert.assertEquals(3, route.asPolyLine().size()); } }