Skip to content

Commit

Permalink
Fix possible IndexOutOfBoundsException exception (#1013)
Browse files Browse the repository at this point in the history
Check if list is empty before getting its items. Also add an
annotation to indicate that steps parameter should be greater than 0.
  • Loading branch information
osana authored Apr 24, 2019
1 parent 5c65967 commit 0934b06
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mapbox.turf;

import android.support.annotation.IntRange;
import android.support.annotation.NonNull;

import com.mapbox.geojson.Polygon;
Expand Down Expand Up @@ -62,14 +63,16 @@ public static Polygon circle(@NonNull Point center, double radius,
* @return a {@link Polygon} which represents the newly created circle
* @since 3.0.0
*/
public static Polygon circle(@NonNull Point center, double radius, int steps,
public static Polygon circle(@NonNull Point center, double radius, @IntRange(from = 1) int steps,
@TurfConstants.TurfUnitCriteria String units) {
List<Point> coordinates = new ArrayList<>();
for (int i = 0; i < steps; i++) {
coordinates.add(TurfMeasurement.destination(center, radius, i * 360d / steps, units));
}
coordinates.add(coordinates.get(0));

if (coordinates.size() > 0) {
coordinates.add(coordinates.get(0));
}
List<List<Point>> coordinate = new ArrayList<>();
coordinate.add(coordinates);
return Polygon.fromLngLats(coordinate);
Expand Down

0 comments on commit 0934b06

Please sign in to comment.