Skip to content

Commit

Permalink
Make sure that the original shape is calculated for flex trips
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 25, 2021
1 parent e1423cb commit 57126c4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.opentripplanner.PolylineAssert.assertThatPolylinesAreEqual;

import java.net.URISyntaxException;
import java.time.OffsetDateTime;
Expand All @@ -12,11 +13,13 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.locationtech.jts.geom.Coordinate;
import org.opentripplanner.PolylineAssert;
import org.opentripplanner.ext.flex.trip.FlexTrip;
import org.opentripplanner.ext.flex.trip.ScheduledDeviatedTrip;
import org.opentripplanner.model.FeedScopedId;
import org.opentripplanner.model.FlexStopLocation;
import org.opentripplanner.model.GenericLocation;
import org.opentripplanner.model.StopTime;
import org.opentripplanner.model.plan.Itinerary;
import org.opentripplanner.routing.algorithm.raptor.router.TransitRouter;
import org.opentripplanner.routing.api.request.RoutingRequest;
Expand Down Expand Up @@ -161,12 +164,19 @@ public void flexTripInTransitMode() {

var itin = itineraries.get(0);
var leg = itin.legs.get(0);

assertEquals("cujv", leg.from.stop.getId().getId());
assertEquals("yz85", leg.to.stop.getId().getId());

var intermediateStops = leg.intermediateStops;
assertEquals(1, intermediateStops.size());
assertEquals("zone_1", intermediateStops.get(0).place.stop.getId().getId());

assertEquals("cujv", leg.from.stop.getId().getId());
assertEquals("yz85", leg.to.stop.getId().getId());
assertThatPolylinesAreEqual(
leg.legGeometry.getPoints(),
"kfsmEjojcOa@eBRKfBfHR|ALjBBhVArMG|OCrEGx@OhAKj@a@tAe@hA]l@MPgAnAgw@nr@cDxCm@t@c@t@c@x@_@~@]pAyAdIoAhG}@lE{AzHWhAtt@t~Aj@tAb@~AXdBHn@FlBC`CKnA_@nC{CjOa@dCOlAEz@E|BRtUCbCQ~CWjD??qBvXBl@kBvWOzAc@dDOx@sHv]aIG?q@@c@ZaB\\mA"
);

}

/**
Expand All @@ -187,7 +197,7 @@ public void shouldNotInterpolateFlexTimes() {
var tripTimes = pattern.getScheduledTimetable().getTripTimes(0);
var arrivalTime = tripTimes.getArrivalTime(1);

assertEquals(-999, arrivalTime);
assertEquals(StopTime.MISSING_VALUE, arrivalTime);
}

private static List<Itinerary> getItineraries(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.opentripplanner.common.geometry.PackedCoordinateSequence;
import org.opentripplanner.common.geometry.SphericalDistanceLibrary;
import org.opentripplanner.common.model.P2;
import org.opentripplanner.ext.flex.trip.FlexTrip;
import org.opentripplanner.graph_builder.DataImportIssueStore;
import org.opentripplanner.graph_builder.issues.BogusShapeDistanceTraveled;
import org.opentripplanner.graph_builder.issues.BogusShapeGeometry;
Expand Down Expand Up @@ -351,6 +352,7 @@ private LineString[] getGeometriesByShape(
}

private List<LinearLocation> getLinearLocations(List<StopTime> stopTimes, LineString shape) {
var isFlexTrip = FlexTrip.isFlexTrip(stopTimes);
// This trip does not have shape_dist in stop_times, but does have an associated shape.
ArrayList<IndexedLineSegment> segments = new ArrayList<>();
for (int i = 0 ; i < shape.getNumPoints() - 1; ++i) {
Expand All @@ -374,7 +376,7 @@ private List<LinearLocation> getLinearLocations(List<StopTime> stopTimes, LineSt
continue;
}
double distance = segment.distance(coord);
if (distance < maxStopToShapeSnapDistance) {
if (distance < maxStopToShapeSnapDistance || isFlexTrip) {
stopSegments.add(segment);
maxSegmentIndex = index;
if (minSegmentIndexForThisStop == -1)
Expand Down

0 comments on commit 57126c4

Please sign in to comment.