use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class OffRouteDetector method movingAwayFromManeuver.
/**
* Checks to see if the current point is moving away from the maneuver.
* <p>
* If the current point is farther away from the maneuver than the last point in the
* stack, add it to the stack.
* <p>
* If the stack if >= 3 distances, return true to fire an off-route event as it
* can be considered that the user is no longer going in the right direction.
*
* @param routeProgress for the upcoming step maneuver
* @param distancesAwayFromManeuver current stack of distances away
* @param stepPoints current step points being traveled along
* @param currentPoint to determine if moving away or not
* @return true if moving away from maneuver, false if not
*/
private static boolean movingAwayFromManeuver(RouteProgress routeProgress, RingBuffer<Integer> distancesAwayFromManeuver, List<Point> stepPoints, Point currentPoint) {
if (routeProgress.currentLegProgress().upComingStep() == null || stepPoints.isEmpty()) {
return false;
}
LineString stepLineString = LineString.fromLngLats(stepPoints);
Point maneuverPoint = stepPoints.get(stepPoints.size() - 1);
Point userPointOnStep = (Point) TurfMisc.nearestPointOnLine(currentPoint, stepPoints).geometry();
if (userPointOnStep == null || maneuverPoint.equals(userPointOnStep)) {
return false;
}
LineString remainingStepLineString = TurfMisc.lineSlice(userPointOnStep, maneuverPoint, stepLineString);
double userDistanceToManeuver = TurfMeasurement.length(remainingStepLineString, TurfConstants.UNIT_METERS);
boolean hasDistances = !distancesAwayFromManeuver.isEmpty();
boolean validOffRouteDistanceTraveled = hasDistances && distancesAwayFromManeuver.peekLast() - distancesAwayFromManeuver.peekFirst() < MINIMUM_BACKUP_DISTANCE_FOR_OFF_ROUTE;
boolean exceedsManeuverDistancesThreshold = validOffRouteDistanceTraveled && distancesAwayFromManeuver.size() >= 3;
if (exceedsManeuverDistancesThreshold) {
// User's moving away from maneuver position, thus offRoute.
return true;
}
if (distancesAwayFromManeuver.isEmpty()) {
distancesAwayFromManeuver.push((int) userDistanceToManeuver);
} else if (userDistanceToManeuver > distancesAwayFromManeuver.peek()) {
distancesAwayFromManeuver.push((int) userDistanceToManeuver);
} else {
// If we get a descending distance, reset the counter
distancesAwayFromManeuver.clear();
}
return false;
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class MockLocationEngine method calculateStepPoints.
/**
* Instead of calculating all the points found in the entire route geometry, we go step by step as needed until the
* route in complete. This resolves a memory issue when long routes are being mocked.
*
* @since 2.2.0
*/
private void calculateStepPoints() {
LineString line = LineString.fromPolyline(route.legs().get(currentLeg).steps().get(currentStep).geometry(), Constants.PRECISION_6);
increaseIndex();
sliceRoute(line, distance);
if (noisyGps) {
addNoiseToRoute(distance);
}
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class BaseTest method createCoordinatesFromCurrentStep.
@NonNull
protected List<Point> createCoordinatesFromCurrentStep(RouteProgress progress) {
LegStep currentStep = progress.currentLegProgress().currentStep();
LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
return lineString.coordinates();
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class ToleranceUtilsTest method dynamicRerouteDistanceTolerance_userJustPastTheIntersection.
@Test
public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() throws Exception {
RouteProgress routeProgress = RouteProgress.builder().directionsRoute(response.routes().get(0)).legDistanceRemaining(0).distanceRemaining(0).stepIndex(0).legIndex(0).build();
double distanceToIntersection = response.routes().get(0).distance();
LineString lineString = LineString.fromPolyline(response.routes().get(0).geometry(), Constants.PRECISION_6);
Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS);
double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress);
assertEquals(25.0, tolerance, DELTA);
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class ToleranceUtilsTest method dynamicRerouteDistanceTolerance_userCloseToIntersection.
@Test
public void dynamicRerouteDistanceTolerance_userCloseToIntersection() throws Exception {
RouteProgress routeProgress = RouteProgress.builder().directionsRoute(response.routes().get(0)).legDistanceRemaining(0).distanceRemaining(0).stepIndex(0).legIndex(0).build();
double distanceToIntersection = response.routes().get(0).distance() - 39;
LineString lineString = LineString.fromPolyline(response.routes().get(0).geometry(), Constants.PRECISION_6);
Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS);
double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress);
assertEquals(25.0, tolerance, DELTA);
}
Aggregations