NTFS Path Mockery

# npm

Share private packages across your team with npm Orgs, now with simplified billing via the aws marketplace!Learn more »

## fernandez-polygon-decomposition

2.0.0 • Public • Published

# fernandez-polygon-decomposition

Library for decomposing polygons with (or without) holes into a partition of convex polygons.

It implements some of the algorithms presented in two publications by J Fernández :

• Algorithms for the decomposition of a polygon into convex polygons
• A practical algorithm for decomposing polygonal domains into convex polygons by diagonals

## Installation

``````npm install fernandez-polygon-decomposition
``````

or

``````yarn add fernandez-polygon-decomposition
``````

## Basic usage

The main function of this library is used to decompose a simple polygon into a partition of convex polygons :

⚠️ In order to decompose your polygon, its vertices have to be in clockwiser order (relative to the inverted y-axis of the web).

💡 But the library exports (along with other methods, see this section) some useful functions if you want to change the vertices order of your polygon :

## Advanced usage (arithmetic robustness)

By default, this library uses a set of robust predicates (more here) that aims to prevent floating point errors. Hence, this library is able to give correct convex partitions with (almost ?) every inputs.

But these kind of predicates are quite slow (compared to standard javascript operators or methods).

If you can control your inputs (not having coordinates like `{ x: 253.79999999999998, y: 84.60000000000001 }` for example), it is best to disable this feature in order to gain a speed boost (multiple times faster).

You can do so easily : `setRobustness(false);` Check here for more details about this method.

## Other methods

### isSimple

Checks if the polygon is simple (see https://en.wikipedia.org/wiki/Simple_polygon).

### isClockwiseOrdered

Indicates if the polygon vertices are in clockwise order (relative to the inverted y-axis of the web, ie : counterclockwise in normal mathematics).

### orderClockwise

Checks if the vertices of the polygon are in clockwise order, and if they are not, it reverses the order of those vertices.

### isConvex

Indicates if the polygon is convex.

### setRobustness - getRobustness

By default, this library uses a set of robust predicates that aims to prevent floating point errors.

But if you work with integers, or controlled inputs (few decimal places), it is best to disable it, in order to increase the speed of the algorithm (multiple times faster).

The use of these predicates can be configured (globally, for all methods) by the method `setRobustness`, and the current robustness state of the library can be accessed by the method `getRobustness`.

## Keywords

### install

`npm i fernandez-polygon-decomposition`

55

2.0.0

MIT

github.com

github