Skip to content

Commit

Permalink
Fixed error in PolyLine
Browse files Browse the repository at this point in the history
  • Loading branch information
rijnb committed Oct 27, 2017
1 parent 5bc4834 commit 454ac09
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions geo/src/main/java/com/tomtom/speedtools/geometry/GeoPolyLine.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,19 @@ public GeoPolyLine(@Nonnull final List<GeoPoint> points) {

// Check the need to correct the elevation in a list of points.
final List<GeoPoint> elevatedPoints;
final boolean noneElevated = points.stream().allMatch(x -> (x.getElevationMeters() != null));
final boolean allElevated = points.stream().allMatch(x -> (x.getElevationMeters() == null));
final boolean noneElevated = points.stream().noneMatch(x -> (x.getElevationMeters() != null));
final boolean allElevated = points.stream().noneMatch(x -> (x.getElevationMeters() == null));

if (allElevated || noneElevated) {

// Don't need to create a new list.
elevatedPoints = points;
} else {

// Find the first elevation.
double elevationMeters = Double.NaN;
for (final GeoPoint point : points) {
if (point.getElevationMeters() != null) {
elevationMeters = point.getElevationMetersOrNaN();
break;
}
}
// Find the first elevation, or use NaN.
double elevationMeters = points.stream().filter(point -> point.getElevationMeters() != null).findFirst().
orElse(new GeoPoint(0.0, 0.0, Double.NaN)).
getElevationMetersOrNaN();

// Create a new list of points, append first elevation if needed.
elevatedPoints = new ArrayList<>(points.size());
Expand Down

0 comments on commit 454ac09

Please sign in to comment.