Search in sources :

Example 56 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class NavigationRouteProcessorTest method onSnapToRouteEnabledAndUserOnRoute_snappedLocationReturns.

@Test
public void onSnapToRouteEnabledAndUserOnRoute_snappedLocationReturns() throws Exception {
    RouteProgress progress = routeProcessor.buildNewRouteProgress(navigation, mock(Location.class));
    boolean snapEnabled = true;
    boolean userOffRoute = false;
    List<Point> coordinates = createCoordinatesFromCurrentStep(progress);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location rawLocation = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    Location snappedLocation = routeProcessor.buildSnappedLocation(navigation, snapEnabled, rawLocation, progress, userOffRoute);
    assertTrue(!rawLocation.equals(snappedLocation));
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 57 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method setupStepPoints.

private void setupStepPoints(OffRouteDetector offRouteDetector) throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> stepPoints = lineString.coordinates();
    offRouteDetector.updateStepPoints(stepPoints);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 58 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method validOffRoute_onMinimumDistanceBeforeReroutingPassed.

@Test
public void validOffRoute_onMinimumDistanceBeforeReroutingPassed() throws Exception {
    Location mapboxOffice = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    RouteProgress routeProgress = buildDefaultRouteProgress();
    offRouteDetector.isUserOffRoute(mockLocation, mockProgress, options);
    Point target = buildPointAwayFromLocation(mapboxOffice, options.minimumDistanceBeforeRerouting() + 1);
    Location locationOverMinimumDistance = buildDefaultLocationUpdate(target.longitude(), target.latitude());
    boolean validOffRoute = offRouteDetector.isUserOffRoute(locationOverMinimumDistance, routeProgress, options);
    assertTrue(validOffRoute);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 59 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class OffRouteDetectorTest method isUserOffRoute_AssertFalseWhenWithinRadiusAndStepLocationHasBadAccuracy.

@Test
public void isUserOffRoute_AssertFalseWhenWithinRadiusAndStepLocationHasBadAccuracy() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    Point stepManeuverPoint = routeProgress.directionsRoute().legs().get(0).steps().get(0).maneuver().location();
    Location firstUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstUpdate, routeProgress, options);
    Point offRoutePoint = buildPointAwayFromPoint(stepManeuverPoint, 250, 90);
    Location secondUpdate = buildDefaultLocationUpdate(offRoutePoint.longitude(), offRoutePoint.latitude());
    when(secondUpdate.getAccuracy()).thenReturn(300f);
    boolean isUserOffRoute = offRouteDetector.isUserOffRoute(secondUpdate, routeProgress, options);
    assertFalse(isUserOffRoute);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 60 with Point

use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.

the class RouteStepProgressTest method distanceRemaining_equalsCorrectValueAtIntervals.

@Test
public void distanceRemaining_equalsCorrectValueAtIntervals() {
    LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
    double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
    // meters
    double stepSegments = 5;
    // Chop the line in small pieces
    for (double i = 0; i < stepDistance; i += stepSegments) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
        if (point.equals(route.legs().get(0).steps().get(1).maneuver().location())) {
            return;
        }
        LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
        double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
        RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
        RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
        assertEquals(distance, routeStepProgress.distanceRemaining(), BaseTest.DELTA);
    }
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2