-
Notifications
You must be signed in to change notification settings - Fork 943
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-disjoint
#805
Conversation
const {name} = path.parse(filepath); | ||
const geojson = load.sync(filepath); | ||
const [feature1, feature2] = geojson.features; | ||
suite.add(name, () => disjoint(feature1, feature2)); |
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.
A new benchmark technique we've been adding is the Single process results by adding console.time
& console.timeEnd
before the suite.add
.
Example
console.time(name);
disjoint(feature1, feature2);
console.timeEnd(name);
suite.add(name, () => disjoint(feature1, feature2));
case 'Point': | ||
switch (type2) { | ||
case 'Point': | ||
return !compareCoords(coords1, coords2) || false; |
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.
Not too sure if || false
is necessary?
If compareCoords
only outputs true/false
then if the result is false
it would fallback again on false
.
I'll look into this, but I'm pretty sure || false
can be dropped.
} | ||
|
||
// /** | ||
// * Is Polygon (geom1) in Polygon (geom2) |
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.
// /**
// *
Double commented?
const [feature1, feature2] = geojson.features; | ||
const result = disjoint(feature1, feature2); | ||
|
||
if (process.env.SHAPELY) shapely.disjoint(feature1, feature2).then(result => t.true(result, '[true] shapely - ' + name)); |
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.
Woot! 👍 Did this work for you @rowanwins ? (It does for me)
- Drop `|| false` from `index.js` - Remove extra comments - Add single process benchmark
Updates to
|
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 to me, we can always add more test cases to improve it in the future.
@stebogit @rowanwins I've organized/grouped the test fixtures, let me know what you think about it. Example: LineString (Feature1) => Point (Feature2)
|
@rowanwins I've refactored module.exports = function (feature1, feature2) {
var boolean;
flattenEach(feature1, function (flatten1) {
flattenEach(feature2, function (flatten2) {
if (boolean === false) return false;
boolean = disjoint(flatten1.geometry, flatten2.geometry);
});
});
return boolean;
}; This way you only need to focus on support the basic geometries. /**
* Disjoint operation for simple Geometries (Point/LineString/Polygon)
*
* @private
* @param {Geometry<any>} geom1 GeoJSON Geometry
* @param {Geometry<any>} geom2 GeoJSON Geometry
* @returns {Boolean} true/false
*/
function disjoint(geom1, geom2) { |
if (dxl > 0) { | ||
return LineSegmentStart[0] <= Point[0] && Point[0] <= LineSegmentEnd[0]; | ||
} else { | ||
return LineSegmentEnd[0] <= Point[0] && Point[0] <= LineSegmentStart[0]; |
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.
@rowanwins Any thoughts how to hit these lines (146 & 151) with Test Fixtures?
$ tap test.js --coverage
test.js ............................................. 74/74
total ............................................... 74/74
74 passing (4s)
ok
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
All files | 96.36 | 85 | 100 | 96.3 | |
index.js | 96.36 | 85 | 100 | 96.3 | 146,151 |
----------|----------|----------|----------|----------|----------------|
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.
Put it into a seperate module and test that module 😀
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.
Where does this source code come from?
Lack of comments is hard to troubleshoot.
@turf/boolean-disjoint
New Module
@turf/boolean-disjoint
Geometry Support
JSDocs
npm test
at the sub modules where changes have occurred.npm run lint
to ensure code style at the turf module level.Submitting a new TurfJS Module.
./scripts/generate-readmes
to createREADME.md
.package.json
using "Full Name <@github Username>".Gday @DenisCarriere
The boolean beast continues! Disjoint returns 1 or t (TRUE) if the intersection of the two geometries is an empty set. In other words, geometries are disjoint if they do not intersect one another.
Think this one is a fair bit more straight forward so hopefully we're all good.