/** * @param location * The {@link Location} to test * @return True if one of the vertices of this {@link PolyLine} is the provided {@link Location} */ public boolean contains(final Location location) { for (final Location thisLocation : this) { if (thisLocation.equals(location)) { return true; } } return false; }
/** * @return True if this {@link PolyLine} is a single point, i.e. all the points are the same. */ public boolean isPoint() { Location firstPoint = null; for (final Location point : this.points) { if (firstPoint == null) { firstPoint = point; continue; } if (!point.equals(firstPoint)) { return false; } } return true; }
/** * Simple algorithm for checking if the polyline has consecutive identical shapepoints by * comparing the current point with the previous one * * @return true if there is a least one overlapping point, false otherwise */ boolean hasDuplicatePoints() { Location previous = null; for (final Location location : this.polyline) { if (location.equals(previous)) { return true; } previous = location; } return false; } }
public boolean nodesContain(final Location location) { return this.nodes.stream().filter(node -> node.getLocation().equals(location)).count() > 0; }
PossiblePolygon(final PolyLine first) { this.completed = first instanceof Polygon || first.first().equals(first.last()); this.polyLines.add(first); }
@Override public boolean equals(final Object other) { if (other instanceof SnappedLocation) { return this.origin.equals(((SnappedLocation) other).getOrigin()) && this.target.equals(((SnappedLocation) other).getTarget()); } if (other instanceof Location) { return super.equals(other); } return false; }
/** * Get the {@link TemporaryNode} at this {@link Location}. * * @param location * The target {@link Location} * @return an {@link Optional} containing the {@link TemporaryNode} */ public Optional<TemporaryNode> getNode(final Location location) { for (final TemporaryNode node : this.getNodes()) { if (node.getLocation().equals(location)) { return Optional.of(node); } } return Optional.empty(); }
@Override public boolean isPoint() { return start().equals(end()); }
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(); } }
/** * Convenience method to gather all {@link Location}s for a list of segments. * * @param segments * target segments * @return a list of {@link Location}s for the given segments */ public static List<Location> asList(final Iterable<Segment> segments) { final List<Location> result = new ArrayList<>(); Iterables.stream(segments).forEach(segment -> { if (result.isEmpty() || !result.get(result.size() - 1).equals(segment.start())) { result.add(segment.start()); } result.add(segment.end()); }); return result; }
/** * Check if this {@link LineItem} is closed. Closed is defined when the first {@link Location} * is the same as the last {@link Location}. * * @return {@code true} if it's closed. */ public boolean isClosed() { final PolyLine polyLine = asPolyLine(); return polyLine.first().equals(polyLine.last()); }
private boolean differentPoints(final Point basePoint, final Point alterPoint) { try { if (!basePoint.getLocation().equals(alterPoint.getLocation())) { return true; } return false; } catch (final Exception e) { throw new CoreException("Unable to compare points {} and {}", basePoint, alterPoint, e); } }
@Override public boolean equals(final Object other) { if (other instanceof TemporaryOrderedLocation) { final TemporaryOrderedLocation that = (TemporaryOrderedLocation) other; return this.getLocation().equals(that.getLocation()) && this.offset.equals(that.offset) && this.occurrenceIndex == that.getOccurrenceIndex(); } return false; }
@Override public boolean equals(final Object other) { if (other instanceof TemporaryOrderedNode) { final TemporaryOrderedNode that = (TemporaryOrderedNode) other; return this.node.getLocation().equals(that.node.getLocation()) && this.offset.equals(that.offset) && this.occurrenceIndex == that.getOccurrenceIndex(); } return false; }
@Override public boolean equals(final Object other) { if (other instanceof TemporaryNode) { final TemporaryNode that = (TemporaryNode) other; return this.getIdentifier() == that.getIdentifier() && this.getLocation().equals(that.getLocation()); } return false; }
/** * @return An iterable of {@link Location}s that will return the first item again at the end. */ public Iterable<Location> closedLoop() { if (!this.first().equals(this.last())) { return new MultiIterable<>(this, Iterables.from(this.first())); } return this; }
@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)); }
/** * Append the given {@link PolyLine} to this one, if possible. * * @param other * The {@link PolyLine} to append * @return the new, combined {@link PolyLine} */ public PolyLine append(final PolyLine other) { if (this.last().equals(other.first())) { return new PolyLine(new MultiIterable<>(this, other.truncate(1, 0))); } else { throw new CoreException( "Cannot append {} to {} - the end and start points do not match.", other.toWkt(), this.toWkt()); } }
private boolean canAddEdgeToBoundary(final Edge edge, final Route boundary) { return edge.getIdentifier() != -boundary.end().getIdentifier() && edge.getOsmIdentifier() == boundary.end().getOsmIdentifier() && boundary.end().end().getLocation().equals(edge.start().getLocation()) && !boundary.includes(edge); } }