@@ -64,7 +64,7 @@ import kotlin.math.max
6464import kotlin.math.sin
6565import kotlin.math.sqrt
6666
67- object MapboxRouteLineUtils {
67+ internal object MapboxRouteLineUtils {
6868
6969 private const val LOG_CATEGORY = " MapboxRouteLineUtils"
7070 internal const val VANISH_POINT_STOP_GAP = .00000000001
@@ -488,7 +488,7 @@ object MapboxRouteLineUtils {
488488 * @return a list of items representing the distance offset of each route leg and the color
489489 * used to represent the traffic congestion.
490490 */
491- internal fun calculateRouteLineSegments (
491+ fun calculateRouteLineSegments (
492492 route : NavigationRoute ,
493493 trafficBackfillRoadClasses : List <String >,
494494 isPrimaryRoute : Boolean ,
@@ -877,7 +877,7 @@ object MapboxRouteLineUtils {
877877 private fun generateFeatureCollection (route : NavigationRouteLine ): RouteFeatureData =
878878 generateRouteFeatureData(route.route, route.identifier)
879879
880- private fun calculateGranularDistances (
880+ private fun calculateGranularDistances (
881881 stepsPoints : List <List <List <Point >>>
882882 ): RouteLineGranularDistances {
883883 var distance = 0.0
@@ -955,41 +955,64 @@ object MapboxRouteLineUtils {
955955 )
956956 }
957957
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 > {
959967 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 {
963971 fillerPoints.addAll(this )
964972 }
965973 }
966974 }
967975 return fillerPoints
968976 }
969977
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+ )
974997 val fillerPoints = mutableListOf<RouteLineDistancesIndex >()
975998 val bearing = TurfMeasurement .bearing(startPoint.point, endPoint.point)
976- var lastCalculatedPoint = startPoint
977- val count = (turfDistance / gapDist).toInt()
999+ val numPointsToCreate = (turfDistance / gapDistanceInMeters).toInt()
9781000 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
9801004
9811005 fillerPoints.add(startPoint)
982- var dist = startPoint.distanceRemaining
983- repeat(count) {
1006+ repeat(numPointsToCreate) {
9841007 val fillerPoint = TurfMeasurement .destination(
9851008 lastCalculatedPoint.point,
986- gapDist ,
1009+ gapDistanceInMeters ,
9871010 bearing,
9881011 TurfConstants .UNIT_METERS
9891012 )
9901013
991- dist - = itemDist
992- fillerPoints.add(RouteLineDistancesIndex (fillerPoint, dist ))
1014+ distanceRemaining - = itemDistance
1015+ fillerPoints.add(RouteLineDistancesIndex (fillerPoint, distanceRemaining ))
9931016 lastCalculatedPoint = fillerPoints.last()
9941017 }
9951018 return fillerPoints
0 commit comments