diff --git a/lib/circle.dart b/lib/circle.dart new file mode 100644 index 0000000..4d137d6 --- /dev/null +++ b/lib/circle.dart @@ -0,0 +1,4 @@ +library turf_transform; + +export 'package:geotypes/geotypes.dart'; +export 'src/circle.dart'; diff --git a/lib/src/circle.dart b/lib/src/circle.dart new file mode 100644 index 0000000..36cbf27 --- /dev/null +++ b/lib/src/circle.dart @@ -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 circle( + Point center, + num radius, { + num? steps = 64, + Unit? unit = Unit.kilometers, + Map? properties = const {}, +}) { + steps ??= 64; + unit ??= Unit.kilometers; + final List 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( + properties: properties, + geometry: Polygon(coordinates: [coordinates]), + ); +}