earcut

package module
v0.0.0-...-7084f78 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2021 License: ISC Imports: 3 Imported by: 5

README

earcut

A library for efficiently transforming polygons into triangles in go.

Build Status Go Report Card Documentation Coverage Status GitHub issues license Release

About

This is a direct port of Mapbox's JavaScript earcut library.

Usage

// flat array of all vertices in polygon, including holes
verts := []float64{
    0.0, 0.0,
    1.0, 0.0,
    1.0, 1.0,
    0.0, 1.0,
    0.0, 0.0,
    0.25, 0.25,
    0.75, 0.25,
    0.75, 0.75,
    0.25, 0.75,
    0.25, 0.25,
}
holes := []int{5} // *vertex* index of beginning of each hole
dims := 2 // number of values per vertex
indices, err := earcut.Earcut(verts, holes, dims)
// indices is an array of integers (3 per triangle) referencing
// the polygon vertexes that make up each triangle

Documentation

See Mapbox and GoDoc.org for complete documentation.

Author

Original implementation by Mapbox. Go port by Ryan Clancey

License

earcut is licensed under the ISC license, described in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deviation

func Deviation(data []float64, holeIndices []int, dim int, triangles []int) float64

Deviation returns a percentage difference between the polygon area and its triangulation area; used to verify correctness of triangulation

func Earcut

func Earcut(data []float64, holeIndices []int, dim int) ([]int, error)

Earcut returns an int array of vertex indices that make up the triangles of the polygon.

The polygon vertices should be passed as a flat array of float64 values.

holeIndices is an array of integers pointing to the vertex index (not the data index) of the start of each hole (if any).

dim is the number of values per vertex. Only the first two values (x & y) will be considered when constructing the triangles.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL