How to use the d3-polygon.polygonArea function in d3-polygon

To help you get started, we’ve selected a few d3-polygon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
// -----------------------------------------------------------------------------
// 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);
github alexjlockwood / ShapeShifter / src / app / scripts / algorithms / Triangulate.ts View on Github external
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]],
    });
  });
github alexjlockwood / ShapeShifter / src / app / scripts / algorithms / AutoMorph.ts View on Github external
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;
}
github alexjlockwood / ShapeShifter / src / app / scripts / algorithms / Topology.ts View on Github external
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],
    });
  });
github Kcnarf / d3-voronoi-map / src / d3-voronoi-map.js View on Github external
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;
  }
github Kcnarf / d3-voronoi-map / src / d3-voronoi-map.js View on Github external
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;
  }

d3-polygon

Operations for two-dimensional polygons.

ISC
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis