@Override public Rectangle bounds() { return this.polyLine.bounds(); }
@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\"?"); }
@Override public PolyLine asPolyLine() { final PolyLine one = this.upstream.asPolyLine(); final PolyLine two = this.downstream.asPolyLine(); final List<Location> points = new ArrayList<>(); one.forEach(points::add); for (int i = 1; i < two.size(); i++) { points.add(two.get(i)); } return new PolyLine(points); }
private PolyLineRoute(final PolyLine source, final List<PolyLine> candidates, final List<Segment> candidateSegments) { this.candidateSegments = candidateSegments; this.source = source; this.candidates = candidates; this.cost = this.source.averageOneWayDistanceTo(this.asPolyLine()) .add(this.asPolyLine().size() > 2 ? new PolyLine(this.asPolyLine().innerLocations()) .averageOneWayDistanceTo(this.source) : Distance.ZERO); }
final Set<Location> selfIntersections = polyLine.selfIntersections(); && polyLine.withoutDuplicateConsecutiveShapePoints().occurrences( polyLine.first()) < MINIMUM_NUMBER_OF_SELF_INTERSECTIONS_FOR_A_NODE) selfIntersections.remove(polyLine.first()); for (int index = 0; index < polyLine.size(); index++) final Location shapePoint = polyLine.get(index); addPointToNodeList(polyLine.first(), nodesForEdge); addPointToNodeList(polyLine.get(polyLine.size() / 2), nodesForEdge); addPointToNodeList(polyLine.first(), nodesForEdge); addPointToNodeList(polyLine.last(), nodesForEdge);
private PolyLine convertPolyLine(final Loc[] points) { return new PolyLine(pointsToLocations(points)); }
if (polyline.size() < MINIMUM_POINTS_TO_QUALIFY_AS_A_LINE) startNode = nodesToSectionAt.getNode(polyline.first()); duplicateLocations.put(polyline.first(), 1); for (int index = 1; index < polyline.size(); index++) final Location currentLocation = polyline.get(index); endNode = nodesToSectionAt.getNode(currentLocation); && polyline.get(index).equals(polyline.get(index - 1))) final PolyLine rawPolyline = polyline.between(polyline.get(startIndex), startOccurrence, polyline.get(index), endOccurrence); final PolyLine edgePolyline = isReversed ? rawPolyline.reversed() : rawPolyline; final PolyLine rawPolyline = polyline.between(polyline.first(), 0, polyline.get(index), 0); polyLineUpToFirstNode = isReversed ? rawPolyline.reversed() : rawPolyline; isFirstNode = false; if (index == polyline.size() - 1) final PolyLine rawPolylineFromLastNodeToLastLocation = polyline.between( polyline.get(startIndex), nodesToSectionAt.getOccurrence(startNode.get()) - 1,
@Test public void testSelfIntersectsNoIntersections() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1)"); Assert.assertFalse(polyLine.selfIntersects()); Assert.assertEquals(0, polyLine.selfIntersections().size()); }
/** * @return Feature change 1: Update the first location in the edge 39001000001L's polyLine */ private Tuple<FeatureChange, FeatureChange> getFeatureChangeUpdatedEdgePolyLine() { final Atlas atlas = this.rule.getAtlasEdge(); final Edge originalEdge1 = atlas.edge(39001000001L); final Edge originalEdge1Reverse = atlas.edge(-39001000001L); // Forward: final PolyLine originalPolyLine1 = originalEdge1.asPolyLine(); final PolyLine originalPolyLine1Modified = new PolyLine( originalPolyLine1.prepend(new PolyLine(NEW_LOCATION, originalPolyLine1.first()))); final CompleteEdge bloatedEdge1 = CompleteEdge.shallowFrom(originalEdge1) .withPolyLine(originalPolyLine1Modified); final FeatureChange featureChange1 = new FeatureChange(ChangeType.ADD, bloatedEdge1); // Backward final PolyLine originalPolyLine1Reverse = originalEdge1Reverse.asPolyLine(); final PolyLine originalPolyLine1ModifiedReverse = new PolyLine(originalPolyLine1Reverse .append(new PolyLine(originalPolyLine1Reverse.last(), NEW_LOCATION))); final CompleteEdge bloatedEdge1Reverse = CompleteEdge.shallowFrom(originalEdge1Reverse) .withPolyLine(originalPolyLine1ModifiedReverse); final FeatureChange featureChange1Reverse = new FeatureChange(ChangeType.ADD, bloatedEdge1Reverse); return new Tuple<>(featureChange1, featureChange1Reverse); } }
final PolyLine edgePoly = edge.asPolyLine(); final Rectangle bounds = edge.asPolyLine().bounds(); || edgeInBounds.asPolyLine().length().equals(ZERO_DISTANCE) || this.isFlagged(edgeInBounds.getIdentifier()) || edge.getIdentifier() == edgeInBounds.getIdentifier()) final PolyLine longerEdge = (edgePoly.length().isGreaterThan(edgeInBoundsPoly.length())) ? edgePoly : edgeInBoundsPoly; final PolyLine subsetEdge = (longerEdge == edgePoly) ? edgeInBoundsPoly : edgePoly; if (longerEdge.overlapsShapeOf(subsetEdge))
@Override public Iterable<? extends Shard> shardsIntersecting(final PolyLine polyLine) { return Iterables.stream(SlippyTile.allTiles(this.zoom, polyLine.bounds())) .filter(slippyTile -> polyLine.intersects(slippyTile.bounds()) || slippyTile.bounds().fullyGeometricallyEncloses(polyLine)); }
@Test public void testAppend() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final PolyLine line2 = new PolyLine(Location.TEST_1, Location.TEST_7); final PolyLine appended = line.append(line2); Assert.assertTrue(appended.equalsShape( new PolyLine(Location.CROSSING_85_280, Location.TEST_1, Location.TEST_7))); }
&& isAtlasEdge(target) && target.asPolyLine().contains(location))) final boolean edgesOnDifferentLayers = targetLayerValue != layerValue; final PolyLine candidatePolyline = candidate.asPolyLine(); final boolean intersectionIsAtEndPoint = candidatePolyline.first() .equals(location) || candidatePolyline.last().equals(location);
@Test public void testNoAnglesMatchingOurCriteria() { final PolyLine polyLine = new PolyLine(this.quadrant); // Find all angles greater than or equal to 140 degrees. final List<Tuple<Angle, Location>> result = polyLine .anglesGreaterThanOrEqualTo(Angle.degrees(179)); Assert.assertTrue(result.size() == 0); }
@Test public void testInnerLocations() { final PolyLine source = new PolyLine(Location.CROSSING_85_280, Location.TEST_7, Location.TEST_1); Assert.assertTrue("Make sure there is a single inner location", source.innerLocations().iterator().next().equals(Location.TEST_7)); }