Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// -----------------------------------------------------------------------------
// Preparatory Steps
// -----------------------------------------------------------------------------
let num: number;
let containsFlag: boolean;
let point: [number, number] = [15, 15];
let polygon: Array<[number, number]> = [[10, 10], [20, 20], [10, 30]];
let pointArray: Array<[number, number]> = [[10, 10], [20, 20], [10, 30], [15, 15]];
let hull: Array<[number, number]>;
// -----------------------------------------------------------------------------
// Tests
// -----------------------------------------------------------------------------
num = d3Polygon.polygonArea(polygon);
point = d3Polygon.polygonCentroid(polygon);
hull = d3Polygon.polygonHull(pointArray);
containsFlag = d3Polygon.polygonContains(polygon, point);
num = d3Polygon.polygonLength(polygon);
const slug = p[0] < p[1] ? p.join(',') : p[1] + ',' + p[0];
const coordinates = p.map(pointIndex => ring[pointIndex]) as [Point, Point];
if (slug in arcIndices) {
// tslint:disable: no-bitwise
geometry.push(~arcIndices[slug]);
} else {
arcIndices[slug] = arcs.length;
geometry.push(arcs.length);
arcs.push(coordinates);
}
});
geometries.push({
type: 'Polygon',
area: Math.abs(polygonArea(triangle.map(d => ring[d[0]]))),
arcs: [geometry as [number, number, number]],
});
});
function normalizeRing(pathStr: string, maxSegmentLength: number) {
const { ring, skipSplit } = pathStringToRing(pathStr, maxSegmentLength);
const points = [...ring];
const samePointFn = (a: Point, b: Point) => MathUtil.distance(a, b) < 1e-9;
if (points.length > 1 && samePointFn(points[0], points[points.length - 1])) {
points.pop();
}
if (points.length < 3) {
throw new TypeError('Polygons must have at least three points');
}
const area = polygonArea(points);
if (area > 0) {
// Make all rings clockwise.
points.reverse();
}
if (!skipSplit && maxSegmentLength && _.isFinite(maxSegmentLength) && maxSegmentLength > 0) {
splitRing(points, maxSegmentLength);
}
return points;
}
triangle.forEach((arc, i) => {
const slug = arc[0] < arc[1] ? arc.join(',') : arc[1] + ',' + arc[0],
coordinates = arc.map(pointIndex => ring[pointIndex]);
if (slug in arcIndices) {
geometry.push(~arcIndices[slug]);
} else {
geometry.push((arcIndices[slug] = topology.arcs.length));
topology.arcs.push(coordinates);
}
});
topology.objects.triangles.geometries.push({
type: 'Polygon',
area: Math.abs(polygonArea(triangle.map(d => ring[d[0]]))),
arcs: [geometry],
});
});
function initializeSimulation() {
//begin: handle algorithm's variants
setHandleOverweighted();
//end: handle algorithm's variants
siteCount = data.length;
totalArea = Math.abs(d3PolygonArea(weightedVoronoi.clip()));
areaErrorTreshold = convergenceRatio * totalArea;
flickeringMitigation.clear().totalArea(totalArea);
iterationCount = 0;
converged = false;
polygons = initialize(data, simulation);
ended = false;
shouldInitialize = false;
}
function computeAreaError(polygons) {
//convergence based on summation of all sites current areas
var areaErrorSum = 0;
var polygon, mapPoint, currentArea;
for (var i = 0; i < siteCount; i++) {
polygon = polygons[i];
mapPoint = polygon.site.originalObject;
currentArea = d3PolygonArea(polygon);
areaErrorSum += Math.abs(mapPoint.targetedArea - currentArea);
}
return areaErrorSum;
}