How to use the earcut.deviation function in earcut

To help you get started, we’ve selected a few earcut 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 maptalks / maptalks.biglayer / src / painter / ExtrudePainter.js View on Github external
}
            if (this.options['project']) {
                c = this.map.coordinateToPoint(new maptalks.Coordinate(data.vertices[i], data.vertices[i + 1]), targetZ);
                bottom.push(c.x, c.y, 0);
                top.push(c.x, c.y, height);
            } else {
                bottom.push(data.vertices[i], data.vertices[i + 1], 0);
                top.push(data.vertices[i], data.vertices[i + 1], height);
            }
        }
        data.vertices = bottom;
        let triangles = earcut(data.vertices, data.holes, dimension);
        if (triangles.length <= 2) {
            return;
        }
        const deviation = earcut.deviation(data.vertices, data.holes, dimension, triangles);
        if (Math.round(deviation * 1E3) / 1E3 !== 0) {
            if (console) {
                console.warn('Failed triangluation.');
            }
            return;
        }

        const count = bottom.length / dimension;

        const preCount = this.vertexArray.length / dimension;
        if (preCount > 0) {
            triangles = triangles.map(e => e + preCount);
        }
        // push bottom vertice
        maptalks.Util.pushIn(this.vertexArray, bottom);
        // push bottom elements
github maptalks / maptalks.biglayer / src / painter / PolygonPainter.js View on Github external
const data = earcut.flatten(vertice);

        if (this.options['project']) {
            const v = [];
            let c;
            for (let i = 0, l = data.vertices.length; i < l; i += 2) {
                c = this.map.coordinateToPoint(new maptalks.Coordinate(data.vertices[i], data.vertices[i + 1]), targetZ);
                v.push(c.x, c.y);
            }
            data.vertices = v;
        }
        let triangles = earcut(data.vertices, data.holes, 2);
        if (triangles.length <= 2) {
            return this;
        }
        const deviation = earcut.deviation(data.vertices, data.holes, 2, triangles);
        if (Math.round(deviation * 1E3) / 1E3 !== 0) {
            if (console) {
                console.warn('Failed triangluation.');
            }
            return this;
        }
        const count = this.vertexArray.length / 2;
        if (count > 0) {
            triangles = triangles.map(e => e + count);
        }
        maptalks.Util.pushIn(this.vertexArray, data.vertices);
        maptalks.Util.pushIn(this.elementArray, triangles);

        // 添加样式数据
        this._addTexCoords(data.vertices.length / 2, style);
        return this;

earcut

The fastest and smallest JavaScript polygon triangulation library for your WebGL apps

ISC
Latest version published 5 months ago

Package Health Score

86 / 100
Full package analysis

Popular earcut functions

Similar packages