Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,12 @@ private List<LineString> generateHopGeometriesFromOriginalTripPattern() {
// being replaced having a different number of stops. In that case the geometry will be
// preserved up until the first mismatching stop, and a straight line will be used for
// all segments after that.
int sizeOfShortestPattern = Math.min(
stopPattern.getSize(),
originalTripPattern.numberOfStops()
);

List<LineString> hopGeometries = new ArrayList<>();

for (int i = 0; i < sizeOfShortestPattern - 1; i++) {
LineString hopGeometry = originalTripPattern.getHopGeometry(i);
for (int i = 0; i < stopPattern.getSize() - 1; i++) {
LineString hopGeometry = i < originalTripPattern.numberOfStops() - 1
? originalTripPattern.getHopGeometry(i)
: null;

if (hopGeometry != null && stopPattern.sameStops(originalTripPattern.getStopPattern(), i)) {
// Copy hop geometry from previous pattern
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class TripPatternTest {

private static final Route ROUTE = TimetableRepositoryForTest.route("routeId").build();
public static final RegularStop STOP_A = TEST_MODEL.stop("A").build();
public static final RegularStop STOP_X = TEST_MODEL.stop("X").build();
public static final RegularStop STOP_B = TEST_MODEL.stop("B").build();
public static final RegularStop STOP_Y = TEST_MODEL.stop("Y").build();
public static final RegularStop STOP_C = TEST_MODEL.stop("C").build();
private static final StopPattern STOP_PATTERN = TimetableRepositoryForTest.stopPattern(
STOP_A,
Expand All @@ -33,8 +35,8 @@ class TripPatternTest {
);

private static final List<LineString> HOP_GEOMETRIES = List.of(
makeLineString(STOP_A.getCoordinate(), STOP_B.getCoordinate()),
makeLineString(STOP_B.getCoordinate(), STOP_C.getCoordinate())
makeLineString(STOP_A.getCoordinate(), STOP_X.getCoordinate(), STOP_B.getCoordinate()),
makeLineString(STOP_B.getCoordinate(), STOP_Y.getCoordinate(), STOP_C.getCoordinate())
);

private static final TripPattern subject = TripPattern
Expand Down Expand Up @@ -70,6 +72,27 @@ void copy() {
assertEquals(HOP_GEOMETRIES.get(1), copy.getHopGeometry(1));
}

@Test
void hopGeometryForReplacementPattern() {
var pattern = TripPattern
.of(id("replacement"))
.withName("replacement")
.withRoute(ROUTE)
.withStopPattern(TimetableRepositoryForTest.stopPattern(STOP_A, STOP_B, STOP_X, STOP_Y))
.withOriginalTripPattern(subject)
.build();

assertEquals(HOP_GEOMETRIES.get(0), pattern.getHopGeometry(0));
assertEquals(
makeLineString(STOP_B.getCoordinate(), STOP_X.getCoordinate()),
pattern.getHopGeometry(1)
);
assertEquals(
makeLineString(STOP_X.getCoordinate(), STOP_Y.getCoordinate()),
pattern.getHopGeometry(2)
);
}

@Test
void sameAs() {
assertTrue(subject.sameAs(subject.copy().build()));
Expand Down
Loading