Skip to content

Commit 1eec828

Browse files
committed
Merge remote-tracking branch 'origin/zero-split-elevation-extension-nan-fix' into v2
2 parents 4fec139 + 7a1d046 commit 1eec828

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

street/src/main/java/org/opentripplanner/street/model/edge/StreetEdge.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ protected void copyPropertiesToSplitEdge(
773773
);
774774

775775
StreetElevationExtensionBuilder.of(seb)
776-
.withDistanceInMeters(defaultMillimeterLength(seb.geometry()) / 1000.)
776+
.withDistanceInMeters(toDistance - fromDistance)
777777
.withElevationProfile(partialElevationProfileFromParent)
778778
.build()
779779
.ifPresent(seb::withElevationExtension);

street/src/main/java/org/opentripplanner/street/model/edge/StreetElevationExtensionBuilder.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ public static StreetElevationExtensionBuilder of(StreetEdgeBuilder<?> seb) {
3939
}
4040

4141
public Optional<StreetElevationExtension> build() {
42-
if (elevationProfileHasAtLeastTwoPoints() && (!isSlopeOverride || computed)) {
42+
if (
43+
distanceInMeters > 0.01 &&
44+
elevationProfileHasAtLeastTwoPoints() &&
45+
(!isSlopeOverride || computed)
46+
) {
4347
return Optional.of(buildInternal());
4448
}
4549
return Optional.empty();

street/src/test/java/org/opentripplanner/street/model/edge/StreetElevationExtensionBuilderTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,14 @@ class StreetElevationExtensionBuilderTest {
3030
new Coordinate(0, 0),
3131
new Coordinate(1, 1),
3232
};
33+
private static final Coordinate[] COORDINATES_ONE_POINT_TWICE = new Coordinate[] {
34+
new Coordinate(0, 0),
35+
new Coordinate(0, 0),
36+
};
3337
private static final PackedCoordinateSequence ELEVATION_PROFILE_TWO_POINTS =
3438
new PackedCoordinateSequence.Double(COORDINATES_TWO_POINTS, 2);
39+
private static final PackedCoordinateSequence ELEVATION_PROFILE_ONE_POINT_TWICE =
40+
new PackedCoordinateSequence.Double(COORDINATES_ONE_POINT_TWICE, 2);
3541

3642
private static final LineString GEOMETRY = GeometryUtils.getGeometryFactory().createLineString(
3743
new Coordinate[] {
@@ -68,6 +74,15 @@ void testValidElevationProfile() {
6874
assertFalse(streetElevationExtension.isEmpty());
6975
}
7076

77+
@Test
78+
void testZeroLengthEdge() {
79+
StreetElevationExtensionBuilder seeb = new StreetElevationExtensionBuilder()
80+
.withDistanceInMeters(0)
81+
.withElevationProfile(ELEVATION_PROFILE_ONE_POINT_TWICE);
82+
Optional<StreetElevationExtension> streetElevationExtension = seeb.build();
83+
assertTrue(streetElevationExtension.isEmpty());
84+
}
85+
7186
@Test
7287
void testBuildFromStreetEdge() {
7388
StreetEdge se = streetEdgeBuilder.buildAndConnect();

0 commit comments

Comments
 (0)