Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

triangulate-polyline

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

triangulate-polyline

Triangulates a complex polygon

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
22K
increased by0.31%
Maintainers
1
Weekly downloads
 
Created
Source

triangulate-polyline

Triangulates a polygon with holes encoded as a list of loops.

Example

var triangulate = require("triangulate-polyline")

var positions = [
  [-2, -2],
  [ 2, -2],
  [ 2,  2],
  [-2,  2],
  [-1, -1],
  [ 1, -1],
  [ 1,  1],
  [-1,  1]
]

var loops = [
  [0, 1, 2, 3],
  [4, 5, 6, 7]
]

console.log(triangulate(loops, positions))

Example output:

[ [ 3, 7, 2 ],
  [ 3, 0, 7 ],
  [ 0, 4, 7 ],
  [ 4, 0, 1 ],
  [ 5, 4, 1 ],
  [ 6, 5, 1 ],
  [ 6, 1, 2 ],
  [ 7, 6, 2 ] ]

Install

npm install triangulate-polyline

API

require("triangulate-polyline")(loops, positions)

Triangulates a complex polygon

  • loops is a list of vertices of the polygon, where each vertex is represented as an index into positions
  • positions is a list of vertex positions encoded, each represented by a length 2 array

Returns A list of triangles represented by triples of indices of position indices.

Note This library is built on top of poly2tri, which is not robust. Points which are close together or near the boundary of other loops may be incorrectly classified and could result in broken triangulations.

Credits

(c) 2014 Mikola Lysenko. MIT License

Keywords

FAQs

Package last updated on 23 Apr 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc