Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const simple_intersect = function (A_Vs2d, B_Vs2d) {
// find 2d intersection of two polygons each specified as list of 2d vertices.
try {
// martinez lib expects geojson multi-path polygon which uses repeated final vertices.
const A_Vs2d_ = A_Vs2d.concat([A_Vs2d[0]]);
const B_Vs2d_ = B_Vs2d.concat([B_Vs2d[0]]);
const result = martinez.intersection([A_Vs2d_], [B_Vs2d_]);
// assume simple intersection structure
// take 1st polygon, 1st path, drop last repeated vertex
if (result.length > 0 && result[0].length > 0) {
return result[0][0].slice(0, result[0][0].length);
} else {
return [];
}
} catch (e) { // catch rare errors
console.log(e);
return [];
}
}
function intersect(poly1, poly2) {
var geom1 = getGeom(poly1);
var geom2 = getGeom(poly2);
var properties = poly1.properties || {};
// Return null if geometry is too narrow in coordinate precision
// fixes topology errors with JSTS
// https://github.com/Turfjs/turf/issues/463
// https://github.com/Turfjs/turf/pull/1004
// if (cleanCoords(truncate(geom2, {precision: 4})).coordinates[0].length < 4) return null;
// if (cleanCoords(truncate(geom1, {precision: 4})).coordinates[0].length < 4) return null;
var intersection = martinez.intersection(geom1.coordinates, geom2.coordinates);
if (intersection === null || intersection.length === 0) return null;
if (intersection.length === 1) return polygon(intersection[0], properties);
else return multiPolygon(intersection, properties);
}
export default function intersect<p>(
poly1: Feature</p>