/** * @return The first {@link Location} of this {@link PolyLine} */ public Location first() { return size() > 0 ? get(0) : null; }
public Location last() { return this.points.size() > 0 ? get(size() - 1) : null; }
private static Segment candidateSegment(final List<PolyLine> candidates, final int polyLineIndex, final int segmentIndex) { return new Segment(candidates.get(polyLineIndex).get(segmentIndex), segmentIndex < candidates.get(polyLineIndex).size() - 1 ? candidates.get(polyLineIndex).get(segmentIndex + 1) : candidates.get(polyLineIndex).first()); }
public PolyLine reversed() { final List<Location> reversed = new ArrayList<>(); for (int i = this.size() - 1; i >= 0; i--) { reversed.add(this.get(i)); } return new PolyLine(reversed); }
protected Optional<Location> canAppend(final int polyLineIndex, final int segmentIndex) { // The segment index and the index of the first point of the segment in the polyline are // the same! final Location end = this.candidateSegments.get(this.candidateSegments.size() - 1).last(); final Location proposed = this.candidates.get(polyLineIndex).get(segmentIndex); final Segment candidateSegment = candidateSegment(this.candidates, polyLineIndex, segmentIndex); final boolean matchingLocations = end.equals(proposed); final boolean candidateSegmentAlreadyContained = this.candidateSegments .contains(candidateSegment); if (matchingLocations && !candidateSegmentAlreadyContained) { return Optional.of(proposed); } else { return Optional.empty(); } }
@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); }
endNode = nodesToSectionAt.getNode(polyline.get(index)); if (endNode.isPresent()) && 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 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; polyline.get(index), 0); polyLineUpToFirstNode = isReversed ? rawPolyline.reversed() : rawPolyline; ? duplicateLocations.get(currentLocation) : 1; final PolyLine rawPolylineFromLastNodeToLastLocation = polyline.between( polyline.get(startIndex), nodesToSectionAt.getOccurrence(startNode.get()) - 1, currentLocation, endOccurrence);
final Location cut = currentShape.get(currentShape.size() / 2); final PolyLine shape1 = currentShape.between(currentShape.first(), 0, cut, 0); final PolyLine shape2 = currentShape.between(cut, 0, currentShape.last(), 0);