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 75 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)
5 changes: 4 additions & 1 deletion analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
include: package:dartclub_lint/dart.yaml

linter:
rules:
# always_declare_return_types: true
analyzer:
errors:
prefer_generic_function_type_aliases: error
prefer_generic_function_type_aliases: error
36 changes: 36 additions & 0 deletions lib/src/booleans/boolean_clockwise.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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.
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
/// 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)
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
/// //=true
/// booleanClockwise(counterClockwiseRing)
/// //=false
/// ```
bool booleanClockwise(dynamic line) {
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
if (line is List) {
if (line is! List<Position>) {
throw UnsupportedError(" type $line is not supperted");
}
}
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
var ring = getCoords(line);
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;
}
41 changes: 41 additions & 0 deletions lib/src/booleans/boolean_concave.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import 'package:turf/helpers.dart';

/// Takes a [Polygon] and returns true or false as to whether it is concave or not.
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
/// 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)
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
/// //=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;
}
206 changes: 206 additions & 0 deletions lib/src/booleans/boolean_contains.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
import 'package:turf/turf.dart';

import 'boolean_point_in_polygon.dart';
import 'boolean_point_on_line.dart';

/// Boolean-contains returns True if the second geometry is completely contained
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
/// by the first geometry.
/// The interiors of both geometries must intersect and, the interior and
/// boundary of the secondary must not intersect the exterior of the primary.
/// Boolean-contains returns the exact opposite result of the `turf/boolean-within`.
/// example:
/// ```dart
/// var line = LineString(coordinates: [Position.of([1, 1]), Position.of([1, 2]), Position.of([1, 3]), Position.of([1, 4])]);
/// var point = Point(cooridantes:Position.of([1, 2]));
/// booleanContains(line, point);
/// //=true
/// ```
bool booleanContains(GeoJSONObject feature1, GeoJSONObject feature2) {
var geom1 = feature1 is Feature ? feature1.geometry : feature1;
var geom2 = feature2 is Feature ? feature2.geometry : feature2;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved

var coords1 = (geom1 as GeometryType).coordinates;
var coords2 = (geom2 as GeometryType).coordinates;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
Exception exception() =>
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
Exception("{feature2 $geom2 geometry not supported}");
if (geom1 is Point) {
if (geom2 is Point) {
return compareCoords(coords1, coords2);
} else {
throw exception();
}
} else if (geom1 is MultiPoint) {
if (geom2 is Point) {
return isPointInMultiPoint(geom1, geom2);
} else if (geom2 is MultiPoint) {
return isMultiPointInMultiPoint(geom1, geom2);
} else {
throw exception();
}
} else if (geom1 is LineString) {
if (geom2 is Point) {
return booleanPointOnLine(geom2, geom1, ignoreEndVertices: true);
} else if (geom2 is LineString) {
return isLineOnLine(geom1, geom2);
} else if (geom2 is MultiPoint) {
return isMultiPointOnLine(geom1, geom2);
} else {
throw exception();
}
} else if (geom1 is Polygon) {
if (geom2 is Point) {
return booleanPointInPolygon((geom2).coordinates, geom1,
ignoreBoundary: true);
} else if (geom2 is LineString) {
return isLineInPoly(geom1, geom2);
} else if (geom2 is Polygon) {
return isPolyInPoly(geom1, geom2);
} else if (geom2 is MultiPoint) {
return isMultiPointInPoly(geom1, geom2);
} else {
throw exception();
}
} else {
throw exception();
}
}

bool isPointInMultiPoint(MultiPoint multiPoint, Point pt) {
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
int i;
var output = false;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
for (i = 0; i < multiPoint.coordinates.length; i++) {
if (compareCoords(multiPoint.coordinates[i], pt.coordinates)) {
output = true;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
break;
}
}
return output;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
}

bool isMultiPointInMultiPoint(MultiPoint multiPoint1, MultiPoint multiPoint2) {
for (var coord2 in multiPoint2.coordinates) {
var matchFound = false;
for (var coord1 in multiPoint1.coordinates) {
if (compareCoords(coord2, coord1)) {
matchFound = true;
break;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
}
}
if (!matchFound) {
return false;
}
}
return true;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
}

bool isMultiPointOnLine(LineString lineString, MultiPoint multiPoint) {
var haveFoundInteriorPoint = false;
for (var coord in multiPoint.coordinates) {
if (booleanPointOnLine(Point(coordinates: coord), lineString,
ignoreEndVertices: true)) {
haveFoundInteriorPoint = true;
}
if (!booleanPointOnLine(Point(coordinates: coord), lineString)) {
return false;
}
}
return haveFoundInteriorPoint;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
}

bool isMultiPointInPoly(Polygon polygon, MultiPoint multiPoint) {
for (var coord in multiPoint.coordinates) {
if (!booleanPointInPolygon(coord, polygon, ignoreBoundary: true)) {
return false;
}
}
return true;
}

bool isLineOnLine(LineString lineString1, LineString lineString2) {
var haveFoundInteriorPoint = false;
for (var coords in lineString2.coordinates) {
if (booleanPointOnLine(
Point(coordinates: coords),
lineString1,
ignoreEndVertices: true,
)) {
haveFoundInteriorPoint = true;
}
if (!booleanPointOnLine(
Point(coordinates: coords),
lineString1,
ignoreEndVertices: false,
)) {
return false;
}
}
return haveFoundInteriorPoint;
}
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved

bool isLineInPoly(Polygon polygon, LineString linestring) {
var output = false;
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
var i = 0;

var polyBbox = bbox(polygon);
var lineBbox = bbox(linestring);
if (!doBBoxOverlap(polyBbox, lineBbox)) {
return false;
}
for (i; i < linestring.coordinates.length - 1; i++) {
var midPoint =
getMidpoint(linestring.coordinates[i], linestring.coordinates[i + 1]);
if (booleanPointInPolygon(
midPoint,
polygon,
ignoreBoundary: true,
)) {
output = true;
break;
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
}
}
return output;
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
}

/// Is Polygon2 in Polygon1
/// Only takes into account outer rings
bool isPolyInPoly(GeoJSONObject geom1, GeoJSONObject geom2) {
var poly1Bbox = bbox(geom1);
var poly2Bbox = bbox(geom2);
if (!doBBoxOverlap(poly1Bbox, poly2Bbox)) {
return false;
}

for (var ring in (geom2 as GeometryType).coordinates) {
for (var coord in ring) {
if (!booleanPointInPolygon(coord, geom1)) {
return false;
}
}
}
return true;
}
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved

bool doBBoxOverlap(BBox bbox1, BBox bbox2) {
if (bbox1[0]! > bbox2[0]!) {
return false;
}
if (bbox1[2]! < bbox2[2]!) {
return false;
}
if (bbox1[1]! > bbox2[1]!) {
return false;
}
if (bbox1[3]! < bbox2[3]!) {
return false;
}
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
return true;
}

bool compareCoords(Position pair1, Position pair2) {
return pair1[0] == pair2[0] && pair1[1] == pair2[1];
armantorkzaban marked this conversation as resolved.
Show resolved Hide resolved
}

Position getMidpoint(Position pair1, Position pair2) {
return Position.of(
[(pair1[0]! + pair2[0]!) / 2, (pair1[1]! + pair2[1]!) / 2]);
}
lukas-h marked this conversation as resolved.
Show resolved Hide resolved
Loading