@@ -64,7 +64,7 @@ import kotlin.math.max
64
64
import kotlin.math.sin
65
65
import kotlin.math.sqrt
66
66
67
- object MapboxRouteLineUtils {
67
+ internal object MapboxRouteLineUtils {
68
68
69
69
private const val LOG_CATEGORY = " MapboxRouteLineUtils"
70
70
internal const val VANISH_POINT_STOP_GAP = .00000000001
@@ -488,7 +488,7 @@ object MapboxRouteLineUtils {
488
488
* @return a list of items representing the distance offset of each route leg and the color
489
489
* used to represent the traffic congestion.
490
490
*/
491
- internal fun calculateRouteLineSegments (
491
+ fun calculateRouteLineSegments (
492
492
route : NavigationRoute ,
493
493
trafficBackfillRoadClasses : List <String >,
494
494
isPrimaryRoute : Boolean ,
@@ -877,7 +877,7 @@ object MapboxRouteLineUtils {
877
877
private fun generateFeatureCollection (route : NavigationRouteLine ): RouteFeatureData =
878
878
generateRouteFeatureData(route.route, route.identifier)
879
879
880
- private fun calculateGranularDistances (
880
+ private fun calculateGranularDistances (
881
881
stepsPoints : List <List <List <Point >>>
882
882
): RouteLineGranularDistances {
883
883
var distance = 0.0
@@ -955,41 +955,64 @@ object MapboxRouteLineUtils {
955
955
)
956
956
}
957
957
958
- fun getFillerPointsForStepPoints (nextSteps : Array <RouteLineDistancesIndex >): List <RouteLineDistancesIndex > {
958
+ /* *
959
+ * Adds equally spaced [RouteLineDistancesIndex] points between each of the inputted steps and
960
+ * returns a collection of the original [RouteLineDistancesIndex] points with the newly created
961
+ * points between them.
962
+ *
963
+ * @param steps a collection of [RouteLineDistancesIndex] representing step points
964
+ * @return a collection of RouteLineDistancesIndex
965
+ */
966
+ fun getFillerPointsForStepPoints (steps : Array <RouteLineDistancesIndex >): List <RouteLineDistancesIndex > {
959
967
val fillerPoints = mutableListOf<RouteLineDistancesIndex >()
960
- nextSteps .forEachIndexed { index, routeLineDistancesIndex ->
961
- if (index < nextSteps .lastIndex) {
962
- getFillerPoints(routeLineDistancesIndex, nextSteps [index + 1 ]).apply {
968
+ steps .forEachIndexed { index, routeLineDistancesIndex ->
969
+ if (index < steps .lastIndex) {
970
+ getFillerPoints(routeLineDistancesIndex, steps [index + 1 ]).apply {
963
971
fillerPoints.addAll(this )
964
972
}
965
973
}
966
974
}
967
975
return fillerPoints
968
976
}
969
977
970
- // todo the variable names below should be named better
971
- fun getFillerPoints (startPoint : RouteLineDistancesIndex , endPoint : RouteLineDistancesIndex ): List <RouteLineDistancesIndex > {
972
- val gapDist = 1.0 // meters
973
- val turfDistance = TurfMeasurement .distance(startPoint.point, endPoint.point, TurfConstants .UNIT_METERS )
978
+ /* *
979
+ * Creates equally spaced [RouteLineDistancesIndex] points between the start point and end points
980
+ * and returns a collection with the start point and end point with the newly created
981
+ * points between them.
982
+ *
983
+ * @param startPoint the starting RouteLineDistancesIndex
984
+ * @param endPoint the ending RouteLineDistancesIndex
985
+ * @return a collection of the start and end points and the points generated here
986
+ */
987
+ private fun getFillerPoints (
988
+ startPoint : RouteLineDistancesIndex ,
989
+ endPoint : RouteLineDistancesIndex
990
+ ): List <RouteLineDistancesIndex > {
991
+ val gapDistanceInMeters = 1.0
992
+ val turfDistance = TurfMeasurement .distance(
993
+ startPoint.point,
994
+ endPoint.point,
995
+ TurfConstants .UNIT_METERS
996
+ )
974
997
val fillerPoints = mutableListOf<RouteLineDistancesIndex >()
975
998
val bearing = TurfMeasurement .bearing(startPoint.point, endPoint.point)
976
- var lastCalculatedPoint = startPoint
977
- val count = (turfDistance / gapDist).toInt()
999
+ val numPointsToCreate = (turfDistance / gapDistanceInMeters).toInt()
978
1000
val delta = startPoint.distanceRemaining - endPoint.distanceRemaining
979
- val itemDist = delta / count
1001
+ val itemDistance = delta / numPointsToCreate
1002
+ var lastCalculatedPoint = startPoint
1003
+ var distanceRemaining = startPoint.distanceRemaining
980
1004
981
1005
fillerPoints.add(startPoint)
982
- var dist = startPoint.distanceRemaining
983
- repeat(count) {
1006
+ repeat(numPointsToCreate) {
984
1007
val fillerPoint = TurfMeasurement .destination(
985
1008
lastCalculatedPoint.point,
986
- gapDist ,
1009
+ gapDistanceInMeters ,
987
1010
bearing,
988
1011
TurfConstants .UNIT_METERS
989
1012
)
990
1013
991
- dist - = itemDist
992
- fillerPoints.add(RouteLineDistancesIndex (fillerPoint, dist ))
1014
+ distanceRemaining - = itemDistance
1015
+ fillerPoints.add(RouteLineDistancesIndex (fillerPoint, distanceRemaining ))
993
1016
lastCalculatedPoint = fillerPoints.last()
994
1017
}
995
1018
return fillerPoints
0 commit comments