Skip to content

Commit

Permalink
Merge branch 'main' into feature-boolean-overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiedentop committed Jan 25, 2024
2 parents 9f05363 + c3537d6 commit d3bc85c
Show file tree
Hide file tree
Showing 90 changed files with 3,756 additions and 67 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ doc/api/

coverage/

.idea/
.idea/

14 changes: 12 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
## 0.0.8

- Implements `transformRotate`, `rhumbDistance`, `rhumbDestination`, `centroid` [#147](https://github.com/dartclub/turf_dart/pull/147)
- Introduce `localCoordIndex` in `coordEach`
- Implements all the `boolean`* functions [#91](https://github.com/dartclub/turf_dart/pull/91)
- Implements `area` function [#123](https://github.com/dartclub/turf_dart/pull/123)
- Implements `polygonSmooth` function [#127](https://github.com/dartclub/turf_dart/pull/127)
- Fixes missing parameter in nearest point on line [#145](https://github.com/dartclub/turf_dart/pull/145)
- Other core improvements
- Support for Dart 3

## 0.0.7

- Implements `nearestPointOn(Multi)Line` [#87](https://github.com/dartclub/turf_dart/pull/87)
Expand Down Expand Up @@ -25,10 +36,9 @@
- Documentation: improves pub.dev scores, raised documentation coverage, fixed typos
- Return type fixes for the the meta extensions


## 0.0.5

- Implements *all* meta functions and`lineSegment`
- Implements *all* meta functions and`lineSegment`
- Adds a lot of documentation
- Several bug and type fixes

Expand Down
29 changes: 19 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,29 @@
Welcome and thank you for deciding to contribute to the project!

Here is how cooperation works perfectly at [Turf Dart](https://github.com/dartclub/turf_dart)

#### Table of Contents
- [Code of Conduct](#code-of-conduct)
- [Get started](#get-started)
- [Structure of modules](#structure-of-modules)
- [Implementation Process](#implementation-process)
- [Documentation](#documentation)
- [GeoJSON object model](#GeoJSON-object-model)

- [Code of Conduct](#code-of-conduct)
- [Get started](#get-started)
- [Structure of modules](#structure-of-modules)
- [Implementation Process](#implementation-process)
- [Documentation](#documentation)
- [GeoJSON object model](#GeoJSON-object-model)

## Code of conduct

By participating, you are expected to uphold international human rights and fundamental freedoms!
To put it simply, be kind to each other.
To put it simply, be kind to each other.

## Get started

- Get the [Dart tools](https://dart.dev/tools)
- Clone the repository: ```git clone [email protected]:dartclub/turf_dart.git```
- Navigate to project's folder in terminal & get its dependencies: ```dart pub get```
- Go through [Implementation Process](#implementation-process)
- Import the library in your code and use it. For example:

```dart
import 'package:turf/helpers.dart';
import 'package:turf/src/line_segment.dart';
Expand Down Expand Up @@ -58,7 +63,8 @@ var total = segmentReduce<int>(poly, (previousValue,
```

## Structure of modules
```

```text
TURF_DART/lib/<MODULE NAME>.dart // public facing API, exports the implementation
│ │
│ └───src/<MODULE NAME>.dart // the implementation
Expand All @@ -67,7 +73,9 @@ TURF_DART/lib/<MODULE NAME>.dart // public facing API, exports the implementatio
└───test/components/<MODULE NAME>_test.dart // all the related tests
```

## Implementation process

- Check the Backlog/Issues for similar issues
- Create a new branch _feature-_ from _main_
- Create a _draft Pull request_, mention in it the associated issues
Expand All @@ -80,16 +88,17 @@ TURF_DART/lib/<MODULE NAME>.dart // public facing API, exports the implementatio
- run the benchmark: ```dart pub run benchmark```
- Commit
- Convert to real Pull request _ready for review_
- Code review / mention a reviewer from [contributors list](https://github.com/dartclub/turf_dart/graphs/contributors)

- Code review / mention a reviewer from [contributors list](https://github.com/dartclub/turf_dart/graphs/contributors)

## Documentation

We follow [Effective Dart](https://dart.dev/guides/language/effective-dart/documentation) guidelines for documentation.

After going through the [Implementation Process](#implementation-process), please mention the made changes in [README.md](https://github.com/dartclub/turf_dart/blob/main/README.md)

In order to add to this very documentation, please develop CONTRIBUTING.md in [documentation branch](https://github.com/dartclub/turf_dart/tree/documentation)

## GeoJSON Object Model

If you have not read our [README.md](https://github.com/dartclub/turf_dart/blob/main/README.md) this diagram will give you a lot of information. Please consider looking our [notable design decisions](https://github.com/dartclub/turf_dart/blob/main/README.md#notable-design-decisions).
![polymorphism](https://user-images.githubusercontent.com/10634693/159876354-f9da2f37-02b3-4546-b32a-c0f82c372272.png)
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# turf.dart

ℹ️ Looking for maintainers as a work student position in Germany: Write an email to [[email protected]](mailto:[email protected]) ℹ️

[![pub package](https://img.shields.io/pub/v/turf.svg)](https://pub.dev/packages/turf)

THIS PROJECT IS WORK IN PROCESS
Expand Down Expand Up @@ -85,7 +87,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [x] [bearing](https://github.com/dartclub/turf_dart/blob/main/lib/src/bearing.dart)
- [x] [center](https://github.com/Dennis-Mwea/turf_dart/blob/main/lib/src/center.dart)
- [ ] centerOfMass
- [ ] centroid
- [x] [centroid](https://github.com/dartclub/turf_dart/blob/main/lib/src/centroid.dart)
- [x] [destination](https://github.com/dartclub/turf_dart/blob/main/lib/src/destination.dart)
- [x] [distance](https://github.com/dartclub/turf_dart/blob/main/lib/src/distance.dart)
- [ ] envelope
Expand All @@ -95,8 +97,8 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [ ] polygonTangents
- [ ] pointToLineDistance
- [x] [rhumbBearing](https://github.com/dartclub/turf_dart/blob/main/lib/src/rhumb_bearing.dart)
- [ ] rhumbDestination
- [ ] rhumbDistance
- [x] [rhumbDestination](https://github.com/dartclub/turf_dart/blob/main/lib/src/rhumb_destination.dart)
- [x] [rhumbDistance](https://github.com/dartclub/turf_dart/blob/main/lib/src/rhumb_distance.dart)
- [ ] square
- [ ] greatCircle

Expand Down Expand Up @@ -124,7 +126,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [x] [polygonSmooth](ttps://github.com/dartclub/turf_dart/blob/main/lib/src/polygon_smooth.dart)
- [ ] simplify
- [ ] tesselate
- [ ] transformRotate
- [x] [transformRotate](https://github.com/dartclub/turf_dart/blob/main/lib/src/transform_rotate.dart)
- [ ] transformTranslate
- [ ] transformScale
- [ ] union
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include: package:dartclub_lint/dart.yaml
include: package:lints/recommended.yaml

analyzer:
errors:
Expand Down
3 changes: 3 additions & 0 deletions lib/centroid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
library turf_centroid;

export 'src/centroid.dart';
1 change: 1 addition & 0 deletions lib/destination.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library turf_destination;

export 'src/destination.dart';
export 'src/rhumb_destination.dart';
1 change: 1 addition & 0 deletions lib/distance.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
library turf_distance;

export 'src/distance.dart';
export 'src/rhumb_distance.dart';
34 changes: 34 additions & 0 deletions lib/src/centroid.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:turf/helpers.dart';
import 'package:turf/meta.dart';

/// Takes a [Feature] or a [FeatureCollection] and computes the centroid as the mean of all vertices within the object.
///
/// example:
/// ```dart
/// final line = Feature<LineString>(geometry: LineString(coordinates: [Position(0, 0), Position(1, 1)]));
///
/// final pt = centroid(line);
/// ```
Feature<Point> centroid(
GeoJSONObject geoJSON, {
Map<String, dynamic>? properties,
}) {
num xSum = 0;
num ySum = 0;
int len = 0;

coordEach(geoJSON, (coords, _, __, ___, ____) {
if (coords != null) {
xSum += coords[0]!;
ySum += coords[1]!;
len++;
}
}, true);

return Feature<Point>(
geometry: Point(
coordinates: Position(xSum / len, ySum / len),
),
properties: properties,
);
}
1 change: 0 additions & 1 deletion lib/src/geojson.dart
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ class BBox extends CoordinateType {

/// latitude 2 for 2 dim. positions; longitude 2 for 3 dim. positions
num lng2, [

/// latitude 2 for 3 dim. positions
num? lat2,

Expand Down
92 changes: 58 additions & 34 deletions lib/src/meta/coord.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,39 @@ typedef CoordEachCallback = dynamic Function(
int? geometryIndex,
);

typedef LocalizedCoordEachCallback = dynamic Function(
Position? currentCoord,
int? coordIndex,
int? featureIndex,
int? multiFeatureIndex,
int? geometryIndex,
int? localCoordIndex,
);

dynamic _callbackWrapper(
Function callback, Position? currentCoord, _IndexCounter counter) {
if (callback is CoordEachCallback) {
return callback(
currentCoord,
counter.coordIndex,
counter.featureIndex,
counter.multiFeatureIndex,
counter.geometryIndex,
);
} else if (callback is LocalizedCoordEachCallback) {
return callback(
currentCoord,
counter.coordIndex,
counter.featureIndex,
counter.multiFeatureIndex,
counter.geometryIndex,
counter.localCoordIndex,
);
} else {
throw Exception('Unknown callback type');
}
}

/// Iterates over coordinates in any [geoJSONObject], similar to [Iterable.forEach]
/// example:
/// ```dart
Expand All @@ -26,7 +59,7 @@ typedef CoordEachCallback = dynamic Function(
/// //=geometryIndex
/// });
/// ```
void coordEach(GeoJSONObject geoJSON, CoordEachCallback callback,
void coordEach(GeoJSONObject geoJSON, Function callback,
[bool excludeWrapCoord = false]) {
_IndexCounter indexCounter = _IndexCounter();
try {
Expand All @@ -52,15 +85,12 @@ void coordEach(GeoJSONObject geoJSON, CoordEachCallback callback,
}
}

void _forEachCoordInGeometryObject(
GeometryType geometry,
CoordEachCallback callback,
bool excludeWrapCoord,
_IndexCounter indexCounter) {
void _forEachCoordInGeometryObject(GeometryType geometry, Function callback,
bool excludeWrapCoord, _IndexCounter indexCounter) {
GeoJSONObjectType geomType = geometry.type;
int wrapShrink = excludeWrapCoord &&
(geomType == GeoJSONObjectType.polygon ||
geomType == GeoJSONObjectType.multiLineString)
geomType == GeoJSONObjectType.multiPolygon)
? 1
: 0;
indexCounter.multiFeatureIndex = 0;
Expand All @@ -84,42 +114,35 @@ void _forEachCoordInGeometryObject(
}

void _forEachCoordInMultiNestedCollection(coords, GeoJSONObjectType geomType,
int wrapShrink, CoordEachCallback callback, _IndexCounter indexCounter) {
int wrapShrink, Function callback, _IndexCounter indexCounter) {
for (var j = 0; j < coords.length; j++) {
int geometryIndex = 0;
indexCounter.geometryIndex = 0;
for (var k = 0; k < coords[j].length; k++) {
indexCounter.localCoordIndex = 0;
for (var l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (callback(
coords[j][k][l],
indexCounter.coordIndex,
indexCounter.featureIndex,
indexCounter.multiFeatureIndex,
geometryIndex) ==
if (_callbackWrapper(callback, coords[j][k][l], indexCounter) ==
false) {
throw ShortCircuit();
}
indexCounter.coordIndex++;
indexCounter.localCoordIndex++;
}
geometryIndex++;
indexCounter.geometryIndex++;
}
indexCounter.multiFeatureIndex++;
}
}

void _forEachCoordInNestedCollection(coords, GeoJSONObjectType geomType,
int wrapShrink, CoordEachCallback callback, _IndexCounter indexCounter) {
int wrapShrink, Function callback, _IndexCounter indexCounter) {
for (var j = 0; j < coords.length; j++) {
indexCounter.localCoordIndex = 0;
for (var k = 0; k < coords[j].length - wrapShrink; k++) {
if (callback(
coords[j][k],
indexCounter.coordIndex,
indexCounter.featureIndex,
indexCounter.multiFeatureIndex,
indexCounter.geometryIndex) ==
false) {
if (_callbackWrapper(callback, coords[j][k], indexCounter) == false) {
throw ShortCircuit();
}
indexCounter.coordIndex++;
indexCounter.localCoordIndex++;
}
if (geomType == GeoJSONObjectType.multiLineString) {
indexCounter.multiFeatureIndex++;
Expand All @@ -134,14 +157,14 @@ void _forEachCoordInNestedCollection(coords, GeoJSONObjectType geomType,
}

void _forEachCoordInCollection(coords, GeoJSONObjectType geomType,
CoordEachCallback callback, _IndexCounter indexCounter) {
Function callback, _IndexCounter indexCounter) {
indexCounter.localCoordIndex = 0;
for (var j = 0; j < coords.length; j++) {
if (callback(coords[j], indexCounter.coordIndex, indexCounter.featureIndex,
indexCounter.multiFeatureIndex, indexCounter.geometryIndex) ==
false) {
if (_callbackWrapper(callback, coords[j], indexCounter) == false) {
throw ShortCircuit();
}
indexCounter.coordIndex++;
indexCounter.localCoordIndex++;
if (geomType == GeoJSONObjectType.multiPoint) {
indexCounter.multiFeatureIndex++;
}
Expand All @@ -152,18 +175,19 @@ void _forEachCoordInCollection(coords, GeoJSONObjectType geomType,
}

void _forEachCoordInPoint(
Position coords, CoordEachCallback callback, _IndexCounter indexCounter) {
if (callback(coords, indexCounter.coordIndex, indexCounter.featureIndex,
indexCounter.multiFeatureIndex, indexCounter.geometryIndex) ==
false) {
Position coords, Function callback, _IndexCounter indexCounter) {
indexCounter.localCoordIndex = 0;
if (_callbackWrapper(callback, coords, indexCounter) == false) {
throw ShortCircuit();
}
indexCounter.localCoordIndex++;
indexCounter.coordIndex++;
indexCounter.multiFeatureIndex++;
}

/// A simple class to manage counters from CoordinateEach functions
class _IndexCounter {
int localCoordIndex = 0;
int coordIndex = 0;
int geometryIndex = 0;
int multiFeatureIndex = 0;
Expand Down Expand Up @@ -232,8 +256,8 @@ T? coordReduce<T>(
bool excludeWrapCoord = false,
]) {
var previousValue = initialValue;
coordEach(geojson, (currentCoord, coordIndex, featureIndex, multiFeatureIndex,
geometryIndex) {
coordEach(geojson, (Position? currentCoord, coordIndex, featureIndex,
multiFeatureIndex, geometryIndex) {
if (coordIndex == 0 && initialValue == null && currentCoord is T) {
previousValue = currentCoord?.clone() as T;
} else {
Expand Down
Loading

0 comments on commit d3bc85c

Please sign in to comment.