Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
Panz99 committed Jun 4, 2024
1 parent b44f20c commit 001e585
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/circle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library turf_transform;

export 'package:geotypes/geotypes.dart';
export 'src/circle.dart';
37 changes: 37 additions & 0 deletions lib/src/circle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:turf/helpers.dart';
import 'destination.dart';

/// Takes a [Point] and calculates the circle polygon given a radius in degrees, radians, miles, or kilometers; and steps for precision.
///
/// example:
/// ```dart
/// var properties = { 'foo': 'bar' };
/// var point = Feature(geometry: Point(coordinates: Position.of([-75.343, 39.984])));
/// final polygonCircle = circle(
/// feature.geometry!,
/// radius,
/// steps: 32,
/// unit: Unit.meters,
/// properties: feature.properties,
/// );
/// ```
Feature<Polygon> circle(
Point center,
num radius, {
num? steps = 64,
Unit? unit = Unit.kilometers,
Map<String, dynamic>? properties = const {},
}) {
steps ??= 64;
unit ??= Unit.kilometers;
final List<Position> coordinates = [];
for (var i = 0; i < steps; i++) {
final c = destination(center, radius, (i * -360) / steps, unit).coordinates;
coordinates.add(c);
}
coordinates.add(coordinates[0]);
return Feature<Polygon>(
properties: properties,
geometry: Polygon(coordinates: [coordinates]),
);
}

0 comments on commit 001e585

Please sign in to comment.