public class TargetVisitChecker
extends java.lang.Object
The set of locations is represented as an array of Google Maps LatLng objects. The path array contains indexes of the captured targets in the order they were captured. To ensure that's it's possible to capture all targets, the path array has the same size as the locations array. If not all targets have been captured yet, unused slots of the path array have the value -1. The path array is filled starting at the beginning, so all instances of -1 are contiguous at the end of the array.
Constructor and Description |
---|
TargetVisitChecker() |
Modifier and Type | Method and Description |
---|---|
static boolean |
checkSnakeRule(com.google.android.gms.maps.model.LatLng[] targets,
int[] path,
int tryVisit)
Determines whether the specified target can be visited without violating the snake rule.
|
static int |
getTargetWithinRange(com.google.android.gms.maps.model.LatLng[] targets,
int[] path,
com.google.android.gms.maps.model.LatLng currentLocation,
int range)
Gets an index of an unvisited target within the specified range of the current location.
|
static int |
visitTarget(int[] path,
int targetIndex)
Marks a target captured by putting its index in the first available (-1) slot of the path array.
|
public static boolean checkSnakeRule(com.google.android.gms.maps.model.LatLng[] targets, int[] path, int tryVisit)
The snake rule is violated if the new line created between the last captured target and this new target would cross the straight line connecting two sequentially captured targets. For example, there is a line between the first-captured and second-captured targets, and between the second-captured and third-captured targets, but no line directly connecting the first-captured and third-captured targets. If zero or one targets have been captured so far, there are no lines and it is permissible to capture any target.
It is assumed that all parameters are valid. The two arrays are non-null and of the same length. All coordinates are valid. The index of the target to visit is a valid index into the coordinates array. The index of the target to visit does not appear in the path array (i.e. the target has not been visited yet). No existing lines violate the snake rule.
This function should not modify the arrays it receives.
targets
- positions of all targetspath
- indexes of targets visited so far (-1 for empty slots)tryVisit
- index of the target to try to visitpublic static int getTargetWithinRange(com.google.android.gms.maps.model.LatLng[] targets, int[] path, com.google.android.gms.maps.model.LatLng currentLocation, int range)
A target is visited if its index appears in the path array.
It is assumed that all parameters are valid. The two arrays are non-null and of the same length. All coordinates are valid. The range is positive.
This function should not modify the arrays it receives.
targets
- positions of all targetspath
- indexes of targets visited so far (same size as targets, -1 for empty slots)currentLocation
- the current locationrange
- maximum distance to target, in meterspublic static int visitTarget(int[] path, int targetIndex)
It is assumed that all parameters are valid. The path array is non-null and does not yet contain the target index. The target index is non-negative.
path
- the path arraytargetIndex
- the target being visited