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);
// -----------------------------------------------------------------------------
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);
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);
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);
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);
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);
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;
}
function adaptPositions(polygons, flickeringMitigationRatio) {
var newMapPoints = [],
flickeringInfluence = 0.5;
var flickeringMitigation, d, polygon, mapPoint, centroid, dx, dy;
flickeringMitigation = flickeringInfluence * flickeringMitigationRatio;
d = 1 - flickeringMitigation; // in [0.5, 1]
for (var i = 0; i < siteCount; i++) {
polygon = polygons[i];
mapPoint = polygon.site.originalObject;
centroid = d3PolygonCentroid(polygon);
dx = centroid[0] - mapPoint.x;
dy = centroid[1] - mapPoint.y;
//begin: handle excessive change;
dx *= d;
dy *= d;
//end: handle excessive change;
mapPoint.x += dx;
mapPoint.y += dy;
newMapPoints.push(mapPoint);
}
handleOverweighted(newMapPoints);