How to use d3-polygon - 10 common examples

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 DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
// -----------------------------------------------------------------------------

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 DefinitelyTyped / DefinitelyTyped / d3-polygon / d3-polygon-tests.ts View on Github external
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 DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
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 DefinitelyTyped / DefinitelyTyped / d3-polygon / d3-polygon-tests.ts View on Github external
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 DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
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 DefinitelyTyped / DefinitelyTyped / types / d3-polygon / d3-polygon-tests.ts View on Github external
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 Kcnarf / d3-voronoi-map / src / d3-voronoi-map.js View on Github external
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);

d3-polygon

Operations for two-dimensional polygons.

ISC
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis