17
17
package com.google.maps.android
18
18
19
19
import com.google.android.gms.maps.model.LatLng
20
+ import com.google.maps.android.data.Polygon
21
+ import com.google.maps.android.data.Polyline
20
22
import com.google.maps.android.MathUtil.clamp
21
23
import com.google.maps.android.MathUtil.hav
22
24
import com.google.maps.android.MathUtil.havDistance
@@ -62,7 +64,7 @@ object PolyUtil {
62
64
* @return `true` if the point is inside the polygon, `false` otherwise.
63
65
*/
64
66
@JvmStatic
65
- fun containsLocation (point : LatLng , polygon : List < LatLng > , geodesic : Boolean ): Boolean {
67
+ fun containsLocation (point : LatLng , polygon : Polygon , geodesic : Boolean ): Boolean {
66
68
return containsLocation(point.latitude, point.longitude, polygon, geodesic)
67
69
}
68
70
@@ -74,7 +76,7 @@ object PolyUtil {
74
76
fun containsLocation (
75
77
latitude : Double ,
76
78
longitude : Double ,
77
- polygon : List < LatLng > ,
79
+ polygon : Polygon ,
78
80
geodesic : Boolean
79
81
): Boolean {
80
82
if (polygon.isEmpty()) {
@@ -122,7 +124,7 @@ object PolyUtil {
122
124
@JvmOverloads
123
125
fun isLocationOnEdge (
124
126
point : LatLng ,
125
- polygon : List < LatLng > ,
127
+ polygon : Polygon ,
126
128
geodesic : Boolean ,
127
129
tolerance : Double = DEFAULT_TOLERANCE
128
130
): Boolean {
@@ -145,7 +147,7 @@ object PolyUtil {
145
147
@JvmOverloads
146
148
fun isLocationOnPath (
147
149
point : LatLng ,
148
- polyline : List < LatLng > ,
150
+ polyline : Polyline ,
149
151
geodesic : Boolean ,
150
152
tolerance : Double = DEFAULT_TOLERANCE
151
153
): Boolean {
@@ -154,12 +156,12 @@ object PolyUtil {
154
156
155
157
private fun isLocationOnEdgeOrPath (
156
158
point : LatLng ,
157
- poly : List < LatLng > ,
159
+ polyline : Polyline ,
158
160
closed : Boolean ,
159
161
geodesic : Boolean ,
160
162
toleranceEarth : Double
161
163
): Boolean {
162
- val idx = locationIndexOnEdgeOrPath(point, poly , closed, geodesic, toleranceEarth)
164
+ val idx = locationIndexOnEdgeOrPath(point, polyline , closed, geodesic, toleranceEarth)
163
165
164
166
return (idx >= 0 )
165
167
}
@@ -183,7 +185,7 @@ object PolyUtil {
183
185
@JvmOverloads
184
186
fun locationIndexOnPath (
185
187
point : LatLng ,
186
- poly : List < LatLng > ,
188
+ poly : Polyline ,
187
189
geodesic : Boolean ,
188
190
tolerance : Double = DEFAULT_TOLERANCE
189
191
): Int {
@@ -209,7 +211,7 @@ object PolyUtil {
209
211
@JvmStatic
210
212
fun locationIndexOnEdgeOrPath (
211
213
point : LatLng ,
212
- poly : List < LatLng > ,
214
+ poly : Polyline ,
213
215
closed : Boolean ,
214
216
geodesic : Boolean ,
215
217
toleranceEarth : Double
@@ -299,8 +301,8 @@ object PolyUtil {
299
301
* simplified poly.
300
302
* @return a simplified poly produced by the Douglas-Peucker algorithm
301
303
*/
302
- @JvmStatic
303
- fun simplify (poly : List < LatLng > , tolerance : Double ): List < LatLng > {
304
+ @JvmStatic
305
+ fun simplify (poly : Polyline , tolerance : Double ): Polyline {
304
306
require(poly.isNotEmpty()) { " Polyline must have at least 1 point" }
305
307
require(tolerance > 0 ) { " Tolerance must be greater than zero" }
306
308
@@ -339,13 +341,13 @@ object PolyUtil {
339
341
* If this point is farther than the specified tolerance, it is kept, and the algorithm is
340
342
* applied recursively to the two new segments.
341
343
*
342
- * @param poly The polyline to be simplified.
344
+ * @param polyline The polyline to be simplified.
343
345
* @param tolerance The tolerance in meters.
344
346
* @return A boolean array where `true` indicates that the point at the corresponding index
345
347
* should be kept in the simplified polyline.
346
348
*/
347
- private fun douglasPeucker (poly : List < LatLng > , tolerance : Double ): BooleanArray {
348
- val n = poly .size
349
+ private fun douglasPeucker (polyline : Polyline , tolerance : Double ): BooleanArray {
350
+ val n = polyline .size
349
351
// We start with a boolean array that will mark the points to keep.
350
352
// Initially, only the first and last points are marked for keeping.
351
353
val keepPoint = BooleanArray (n) { false }
@@ -368,7 +370,7 @@ object PolyUtil {
368
370
// For the current segment, we find the point that is farthest from the line
369
371
// connecting the start and end points.
370
372
for (idx in start + 1 until end) {
371
- val dist = distanceToLine(poly [idx], poly [start], poly [end])
373
+ val dist = distanceToLine(polyline [idx], polyline [start], polyline [end])
372
374
if (dist > maxDist) {
373
375
maxDist = dist
374
376
maxIdx = idx
@@ -393,13 +395,13 @@ object PolyUtil {
393
395
* Returns true if the provided list of points is a closed polygon (i.e., the first and last
394
396
* points are the same), and false if it is not
395
397
*
396
- * @param poly polyline or polygon
398
+ * @param polyline polyline or polygon
397
399
* @return true if the provided list of points is a closed polygon (i.e., the first and last
398
400
* points are the same), and false if it is not
399
401
*/
400
402
@JvmStatic
401
- fun isClosedPolygon (poly : List < LatLng > ): Boolean {
402
- return poly .isNotEmpty() && poly .first() == poly .last()
403
+ fun isClosedPolygon (polyline : Polyline ): Boolean {
404
+ return polyline .isNotEmpty() && polyline .first() == polyline .last()
403
405
}
404
406
405
407
/* *
@@ -447,7 +449,7 @@ object PolyUtil {
447
449
* Decodes an encoded path string into a sequence of LatLngs.
448
450
*/
449
451
@JvmStatic
450
- fun decode (encodedPath : String ): List < LatLng > {
452
+ fun decode (encodedPath : String ): Polyline {
451
453
val len = encodedPath.length
452
454
val path = mutableListOf<LatLng >()
453
455
var index = 0
@@ -484,7 +486,7 @@ object PolyUtil {
484
486
* Encodes a sequence of LatLngs into an encoded path string.
485
487
*/
486
488
@JvmStatic
487
- fun encode (path : List < LatLng > ): String {
489
+ fun encode (path : Polyline ): String {
488
490
var lastLat: Long = 0
489
491
var lastLng: Long = 0
490
492
val result = StringBuilder ()
0 commit comments