mirror of
https://github.com/Turfjs/turf.git
synced 2025-12-08 20:26:16 +00:00
* Improve boolean-intersects docs * Improving boolean-intersects docs * adding boolean-intersects to documentation.yml * moved addtomap to end and colored markers --------- Co-authored-by: James Beard <james@smallsaucepan.com>
46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { Feature, Geometry } from "geojson";
|
|
import { booleanDisjoint } from "@turf/boolean-disjoint";
|
|
import { flattenEach } from "@turf/meta";
|
|
|
|
/**
|
|
* Boolean-intersects returns (TRUE) if the intersection of the two geometries is NOT an empty set.
|
|
*
|
|
* @name booleanIntersects
|
|
* @param {Geometry|Feature<any>} feature1 GeoJSON Feature or Geometry
|
|
* @param {Geometry|Feature<any>} feature2 GeoJSON Feature or Geometry
|
|
* @returns {boolean} true/false
|
|
* @example
|
|
* var point1 = turf.point([2, 2]);
|
|
* var point2 = turf.point([1, 2]);
|
|
* var line = turf.lineString([[1, 1], [1, 3], [1, 4]]);
|
|
*
|
|
* turf.booleanIntersects(line, point1);
|
|
* //=false
|
|
*
|
|
* turf.booleanIntersects(line, point2);
|
|
* //=true
|
|
*
|
|
* //addToMap
|
|
* var addToMap = [point1, point2, line];
|
|
* point1.properties['marker-color'] = '#f00'
|
|
* point2.properties['marker-color'] = '#0f0'
|
|
*/
|
|
function booleanIntersects(
|
|
feature1: Feature<any> | Geometry,
|
|
feature2: Feature<any> | Geometry
|
|
) {
|
|
let bool = false;
|
|
flattenEach(feature1, (flatten1) => {
|
|
flattenEach(feature2, (flatten2) => {
|
|
if (bool === true) {
|
|
return true;
|
|
}
|
|
bool = !booleanDisjoint(flatten1.geometry, flatten2.geometry);
|
|
});
|
|
});
|
|
return bool;
|
|
}
|
|
|
|
export { booleanIntersects };
|
|
export default booleanIntersects;
|