/** * Tests if this {@link PolyLine} has at least the same shape as another {@link PolyLine}. If * this {@link PolyLine} is made up of {@link Segment}s ABC and the given {@link PolyLine} is * made up of BC, this would return true, despite the excess {@link Segment}. * * @param other * The other {@link PolyLine} to compare to * @return True if this {@link PolyLine} has at least the same shape as the other (but possibly * more) */ public boolean overlapsShapeOf(final PolyLine other) { final Set<Segment> thisSegments = new HashSet<>(); final List<Segment> segments = this.segments(); segments.forEach(segment -> { thisSegments.add(segment); thisSegments.add(segment.reversed()); }); final List<Segment> otherSegments = other.segments(); for (final Segment otherSegment : otherSegments) { if (!thisSegments.contains(otherSegment)) { return false; } } return true; }
/** * For an point defined by the two surrounding segments, return the angle and location of that * point if that point is not part of a curve, and the angle between the two segments is less * than headingThreshold. * * @param beforeAngle * the segment directly before the point in question * @param afterAngle * the segment directly after the point in question * @param curvedLocations * the locations of all curved segments in the polygon * @return an empty optional if the point is part of a curve, or if the angle is greater than or * equal to headingThreshold. Otherwise, a tuple containing the location of the point * and the angle between beforeAnge and afterAngle */ private Optional<Tuple<Angle, Location>> getSpikyAngleLocation(final Segment beforeAngle, final Segment afterAngle, final Set<Location> curvedLocations) { if (!curvedLocations.contains(afterAngle.end()) && !curvedLocations.contains(beforeAngle.start())) { final Angle difference = this.getDifferenceInHeadings(beforeAngle, afterAngle.reversed(), Angle.MAXIMUM); if (difference.isLessThan(headingThreshold)) { return Optional.of(Tuple.createTuple(difference, afterAngle.start())); } } return Optional.empty(); }