Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public partialSort(arr: Uint32Array, compare: (x: number, y: number) => number, num: number) {
const len = arr.length;
// no point to use quick select if num of elements to be selected is greater than half of the length
if (num >= len / 2) {
arr.sort(compare);
} else {
quickselect(arr, num, 0, len - 1, compare);
const slc = arr.slice(0, num).sort(compare);
for (let i = 0; i < num; i++) arr[i] = slc[i];
}
}
if (polygon) polygons.push(polygon);
polygon = [rings[i]];
} else {
// @ts-ignore
polygon.push(rings[i]);
}
}
if (polygon) polygons.push(polygon);
// Earcut performance degrages with the # of rings in a polygon. For this
// reason, we limit strip out all but the `maxRings` largest rings.
if (maxRings > 1) {
for (let j = 0; j < polygons.length; j++) {
if (polygons[j].length <= maxRings) continue;
quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
polygons[j] = polygons[j].slice(0, maxRings);
}
}
return polygons;
}
if (ccw === area < 0) {
if (polygon) polygons.push(polygon);
polygon = [rings[i]];
} else {
(polygon: any).push(rings[i]);
}
}
if (polygon) polygons.push(polygon);
// Earcut performance degrades with the # of rings in a polygon. For this
// reason, we limit strip out all but the `maxRings` largest rings.
if (maxRings > 1) {
for (let j = 0; j < polygons.length; j++) {
if (polygons[j].length <= maxRings) continue;
quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
polygons[j] = polygons[j].slice(0, maxRings);
}
}
return polygons;
}
function multiSelect(arr, left, right, n, compare) {
const stack = [left, right];
while (stack.length) {
right = stack.pop();
left = stack.pop();
if (right - left <= n) continue;
const mid = left + Math.ceil((right - left) / n / 2) * n;
quickselect(arr, mid, left, right, compare);
stack.push(left, mid, mid, right);
}
}