dufour-peyton-intersection
Version:
Reference Implementation of the Dufour-Peyton Intersection Algorithm. Calculates the Intersections of Arbitrary Polygons with a Geospatial Raster.
24 lines (20 loc) • 514 B
JavaScript
;
module.exports = function cluster(items, newClusterTest) {
try {
const numberOfItems = items.length;
const clusters = [];
let cluster = [];
for (let i = 0; i < numberOfItems; i++) {
const item = items[i];
cluster.push(item);
if (newClusterTest(item)) {
clusters.push(cluster);
cluster = [];
}
}
if (cluster.length > 0) clusters.push(cluster);
return clusters;
} catch (error) {
console.error("[cluster]:", error);
}
};