Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix possible IndexOutOfBoundsException exception #1012

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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