/** * @return All the locations in this {@link PolyLine} except the first and last. */ public Iterable<Location> innerLocations() { return this.truncate(1, 1); }
private void createEdgeFromRemainingPolyline(final Line line, final int startIndex, final boolean isReversed, final boolean hasReverseEdge, final WaySectionIdentifierFactory identifierFactory, final List<TemporaryEdge> newEdgesForLine) { // If we have a single way-section identifier left to use, we're going to run out // identifiers if we continue sectioning. At this point, take the rest of the // un-sectioned polyline and add it as the 999th edge. final PolyLine polyline = line.asPolyLine(); final PolyLine rawPolyLine = new PolyLine(polyline.truncate(startIndex, 0)); final PolyLine edgePolyLine = isReversed ? rawPolyLine.reversed() : rawPolyLine; final long edgeIdentifier = identifierFactory.nextIdentifier(); // Update the tags to indicate this edge wasn't way-sectioned final Map<String, String> tags = line.getTags(); tags.put(SyntheticInvalidWaySectionTag.KEY, SyntheticInvalidWaySectionTag.YES.toString()); // Add the edge newEdgesForLine.add(new TemporaryEdge(edgeIdentifier, edgePolyLine, tags, hasReverseEdge)); }
public PolyLine shiftLastAlongGreatCircle(final Heading initialHeading, final Distance distance) { return new PolyLine(new MultiIterable<>(this.truncate(0, 1), Iterables.from(this.last().shiftAlongGreatCircle(initialHeading, distance)))); }
public PolyLine shiftFirstAlongGreatCircle(final Heading initialHeading, final Distance distance) { return new PolyLine(new MultiIterable<>( Iterables.from(this.first().shiftAlongGreatCircle(initialHeading, distance)), this.truncate(1, 0))); }
@Test public void testTruncatingWithInvalidIndex() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(-1, 1); Assert.assertTrue("Make sure truncated is empty", Iterables.isEmpty(truncated)); }
@Test public void testTruncatingWithStartAndEndCombinedEqualToPolyLineSize() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(1, 1); Assert.assertTrue("Make sure truncated is empty", Iterables.isEmpty(truncated)); }
@Test public void testTruncatingWithStartIndexEqualToPolyLineSize() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(2, 0); Assert.assertTrue("Make sure truncated is empty", Iterables.isEmpty(truncated)); }
@Test public void testTruncatingWithEndIndexEqualToPolyLineSize() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(0, 2); Assert.assertTrue("Make sure truncated is empty", Iterables.isEmpty(truncated)); }
@Test public void testTruncatingWithZeroIndices() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(0, 0); Assert.assertTrue(new PolyLine(truncated).equals(line)); }
/** * 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()); } }
/** * Prepends the given {@link PolyLine} to this one, if possible. * * @param other * The {@link PolyLine} to prepend * @return the new, combined {@link PolyLine} */ public PolyLine prepend(final PolyLine other) { if (this.first().equals(other.last())) { return new PolyLine(new MultiIterable<>(other, this.truncate(1, 0))); } else { throw new CoreException( "Cannot prepend {} to {} - the end and start points do not match.", other.toWkt(), this.toWkt()); } }
@Test public void testTruncatingFromStart() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(1, 0); Assert.assertTrue(new PolyLine(truncated).equals(new PolyLine(Location.TEST_1))); }
@Test public void testTruncatingFromBothSides() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1, Location.TEST_2); final Iterable<Location> truncated = line.truncate(1, 1); Assert.assertTrue(new PolyLine(truncated).equals(new PolyLine(Location.TEST_1))); }
@Test public void testTruncatingFromEnd() { final PolyLine line = new PolyLine(Location.CROSSING_85_280, Location.TEST_1); final Iterable<Location> truncated = line.truncate(0, 1); Assert.assertTrue(new PolyLine(truncated).equals(new PolyLine(Location.CROSSING_85_280))); }
builder.addArea(areaIdentifier, new Polygon(line.asPolyLine().truncate(0, 1)), line.getTags()); });