-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port boolean functions and tests (#91)
* in process - early analysis of the work * linked the meta functions in readme * CONTRIBUTING.md * links to the sources * edited typos * documentation work * closes #77, closes #16 * proofread * improves pub.dev score, closes #79, #78, #75 * Added deleted model, complemented contributing.md * booleans init * initial import * boolean_touches * valid - wip * within - init * rewiring the translated code * contains etc. * touches * valid * dependencies imported * Update CONTRIBUTING.md * clockwise test * concave test * intersect test * pointOnLine test * contains * crosses_test - blocked by findIntersections * boolean_contain * boolean_within * rhumb_bearing * rhumb_bearing\'s test - incomplete * rhumb_bearing's test - done, added to lib/bearing * boolean_contains, boolean_parallel, IP * working on contain - removed usages of runtimeType * rewriting pointInLine * tests reverted to false/true folder style * restructuring, clean-up * clockwise and its test, documentation * concave finalized * PointInPolygon plus test, dart format * removed the commented JS lines * return type added * disjoint and test - not done, depends on sweepline * equal implement, test, has dependencies * moving on * clean coords init * cleanCoord implemented, going to new branch * moving on with equal * update turf_equality dep * moving forward * refactors boolean_equal * #88 crosses, disjoint, equal, intersects, pip @lukas-h * cleanup on #88 * progress on overlap * bool: overlap,parallel,valid,touches & lineOverlap * issue with test is worked on * still at porting the overlap test * done: parallel * working on valid * touches done * valid - got stuck * progress on within * moved on with valid, refactored * valid test * lineIntersection testet - contains sweepline * package publishabe, rm git deps, fix equality dep * update params in equality * mod. on valid to cover the std. - MutiPs' 'finite' * RFCs resolved - readied for merge * return type of getGeom * linter effect! * reolved requests * more requests resolved * more requests resolved * test name, touching lineOverlap * fix conversations in booleanContains * fixes conversations in crosses and disjoint * resolves allllllllll outdated conversations, refactor * use getGeom in booleanTouches * use getGeom more frequently * rm linter rule, which is already inherited from dartclub_lint * cleanup, ready for merge Co-authored-by: Lukas Himsel <[email protected]>
- Loading branch information
1 parent
f503b90
commit b17c9bf
Showing
440 changed files
with
16,117 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,42 @@ To put it simply, be kind to each other. | |
- 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'; | ||
Feature<Polygon> poly = Feature<Polygon>( | ||
geometry: Polygon(coordinates: [ | ||
[ | ||
Position(0, 0), | ||
Position(2, 2), | ||
Position(0, 1), | ||
Position(0, 0), | ||
], | ||
[ | ||
Position(0, 0), | ||
Position(1, 1), | ||
Position(0, 1), | ||
Position(0, 0), | ||
], | ||
]), | ||
); | ||
var total = segmentReduce<int>(poly, (previousValue, | ||
currentSegment, | ||
initialValue, | ||
featureIndex, | ||
multiFeatureIndex, | ||
geometryIndex, | ||
segmentIndex) { | ||
if (previousValue != null) { | ||
previousValue++; | ||
} | ||
return previousValue; | ||
}, 0, combineNestedGeometries: false); | ||
// total.length == 6 | ||
``` | ||
|
||
## Structure of modules | ||
``` | ||
|
@@ -56,4 +92,4 @@ In order to add to this very documentation, please develop CONTRIBUTING.md in [d | |
|
||
## 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) | ||
![polymorphism](https://user-images.githubusercontent.com/10634693/159876354-f9da2f37-02b3-4546-b32a-c0f82c372272.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import 'package:turf/src/invariant.dart'; | ||
|
||
import '../../helpers.dart'; | ||
|
||
/// Takes a ring and return [true] or [false] whether or not the ring is clockwise | ||
/// or counter-clockwise. | ||
/// Takes a [Feature<LineString>] or[LineString] or a [List<Position>] to be | ||
/// evaluated. | ||
/// example: | ||
/// ```dart | ||
/// var clockwiseRing = LineString( | ||
/// coordinates: [ | ||
/// Position.of([0, 0]), | ||
/// Position.of([1, 1]), | ||
/// Position.of([1, 0]), | ||
/// Position.of([0, 0]) | ||
/// ], | ||
/// ); | ||
/// var counterClockwiseRing = LineString( | ||
/// coordinates: [ | ||
/// Position.of([0, 0]), | ||
/// Position.of([1, 0]), | ||
/// Position.of([1, 1]), | ||
/// Position.of([0, 0]) | ||
/// ], | ||
/// ); | ||
/// | ||
/// booleanClockwise(clockwiseRing); | ||
/// //=true | ||
/// booleanClockwise(counterClockwiseRing); | ||
/// //=false | ||
/// ``` | ||
bool booleanClockwise(LineString line) { | ||
var ring = getCoords(line) as List<Position>; | ||
num sum = 0; | ||
int i = 1; | ||
Position prev; | ||
Position? cur; | ||
|
||
while (i < ring.length) { | ||
prev = cur ?? ring[0]; | ||
cur = ring[i]; | ||
sum += (cur[0]! - prev[0]!) * (cur[1]! + prev[1]!); | ||
i++; | ||
} | ||
return sum > 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:turf/helpers.dart'; | ||
|
||
/// Takes a [Polygon] and returns [true] or [false] as to whether it is concave | ||
/// or not. | ||
/// example: | ||
/// ```dart | ||
/// var convexPolygon = Polygon(coordinates: [ | ||
/// [ | ||
/// Position.of([0, 0]), | ||
/// Position.of([0, 1]), | ||
/// Position.of([1, 1]), | ||
/// Position.of([1, 0]), | ||
/// Position.of([0, 0]) | ||
/// ] | ||
/// ]); | ||
/// booleanConcave(convexPolygon); | ||
/// //=false | ||
/// ``` | ||
bool booleanConcave(Polygon polygon) { | ||
// Taken from https://stackoverflow.com/a/1881201 & https://stackoverflow.com/a/25304159 | ||
List<List<Position>> coords = polygon.coordinates; | ||
|
||
if (coords[0].length <= 4) { | ||
return false; | ||
} | ||
|
||
var sign = false; | ||
var n = coords[0].length - 1; | ||
for (var i = 0; i < n; i++) { | ||
var dx1 = coords[0][(i + 2) % n][0]! - coords[0][(i + 1) % n][0]!; | ||
var dy1 = coords[0][(i + 2) % n][1]! - coords[0][(i + 1) % n][1]!; | ||
var dx2 = coords[0][i][0]! - coords[0][(i + 1) % n][0]!; | ||
var dy2 = coords[0][i][1]! - coords[0][(i + 1) % n][1]!; | ||
var zcrossproduct = dx1 * dy2 - dy1 * dx2; | ||
if (i == 0) { | ||
sign = zcrossproduct > 0; | ||
} else if (sign != zcrossproduct > 0) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |
Oops, something went wrong.