0.10.0 • Published 8 months ago

earclip v0.10.0

Weekly downloads
85
License
BSD-3-Clause
Repository
github
Last release
8 months ago

earclip npm downloads bundlephobia JavaScript Style Guide

About

The fastest and smallest JavaScript polygon triangulation library with builtin tesselation. 2.9 kB minified and gzipped.

Install

# NPM
npm install earcut
# PNPM
pnpm add earcut
# Yarn
yarn add earcut

The Algorithm

The library implements a modified ear slicing algorithm, optimized by z-order curve hashing and extended to handle holes, twisted polygons, degeneracies and self-intersections in a way that doesn't guarantee correctness of triangulation, but attempts to always produce acceptable results for practical data.

It's based on ideas from FIST: Fast Industrial-Strength Triangulation of Polygons by Martin Held and Triangulation by Ear Clipping by David Eberly.

Why another triangulation library?

The aim of this project is to create a JS triangulation library that is fast enough for real-time triangulation in the browser, sacrificing triangulation quality for raw speed and simplicity, while being robust enough to handle most practical datasets without crashing or producing garbage. Some benchmarks using Node 0.12:

(ops/sec)ptsearcutlibtesspoly2tripnltripolyk
OSM building15795,93550,64061,501122,966175,570
dude shape9435,65810,3398,78411,17213,557
holed dude shape10428,3198,8837,4942,130n/a
complex OSM water252354377.54failurefailuren/a
huge OSM water56679529.30failurefailuren/a

If you want to get correct triangulation even on very bad data with lots of self-intersections and earcut is not precise enough, take a look at libtess.js.

Usage

import { earclip } from 'earclip'

const poly = [[[3506,-2048],[7464,402],[-2048,2685],[-2048,-2048],[3506,-2048]],[[-2048,-37],[1235,747],[338,-1464],[-116,-1188],[-2048,-381],[-2048,-37]],[[-1491,-1981],[-1300,-1800],[-1155,-1981],[-1491,-1981]]]
const modulo = 8192 / 2

const res = earclip(poly, modulo)
console.log(res)
0.10.0

8 months ago

0.9.8

10 months ago

0.9.0

3 years ago

0.9.2

3 years ago

0.9.1

3 years ago

0.9.3

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.0

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.6.1

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.4

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.4.2

4 years ago

0.3.18

4 years ago

0.3.17

4 years ago

0.3.16

4 years ago

0.3.15

4 years ago

0.3.14

4 years ago

0.3.13

4 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

5 years ago

0.3.9

5 years ago

0.3.8

5 years ago

0.3.7

5 years ago

0.3.6

5 years ago

0.3.4

5 years ago

0.3.3

5 years ago

0.3.1

5 years ago

0.2.9

5 years ago

0.2.7

5 years ago

0.2.6

5 years ago

0.2.5

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.0

5 years ago