How to use the d3-polygon.polygonLength 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
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 / AutoMorph.ts View on Github external
function addPoints(ring: Ring, numPoints: number) {
  const desiredLength = ring.length + numPoints;
  const step = polygonLength(ring) / numPoints;
  let i = 0;
  let cursor = 0;
  let insertAt = step / 2;
  while (ring.length < desiredLength) {
    const a = ring[i];
    const b = ring[(i + 1) % ring.length];
    const segment = MathUtil.distance(a, b);
    if (insertAt <= cursor + segment) {
      const p = segment ? MathUtil.lerp(a, b, (insertAt - cursor) / segment) : [...a] as Point;
      ring.splice(i + 1, 0, p);
      insertAt += step;
      continue;
    }
    cursor += segment;
    i++;
  }
github veltman / flubber / src / add.js View on Github external
export function addPoints(ring, numPoints) {
  const desiredLength = ring.length + numPoints,
    step = polygonLength(ring) / numPoints;

  let i = 0,
    cursor = 0,
    insertAt = step / 2;

  while (ring.length < desiredLength) {
    let a = ring[i],
      b = ring[(i + 1) % ring.length],
      segment = distance(a, b);

    if (insertAt <= cursor + segment) {
      ring.splice(
        i + 1,
        0,
        segment ? pointAlong(a, b, (insertAt - cursor) / segment) : a.slice(0)
      );
github alexjlockwood / ShapeShifter / src / app / scripts / algorithms / Add.ts View on Github external
export function addPoints(ring: Ring, numPoints: number, maxLength = Infinity) {
  const desiredLength = ring.length + numPoints;
  const step = polygonLength(ring) / numPoints;

  let i = 0;
  let cursor = 0;
  let insertAt = step / 2;

  while (ring.length < desiredLength) {
    const a = ring[i];
    const b = ring[(i + 1) % ring.length];
    const segment = distance(a, b);

    if (insertAt <= cursor + segment) {
      ring.splice(
        i + 1,
        0,
        segment ? pointAlong(a, b, (insertAt - cursor) / segment) : a.slice(0) as Point,
      );
github veltman / flubber / src / shape.js View on Github external
return function(ring) {
    let centroid = polygonCentroid(ring),
      perimeter = polygonLength([...ring, ring[0]]),
      startingAngle = Math.atan2(
        ring[0][1] - centroid[1],
        ring[0][0] - centroid[0]
      ),
      along = 0;

    if (startingAngle < 0) {
      startingAngle = 2 * Math.PI + startingAngle;
    }

    let startingProgress = startingAngle / (2 * Math.PI);

    return ring.map((point, i) => {
      if (i) {
        along += distance(point, ring[i - 1]);
      }

d3-polygon

Operations for two-dimensional polygons.

ISC
Latest version published 3 years ago

Package Health Score

71 / 100
Full package analysis