npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

clipper

v2.0.0

Published

Node binding to C++ clipping library

Downloads

52

Readme

clipper

Build Status

Node binding to C++ clipping library found at http://www.angusj.com/delphi/clipper.php

Installation and use

Add the module to your package dependencies:

npm install clipper --save

Use the module:

var clipper = require('clipper');

Api Overview

This library can be divided up into two parts. The first part is the clipping operation module. A clipping operation is initiated with a call to begin(). The returned object provides several functions of its own.

The second part comprises a collection of utility functions that clipper provides for operating on paths.

This is illustrated in the following diagram:

clipper
|-> begin():
|   |-> setFillTypes()
|   |-> setFactor()
|   |-> addSubjectPath()
|   |-> addClipPath()
|   |-> union()
|   |-> intersection()
|   |-> difference()
|   `-> xor()
|-> area()
|-> clean()
|-> cleanAll()
|-> simplify()
`-> simplifyAll()

In the documentation below, the variable clipper is used to denote the object returned from require('clipper');, while the variable op is the object returned from a clipper.begin() call. Also note that when a path is given as a parameter or return type, it always refers to an array of path vertices like [x_0, y_0, x_1, y_1, x_2, y_2, ...]. paths refers to an array of multiple paths.

Clipping Operation Module

clipper.begin([callback]);

Starts a new clipper operation. This also sets both the subject and clip fill types to EVENODD.

op.setFillTypes(subjFillType[, clipFillType][, callback]);

Sets the subject fill type (and optionally the clip fill type). Use the values defined in clipper.PolyFillType. For example:

op.setFillTypes(clipper.PolyFillType.POSITIVE);

Possible fill types are EVENODD, NONZERO, POSITIVE, and NEGATIVE.

op.setFactor(factor[, callback]);

Sets the factor used to transform each coordinate. Useful when the coordinates are given in small units such as [0.0, 0.0, 0.010, 0.0, 0.010, 0.010, 0.0, 0.010]. Clipper works in integers, so the coordinates must be scalled up. For example, the factor could be set to 1000. The result from any clipping operation will return any results in the original scale.

op.addSubjectPath(path, closed[, callback]);

Adds an open or closed subject path to the the clipping operation. The path should be a list of (x, y) vertices given in an array. The closed parameter indicates whether the path is closed (i.e., a polygon) or open (i.e., a polyline).

op.addClipPath(path[, callback]);

Adds a clip path to the clipping operation. The path should be a list of (x, y) vertices given in an array. Note that clip paths are closed; that is, clip path must always represent polygons.

op.union([callback]);

Performs the union operation. Returns an array of size 2. The first element is an array of all closed paths; the second element is an array of all open paths.

op.intersection([callback]);

Performs the intersection operation. Returns an array of size 2. The first element is an array of all closed paths; the second element is an array of all open paths.

op.difference([callback]);

Performs the difference operation. Returns an array of size 2. The first element is an array of all closed paths; the second element is an array of all open paths.

op.xor([callback]);

Performs the xor operation. Returns an array of size 2. The first element is an array of all closed paths; the second element is an array of all open paths.

Utility Function Module

Note: Clipper works in integers, so double value are accepted but must be scalled up. For example, the factor could be set to 10 if measurements are given in centimeters with millimeter precision. In that case, the vertex (2.7, 12.9) would be transformed to (27, 129) for the purposes of the operation. The result from any clipping operation will return any results in the original scale.

clipper.area(path[, factor=1.0][, callback]);

Computes the area of the given polygon.

clipper.clean(path[, factor=1.0[, distance=1.415]][, callback]);

Performs the clean operation, which does the following:

  1. Removes vertices that join co-linear edges, or join edges that are almost co-linear.
  2. Removes vertices that are within the specified distance of an adjacent vertex.
  3. Removes vertices that are within a specified distance of a semi-adjacent vertex together with their out-lying vertices.

Returns a path. Please see the CleanPolygon Documentation for examples.

clipper.orientation(path[, factor=1.0][, callback]);

Detects and reports whether the provided path is an outer or hole polygon. Please see the Orientation Documentation for more information.

clipper.simplify(path[, factor=1.0[, PolyFillType=EVENODD]][, callback]);

Removes self-intersections from the supplied polygon (by performing a boolean union operation using the nominated PolyFillType). Polygons with non-contiguous duplicate vertices (ie 'touching') will be split into two polygons. Returns an array of paths. Please see the SimplifyPolygon Documentation for examples. To find the orientation of a given path, use the orientation method.