Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolves several code issues #287

Merged
merged 5 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -19,8 +19,8 @@ public Milestone(Builder builder) {
}

/**
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone
* invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
*
* @return {@code int} representing the identifier
* @since 0.4.0
Expand All @@ -31,7 +31,7 @@ public int getIdentifier() {

/**
* Milestone specific {@link Instruction}, which can be used to build a {@link String}
* instruction specified by the superclass
* instruction specified by the superclass.
*
* @return {@link Instruction} to be used to build the {@link String} passed to
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
Expand All @@ -46,13 +46,14 @@ public Instruction getInstruction() {
* {@link com.mapbox.services.android.navigation.v5.navigation.MapboxNavigation} object
* (recommended) or validated directly inside your activity.
*
* @param previousRouteProgress last locations generated {@link RouteProgress} object used to determine certain
* {@link TriggerProperty}s
* @param previousRouteProgress last locations generated {@link RouteProgress} object used to
* determine certain {@link TriggerProperty}s
* @param routeProgress used to determine certain {@link TriggerProperty}s
* @return true if the milestone trigger's valid, else false
* @since 0.4.0
*/
public abstract boolean isOccurring(RouteProgress previousRouteProgress, RouteProgress routeProgress);
public abstract boolean isOccurring(RouteProgress previousRouteProgress,
RouteProgress routeProgress);

/**
* Build a new {@link Milestone}
Expand All @@ -68,8 +69,8 @@ public Builder() {
}

/**
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone
* invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
*
* @return {@code int} representing the identifier
* @since 0.4.0
Expand All @@ -79,8 +80,8 @@ public int getIdentifier() {
}

/**
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone invoked
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
* Milestone specific identifier as an {@code int} value, useful for deciphering which milestone
* invoked {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}.
*
* @param identifier an {@code int} used to identify this milestone instance
* @return this builder
Expand Down Expand Up @@ -126,7 +127,6 @@ public Builder setInstruction(Instruction instruction) {
* @throws NavigationException if an invalid value has been set on the milestone
* @since 0.4.0
*/
public abstract Milestone build() throws NavigationException;
public abstract Milestone build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@
*/
class Operation {

private Operation() {
// Private constructor to prevent initialization of class.
}

static boolean greaterThan(Number[] valueOne, Number valueTwo) {
if (valueOne.length > 1) {
if (valueTwo.equals(TriggerProperty.TRUE)) {
return valueOne[0].doubleValue() > valueOne[1].doubleValue();
} else {
return !(valueOne[0].doubleValue() > valueOne[1].doubleValue());
return valueOne[0].doubleValue() <= valueOne[1].doubleValue();
}
}
return valueOne[0].doubleValue() > valueTwo.doubleValue();
Expand All @@ -23,7 +27,7 @@ static boolean lessThan(Number[] valueOne, Number valueTwo) {
if (valueTwo.equals(TriggerProperty.TRUE)) {
return valueOne[0].doubleValue() < valueOne[1].doubleValue();
} else {
return !(valueOne[0].doubleValue() < valueOne[1].doubleValue());
return valueOne[0].doubleValue() >= valueOne[1].doubleValue();
}
}
return valueOne[0].doubleValue() < valueTwo.doubleValue();
Expand Down Expand Up @@ -56,7 +60,7 @@ static boolean greaterThanEqual(Number[] valueOne, Number valueTwo) {
if (valueTwo.equals(TriggerProperty.TRUE)) {
return valueOne[0].doubleValue() >= valueOne[1].doubleValue();
} else {
return !(valueOne[0].doubleValue() >= valueOne[1].doubleValue());
return valueOne[0].doubleValue() < valueOne[1].doubleValue();
}
}
return valueOne[0].doubleValue() >= valueTwo.doubleValue();
Expand All @@ -67,7 +71,7 @@ static boolean lessThanEqual(Number[] valueOne, Number valueTwo) {
if (valueTwo.equals(TriggerProperty.TRUE)) {
return valueOne[0].doubleValue() <= valueOne[1].doubleValue();
} else {
return !(valueOne[0].doubleValue() <= valueOne[1].doubleValue());
return valueOne[0].doubleValue() > valueOne[1].doubleValue();
}
}
return valueOne[0].doubleValue() <= valueTwo.doubleValue();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.mapbox.services.android.navigation.v5.milestone;

import com.mapbox.services.android.navigation.v5.exception.NavigationException;
import com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress;

/**
* Using a Route Milestone will result in {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)}
* being invoked only once during a navigation session.
* Using a Route Milestone will result in
* {@link MilestoneEventListener#onMilestoneEvent(RouteProgress, String, int)} being invoked only
* once during a navigation session.
*
* @since 0.4.0
*/
public class RouteMilestone extends Milestone {


private Builder builder;
private boolean called;

Expand Down Expand Up @@ -56,7 +55,7 @@ Trigger.Statement getTrigger() {
}

@Override
public RouteMilestone build() throws NavigationException {
public RouteMilestone build() {
return new RouteMilestone(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
*/
public class Trigger {

private Trigger() {
// Empty private constructor to prevent users creating an instance of this class.
}

/**
* Base Trigger statement. Subclassed to provide concrete statements.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,58 +7,118 @@
*/
public class NavigationConstants {

private NavigationConstants() {
// Empty private constructor to prevent users creating an instance of this class.
}

/**
* Identifier value for the default departure milestone event. If additional milestones are added,
* avoid using the 1-5 integer values as identifiers.
*
* @since 0.4.0
*/
public static final int DEPARTURE_MILESTONE = 1;

/**
* Identifier value for the default new step milestone event. If additional milestones are added,
* avoid using the 1-5 integer values as identifiers.
*
* @since 0.4.0
*/
public static final int NEW_STEP_MILESTONE = 2;

/**
* Identifier value for the default imminent milestone event. If additional milestones are added,
* avoid using the 1-5 integer values as identifiers.
*
* @since 0.4.0
*/
public static final int IMMINENT_MILESTONE = 3;

/**
* Identifier value for the default urgent milestone event. If additional milestones are added,
* avoid using the 1-5 integer values as identifiers.
*
* @since 0.4.0
*/
public static final int URGENT_MILESTONE = 4;

/**
* Identifier value for the default arrival milestone event. If additional milestones are added,
* avoid using the 1-5 integer values as identifiers.
*
* @since 0.4.0
*/
public static final int ARRIVAL_MILESTONE = 5;

/**
* Random integer value used for identifying the navigation notification.
*
* @since 0.5.0
*/
static final int NAVIGATION_NOTIFICATION_ID = 5678;

/**
* Threshold user must be in within to count as completing a step. One of two heuristics used to know when a user
* completes a step, see `RouteControllerManeuverZoneRadius`. The users `heading` and the `finalHeading` are
* compared. If this number is within `RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion`, the user has
* Threshold user must be within to count as completing a step. One of two heuristics used to know
* when a user completes a step, see {@link #MANEUVER_ZONE_RADIUS}. The users heading and the
* finalHeading are compared. If this number is within this defined constant, the user has
* completed the step.
*
* @since 0.1.0
*/
static final int MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION = 30;

/**
* Radius in meters the user must enter to count as completing a step. One of two heuristics used to know when a user
* completes a step, see `RouteControllerMaximumAllowedDegreeOffsetForTurnCompletion`.
* Radius in meters the user must enter to count as completing a step. One of two heuristics used
* to know when a user completes a step, see
* {@link #MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION}.
*
* @since 0.1.0
*/
static final int MANEUVER_ZONE_RADIUS = 40;

/**
* Maximum number of meters the user can travel away from step before the
* {@link OffRouteListener}'s called.
*
* @since 0.2.0
*/
static final double MAXIMUM_DISTANCE_BEFORE_OFF_ROUTE = 20;

/**
* Seconds used before a reroute occurs.
*
* @since 0.2.0
*/
static final int SECONDS_BEFORE_REROUTE = 3;

/**
* Accepted deviation excluding horizontal accuracy before the user is considered to be off route.
*
* @since 0.1.0
*/
static final double USER_LOCATION_SNAPPING_DISTANCE = 10;

/**
* When calculating whether or not the user is on the route, we look where the user will be given their speed and
* this variable.
* When calculating whether or not the user is on the route, we look where the user will be given
* their speed and this variable.
*
* @since 0.2.0
*/
static final double DEAD_RECKONING_TIME_INTERVAL = 1.0;

/**
* Maximum angle the user puck will be rotated when snapping the user's course to the route line.
*
* @since 0.3.0
*/
static final int MAX_MANIPULATED_COURSE_ANGLE = 25;

/**
* Meter radius which the user must be inside for an arrival milestone to be triggered and
* navigation to end.
*
*/
static final double METERS_REMAINING_TILL_ARRIVAL = 40;

// Bundle variable keys
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
*/
class NavigationHelper {

private NavigationHelper() {
// Empty private constructor to prevent users creating an instance of this class.
}

/**
* Takes in a raw location, converts it to a point, and snaps it to the closest point along the
* route. This is isolated as separate logic from the snap logic provided because we will always
Expand Down Expand Up @@ -121,15 +125,17 @@ static double routeDistanceRemaining(double legDistanceRemaining, int legIndex,
* @return boolean true if the user location matches (using a tolerance) the final heading
* @since 0.2.0
*/
static boolean bearingMatchesManeuverFinalHeading(Location userLocation, RouteProgress routeProgress,
static boolean bearingMatchesManeuverFinalHeading(Location userLocation,
RouteProgress routeProgress,
double maxTurnCompletionOffset) {
if (routeProgress.currentLegProgress().upComingStep() == null) {
return false;
}

// Bearings need to be normalized so when the bearingAfter is 359 and the user heading is 1, we
// count this as within the MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION.
double finalHeading = routeProgress.currentLegProgress().upComingStep().getManeuver().getBearingAfter();
double finalHeading = routeProgress.currentLegProgress().upComingStep().getManeuver()
.getBearingAfter();
double finalHeadingNormalized = MathUtils.wrap(finalHeading, 0, 360);
double userHeadingNormalized = MathUtils.wrap(userLocation.getBearing(), 0, 360);
return MathUtils.differenceBetweenAngles(finalHeadingNormalized, userHeadingNormalized)
Expand All @@ -150,18 +156,21 @@ static boolean bearingMatchesManeuverFinalHeading(Location userLocation, RoutePr
* @param previousIndices used for adjusting the indices
* @return a {@link NavigationIndices} object which contains the new leg and step indices
*/
static NavigationIndices increaseIndex(RouteProgress routeProgress, NavigationIndices previousIndices) {
static NavigationIndices increaseIndex(RouteProgress routeProgress,
NavigationIndices previousIndices) {
// Check if we are in the last step in the current routeLeg and iterate it if needed.
if (previousIndices.stepIndex()
>= routeProgress.directionsRoute().getLegs().get(routeProgress.legIndex()).getSteps().size() - 2
>= routeProgress.directionsRoute().getLegs().get(routeProgress.legIndex())
.getSteps().size() - 2
&& previousIndices.legIndex() < routeProgress.directionsRoute().getLegs().size() - 1) {
return NavigationIndices.create((previousIndices.legIndex() + 1), 0);
}
return NavigationIndices.create(previousIndices.legIndex(), (previousIndices.stepIndex() + 1));
}

static List<Milestone> checkMilestones(RouteProgress previousRouteProgress,
RouteProgress routeProgress, MapboxNavigation mapboxNavigation) {
RouteProgress routeProgress,
MapboxNavigation mapboxNavigation) {
List<Milestone> milestones = new ArrayList<>();
for (Milestone milestone : mapboxNavigation.getMilestones()) {
if (milestone.isOccurring(previousRouteProgress, routeProgress)) {
Expand Down Expand Up @@ -192,6 +201,6 @@ static Position nextManeuverPosition(int stepIndex, List<LegStep> steps, List<Po
if (steps.size() > (stepIndex + 1)) {
return steps.get(stepIndex + 1).getManeuver().asPosition();
}
return coords.size() >= 1 ? coords.get(coords.size() - 1) : coords.get(coords.size());
return !coords.isEmpty() ? coords.get(coords.size() - 1) : coords.get(coords.size());
}
}