-
Notifications
You must be signed in to change notification settings - Fork 934
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
New module @turf/boolean-overlaps
#856
Conversation
@stebogit Couldn't we also support |
The definition looks good, however if we did support all Geometry Types then it would look something like this: /// <reference types="geojson" />
type Feature = GeoJSON.Feature<any> | GeoJSON.GeometryObject
/**
* http://turfjs.org/docs/#boolean-overlaps
*/
declare function overlaps(feature1: Feature, feature2: Feature): boolean;
declare namespace overlaps { }
export = overlaps; |
* @param {Array<Array<number>>} line2 array of a segment coordinates | ||
* @returns {boolean} segments intersect | ||
*/ | ||
function doSegmentsIntersect(line1, line2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this be replaced with @turf/line-intersects
? The module goes really fast if you only provide 2 vertex line segments.
https://github.com/Turfjs/turf/blob/master/packages/turf-line-intersect/index.js#L85
* @param {Array<Array<number|Array<number>>>} ring2 array of a LineString coordinates | ||
* @returns {boolean} lines intersect | ||
*/ | ||
function doLinesIntersect(ring1, ring2) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should build a segmentEach
& segmentReduce
module in @turf/meta
for iterating over line segments. (most logic can be pulled from @turf/line-segment
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, segmentEach
& segmentReduce
is now available in PR #863.
You can use it right now (after PR merged) by using lerna bootstrap
on an updated branch.
|
||
// This looks completely stupid ridiculous to have so many nested loops, but it supports | ||
// multipolygons nicely. In the case of polygons or linestrings, the outer loops are only one iteration. | ||
return coords1.some(function (rings1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have flattenEach
which solves this "stupid ridiculous" pattern 😝 (pulling directly from comment above).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of this source code could be replaced with existing modules:
-
@turf/line-intersect
-
@turf/meta
=>flattenEach
-
Also to include
Point
&MultiPoint
support would be ideal. -
Change name to
@turf/boolean-overlap
(drop the S)
Since this is one of the DE-9IM modules, we should use the same naming convention http://edndoc.esri.com/arcsde/9.0/general_topics/understand_spatial_relations.htm @rowanwins had already started working on this in the past, might be worth including some of his test cases (PR #707 & turf/packages/boolean-overlap). |
👍 great idea!
correct? I'll implement the changes you suggested using the available modules.
Sure thing |
@stebogit You are spot on #856 (comment) 👍 |
Gday @stebogit For verifying scenarios it's also worth using @DenisCarriere handy |
Thanks @rowanwins for sharing, that |
@DenisCarriere @rowanwins
Shall I implement this behavior? |
Gday @stebogit Yep to aim is to follow the implementation provided by those guidelines. If in doubt about how the rules play out check the scenarios against shapely. |
- added equal check; - updated tests; - updated bench; - updated types;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks good
Solves #286.
@DenisCarriere can you please take a look at the Typescript file?
Thanks @tcql for the great job! 👍
To-Do:
Point
&MultiPoint
index.d.ts
@turf/line-intersects
,segmentEach
,flattenEach
@turf/boolean-overlap