@types/earcut
TypeScript definitions for earcut
Last updated a year ago by types .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @types/earcut 
SYNC missed versions from official npm registry.

Installation

npm install --save @types/earcut

Summary

This package contains type definitions for earcut (https://github.com/mapbox/earcut#readme).

Details

Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/earcut.

index.d.ts

/**
 * Triangulate an outline.
 *
 * @param vertices A flat array of vertice coordinates like [x0,y0, x1,y1, x2,y2, ...].
 * @param holes An array of hole indices if any (e.g. [5, 8] for a 12-vertice input would mean one hole with vertices 5–7 and another with 8–11).
 * @param dimensions The number of coordinates per vertice in the input array (2 by default).
 * @return A flat array with each group of three numbers indexing a triangle in the `vertices` array.
 * @example earcut([10,0, 0,50, 60,60, 70,10]); // returns [1,0,3, 3,2,1]
 * @example with a hole: earcut([0,0, 100,0, 100,100, 0,100,  20,20, 80,20, 80,80, 20,80], [4]); // [3,0,4, 5,4,0, 3,4,7, 5,0,1, 2,3,7, 6,5,1, 2,7,6, 6,1,2]
 * @example with 3d coords: earcut([10,0,1, 0,50,2, 60,60,3, 70,10,4], null, 3); // [1,0,3, 3,2,1]
 */
export default function earcut(vertices: ArrayLike<number>, holes?: ArrayLike<number>, dimensions?: number): number[];

/**
 * Transforms multi-dimensional array (e.g. GeoJSON Polygon) into the format expected by earcut.
 * @example Transforming GeoJSON data.
 *     const data = earcut.flatten(geojson.geometry.coordinates);
 *     const triangles = earcut(data.vertices, data.holes, data.dimensions);
 * @example Transforming simple triangle with hole:
 *     const data = earcut.flatten([[[0, 0], [100, 0], [0, 100]], [[10, 10], [0, 10], [10, 0]]]);
 *     const triangles = earcut(data.vertices, data.holes, data.dimensions);
 * @param data Arrays of rings, with the first being the outline and the rest holes. A ring is an array points, each point being an array of numbers.
 */
export function flatten(
    data: ArrayLike<ArrayLike<ArrayLike<number>>>,
): { vertices: number[]; holes: number[]; dimensions: number };

/**
 * Returns the relative difference between the total area of triangles and the area of the input polygon. 0 means the triangulation is fully correct.
 * Used to verify correctness of triangulation
 * @param vertices same as earcut
 * @param holes same as earcut
 * @param dimensions same as earcut
 * @param triangles see return value of earcut
 * @example
 *     const triangles = earcut(vertices, holes, dimensions);
 *     const deviation = earcut.deviation(vertices, holes, dimensions, triangles);
 */
export function deviation(
    vertices: ArrayLike<number>,
    holes: ArrayLike<number> | undefined,
    dimensions: number,
    triangles: ArrayLike<number>,
): number;

Additional Details

  • Last updated: Mon, 20 Jan 2025 06:02:51 GMT
  • Dependencies: none

Credits

These definitions were written by Adrian Leonhard.

Current Tags

  • 3.0.0                                ...           latest (a year ago)
  • 2.1.0                                ...           ts2.0 (8 years ago)
  • 2.1.0                                ...           ts2.1 (8 years ago)
  • 2.1.0                                ...           ts2.2 (8 years ago)
  • 2.1.0                                ...           ts2.3 (8 years ago)
  • 2.1.0                                ...           ts2.4 (8 years ago)
  • 2.1.0                                ...           ts2.5 (8 years ago)
  • 2.1.0                                ...           ts2.6 (8 years ago)
  • 2.1.0                                ...           ts2.7 (8 years ago)
  • 2.1.0                                ...           ts2.8 (8 years ago)
  • 2.1.0                                ...           ts2.9 (8 years ago)
  • 2.1.1                                ...           ts3.0 (6 years ago)
  • 2.1.1                                ...           ts3.1 (6 years ago)
  • 2.1.1                                ...           ts3.2 (6 years ago)
  • 2.1.1                                ...           ts3.3 (6 years ago)
  • 2.1.1                                ...           ts3.4 (6 years ago)
  • 2.1.1                                ...           ts3.5 (6 years ago)
  • 2.1.1                                ...           ts3.6 (6 years ago)
  • 2.1.1                                ...           ts3.7 (6 years ago)
  • 2.1.1                                ...           ts3.8 (6 years ago)
  • 2.1.1                                ...           ts3.9 (6 years ago)
  • 2.1.1                                ...           ts4.0 (6 years ago)
  • 2.1.1                                ...           ts4.1 (6 years ago)
  • 2.1.1                                ...           ts4.2 (6 years ago)
  • 2.1.1                                ...           ts4.3 (6 years ago)
  • 2.1.1                                ...           ts4.4 (6 years ago)
  • 2.1.4                                ...           ts4.5 (2 years ago)
  • 2.1.4                                ...           ts4.6 (2 years ago)
  • 2.1.4                                ...           ts4.7 (2 years ago)
  • 2.1.4                                ...           ts4.8 (2 years ago)
  • 2.1.4                                ...           ts4.9 (2 years ago)
  • 3.0.0                                ...           ts5.0 (a year ago)
  • 3.0.0                                ...           ts5.1 (a year ago)
  • 3.0.0                                ...           ts5.2 (a year ago)
  • 3.0.0                                ...           ts5.3 (a year ago)
  • 3.0.0                                ...           ts5.4 (a year ago)
  • 3.0.0                                ...           ts5.5 (a year ago)
  • 3.0.0                                ...           ts5.6 (a year ago)
  • 3.0.0                                ...           ts5.7 (a year ago)
  • 3.0.0                                ...           ts5.8 (a year ago)
  • 3.0.0                                ...           ts5.9 (a year ago)

6 Versions

  • 3.0.0                                ...           a year ago
  • 2.1.4                                ...           2 years ago
  • 2.1.3                                ...           2 years ago
  • 2.1.2                                ...           3 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dev Dependencies (0)
None
Dependents (2)

Copyright 2013 - present © cnpmjs.org | Home |