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

Port boolean functions and tests #91

Merged
merged 91 commits into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
2288fa2
in process - early analysis of the work
armantorkzaban Apr 11, 2022
27d7b0f
Merge branch 'main' into documentation
armantorkzaban Apr 11, 2022
f83a14a
linked the meta functions in readme
armantorkzaban Apr 12, 2022
fe1c044
CONTRIBUTING.md
armantorkzaban Apr 12, 2022
501b393
links to the sources
armantorkzaban Apr 12, 2022
15a6312
edited typos
armantorkzaban Apr 12, 2022
b2d66a6
documentation work
armantorkzaban Apr 14, 2022
e3ed8d2
closes #77, closes #16
armantorkzaban Apr 14, 2022
a0dfba4
proofread
armantorkzaban Apr 14, 2022
c301657
improves pub.dev score, closes #79, #78, #75
armantorkzaban Apr 14, 2022
2a7ee7c
Merge branch 'main' into documentation
lukas-h Apr 14, 2022
a3b3d03
Added deleted model, complemented contributing.md
armantorkzaban Apr 14, 2022
820a491
booleans init
armantorkzaban Jun 7, 2022
0a53f80
initial import
armantorkzaban Jun 7, 2022
ce7a522
boolean_touches
armantorkzaban Jun 7, 2022
da25617
valid - wip
armantorkzaban Jun 8, 2022
a15a417
within - init
armantorkzaban Jun 8, 2022
e438241
rewiring the translated code
armantorkzaban Jun 9, 2022
6efe633
contains etc.
armantorkzaban Jun 9, 2022
5f91040
touches
armantorkzaban Jun 9, 2022
56c6d93
valid
armantorkzaban Jun 9, 2022
afcc3a3
dependencies imported
armantorkzaban Jun 9, 2022
526a957
before merge
armantorkzaban Jun 9, 2022
3fb7169
Merge branch 'main' into feature-booleans
armantorkzaban Jun 9, 2022
54eb36e
Update CONTRIBUTING.md
lukas-h Jun 9, 2022
a5d67bd
clockwise test
armantorkzaban Jun 14, 2022
5dbe443
concave test
armantorkzaban Jun 14, 2022
43e372a
intersect test
armantorkzaban Jun 14, 2022
698fe61
pointOnLine test
armantorkzaban Jun 14, 2022
c54a2d7
contains
armantorkzaban Jun 15, 2022
6ec1db0
crosses_test - blocked by findIntersections
armantorkzaban Jun 15, 2022
7a17d77
Merge branch 'main' into feature-booleans
armantorkzaban Jun 19, 2022
5fe7e1d
boolean_contain
armantorkzaban Jun 19, 2022
453bab2
boolean_within
armantorkzaban Jun 19, 2022
9e85551
Merge branch 'main' into feature-booleans
armantorkzaban Jun 20, 2022
e648af7
rhumb_bearing
armantorkzaban Jun 25, 2022
d2cd51d
rhumb_bearing\'s test - incomplete
armantorkzaban Jun 25, 2022
a6d91b0
rhumb_bearing's test - done, added to lib/bearing
armantorkzaban Jun 26, 2022
ace18bc
boolean_contains, boolean_parallel, IP
armantorkzaban Jun 26, 2022
ed2ec1a
working on contain - removed usages of runtimeType
armantorkzaban Jul 1, 2022
8e9f058
rewriting pointInLine
armantorkzaban Jul 1, 2022
40a9847
tests reverted to false/true folder style
armantorkzaban Jul 1, 2022
ad61bef
restructuring, clean-up
armantorkzaban Jul 3, 2022
d3541b5
clockwise and its test, documentation
armantorkzaban Jul 4, 2022
84b97f6
concave finalized
armantorkzaban Jul 4, 2022
e6d7580
PointInPolygon plus test, dart format
armantorkzaban Jul 4, 2022
db932b1
removed the commented JS lines
armantorkzaban Jul 4, 2022
a7b1ca7
return type added
armantorkzaban Jul 4, 2022
d11ff4a
disjoint and test - not done, depends on sweepline
armantorkzaban Jul 4, 2022
93a51ca
equal implement, test, has dependencies
armantorkzaban Jul 4, 2022
e2b8a1f
moving on
armantorkzaban Jul 4, 2022
454c102
clean coords init
armantorkzaban Jul 4, 2022
b64d644
cleanCoord implemented, going to new branch
armantorkzaban Jul 5, 2022
3b2722a
moving on with equal
armantorkzaban Jul 7, 2022
3ff9b3a
update turf_equality dep
lukas-h Jul 7, 2022
63a319a
Merge branch 'main' into feature-booleans
armantorkzaban Jul 7, 2022
5c863e0
moving forward
armantorkzaban Jul 7, 2022
29ff2b8
refactors boolean_equal
armantorkzaban Jul 8, 2022
65eddf8
#88 crosses, disjoint, equal, intersects, pip @lukas-h
armantorkzaban Aug 29, 2022
8c912f6
cleanup on #88
armantorkzaban Aug 30, 2022
c45a922
progress on overlap
armantorkzaban Aug 30, 2022
29dd77b
bool: overlap,parallel,valid,touches & lineOverlap
armantorkzaban Aug 30, 2022
2656017
issue with test is worked on
armantorkzaban Aug 31, 2022
2a59e67
still at porting the overlap test
armantorkzaban Aug 31, 2022
f8ebffd
done: parallel
armantorkzaban Aug 31, 2022
349bab8
working on valid
armantorkzaban Aug 31, 2022
e4c929b
touches done
armantorkzaban Sep 1, 2022
55bbe3c
valid - got stuck
armantorkzaban Sep 1, 2022
01e860b
progress on within
armantorkzaban Sep 1, 2022
e6792c6
moved on with valid, refactored
armantorkzaban Sep 5, 2022
88677c2
valid test
armantorkzaban Sep 5, 2022
e88c9e9
lineIntersection testet - contains sweepline
armantorkzaban Sep 5, 2022
63ce12d
package publishabe, rm git deps, fix equality dep
lukas-h Sep 5, 2022
ad47ac4
update params in equality
lukas-h Sep 5, 2022
775f0ee
mod. on valid to cover the std. - MutiPs' 'finite'
armantorkzaban Sep 7, 2022
7b61f7f
RFCs resolved - readied for merge
armantorkzaban Sep 10, 2022
3baae8b
return type of getGeom
armantorkzaban Sep 10, 2022
c783bec
linter effect!
armantorkzaban Sep 10, 2022
7a8d0ba
reolved requests
armantorkzaban Sep 10, 2022
1589d98
more requests resolved
armantorkzaban Sep 10, 2022
73c26fe
more requests resolved
armantorkzaban Sep 10, 2022
41a7327
Merge branch 'main' into feature-booleans
lukas-h Sep 11, 2022
32c0593
Merge branch 'feature-booleans' of github.com:dartclub/turf_dart into…
armantorkzaban Sep 11, 2022
fdd34d2
test name, touching lineOverlap
armantorkzaban Sep 11, 2022
f0e83d4
fix conversations in booleanContains
lukas-h Sep 11, 2022
59d452f
fixes conversations in crosses and disjoint
lukas-h Sep 11, 2022
2ac6308
resolves allllllllll outdated conversations, refactor
lukas-h Sep 11, 2022
8f06118
use getGeom in booleanTouches
lukas-h Sep 11, 2022
0c7dc79
use getGeom more frequently
lukas-h Sep 11, 2022
955c015
rm linter rule, which is already inherited from dartclub_lint
lukas-h Sep 11, 2022
2306c59
cleanup, ready for merge
lukas-h Sep 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 37 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down Expand Up @@ -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)
33 changes: 19 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Most of the implementation is a direct translation from [turf.js](https://github
- Get the [Dart tools](https://dart.dev/tools)
- Install the library with `dart pub add turf`
- 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 All @@ -36,7 +37,7 @@ Feature<Polygon> poly = Feature<Polygon>(
]),
);

main() {
void main() {
var total = segmentReduce<int>(
poly,
(previousValue, currentSegment, initialValue, featureIndex,
Expand Down Expand Up @@ -145,7 +146,7 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [ ] kinks
- [ ] lineArc
- [ ] lineChunk
- [ ] lineIntersect
- [ ] [lineIntersect](https://github.com/dartclub/turf_dart/blob/main/lib/src/line_intersect.dart)
- [ ] lineOverlap
- [x] [lineSegment](https://github.com/dartclub/turf_dart/blob/main/lib/src/line_segment.dart)
- [ ] lineSlice
Expand Down Expand Up @@ -207,8 +208,6 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [x] [featureReduce](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/feature.dart)
- [x] [flattenEach](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/flatten.dart)
- [x] [flattenReduce](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/flatten.dart)
- [x] [getCoord](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/coord.dart)
- [x] [getCoords](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/coord.dart)
- [x] [geomEach](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/geom.dart)
- [x] [geomReduce](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/geom.dart)
- [x] [propEach](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/prop.dart)
Expand All @@ -219,19 +218,25 @@ Any new benchmarks must be named `*_benchmark.dart` and reside in the
- [x] [clusterEach](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/cluster.dart)
- [x] [clusterReduce](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/cluster.dart)

### Invariants

- [x] [getCoord](https://github.com/dartclub/turf_dart/blob/main/lib/src/meta/coord.dart)
- [x] [getCoords](https://github.com/dartclub/turf_dart/blob/main/lib/src/invariant.dart)
- [x] [getGeom](https://github.com/dartclub/turf_dart/blob/main/lib/src/invariant.dart)

### Booleans

- [ ] booleanClockwise
- [ ] booleanConcave
- [ ] booleanContains
- [ ] booleanCrosses
- [ ] booleanDisjoint
- [ ] booleanEqual
- [ ] booleanIntersects
- [x] [booleanClockwise](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_clockwise.dart)
- [x] [booleanConcave](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_concave.dart)
- [x] [booleanContains](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_contains.dart)
- [x] [booleanCrosses](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_crosses.dart)
- [x] [booleanDisjoint](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_disjoint.dart)
- [x] [booleanEqual](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_equal.dart)
- [x] [booleanIntersects](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_intersect.dart)
- [ ] booleanOverlap
- [ ] booleanParallel
- [ ] booleanPointInPolygon
- [ ] booleanPointOnLine
- [x] [booleanParallel](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_parallel.dart)
- [x] [booleanPointInPolygon](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_point_in_polygon.dart)
- [x] [booleanPointOnLine](https://github.com/dartclub/turf_dart/blob/main/lib/src/booleans/boolean_point_on_line.dart)
- [ ] booleanWithin

### Unit Conversion
Expand Down
2 changes: 1 addition & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ include: package:dartclub_lint/dart.yaml

analyzer:
errors:
prefer_generic_function_type_aliases: error
prefer_generic_function_type_aliases: error
2 changes: 1 addition & 1 deletion benchmark/area_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Feature<Polygon> poly = Feature<Polygon>(
]),
);

main() {
void main() {
group('area', () {
benchmark('simple', () {
area(poly);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/explode_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var poly = Polygon(coordinates: [
],
]);

main() {
void main() {
group('explode', () {
benchmark('simple', () {
explode(poly);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/polygon_smooth_benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:benchmark/benchmark.dart';
import 'package:turf/polygon_smooth.dart';
import 'package:turf/turf.dart';

main() {
void main() {
group("turf-polygon-smooth", () {
var inDir = Directory('./test/examples/polygonSmooth/in');
for (var file in inDir.listSync(recursive: true)) {
Expand Down
2 changes: 1 addition & 1 deletion example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Feature<Polygon> poly = Feature<Polygon>(
]),
);

main() {
void main() {
var total = segmentReduce<int>(
poly,
(previousValue, currentSegment, initialValue, featureIndex,
Expand Down
47 changes: 47 additions & 0 deletions lib/src/booleans/boolean_clockwise.dart
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;
}
42 changes: 42 additions & 0 deletions lib/src/booleans/boolean_concave.dart
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;
}
Loading