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

polyk

v0.24.0

Published

JavaScript tool for working with polygons. It uses several basic principles to be super simple and super universal.

Downloads

2,690

Readme

PolyK

This library was written by Ivan Kuckir.

What is PolyK?

PolyK is JavaScript tool for working with polygons. It uses several basic principles to be super simple and super universal:

  • No classes. PolyK does not have any classes or special data structures. PolyK consists of static functions only.
  • What is polygon? For PolyK, polygon is an array of numbers. Each two of them are X and Y coordinate of polygon vertex.
  • Simplicity and speed. Since PolyK does not make you use any special data structures, it is very easy to implement into your project. Since all JS engines are optimised for work with arrays, PolyK runs very fast.

PolyK was used in the game Tiny Monsters. Do you like the project? Make a donation!

Install

npm

$ npm install --save deep-slice

bower

$ bower install polyk

web browser ES5

<script src="https://unpkg.com/polyk/dist/polyk.min.js"></script>

Resources

API

IsSimple

Checks, if polygon is simple. Polygon is simple, when its edges don't cross each other.

Parameters

Returns boolean true if Polygon is simple

IsConvex

Checks, if polygon is convex. Polygon is convex, when each inner angle is <= 180°.

Parameters

Returns boolean

GetArea

Returns the area of polygon.

Parameters

Returns number

GetAABB

Returns the Axis-aligned Bounding Box of polygon

Parameters

Examples

//={x:0, y:0, width:0, height:0}

Returns AABB

Triangulate

Computes the triangulation. Output array is array of triangles (triangle = 3 indices of polygon vertices).

Works with simple polygons only.

Parameters

Examples

var ids = PolyK.Triangulate([0, 0, 1, 0, 1, 1, 0, 1]);
//=[0, 1, 2, 0, 2, 3]

Returns Array<number> array of triangles (triangle = 3 indices of polygon vertices)

Slice

Slices the polygon with line segment A-B, defined by [ax,ay] and [bx,by]. A, B must not lay inside a polygon. Returns an array of polygons.

Works with simple polygons only.

Parameters

ContainsPoint

Checks, if polygon contains [x, y].

Works with simple polygons only.

Parameters

Returns boolean depth

Raycast

Finds the closest point of polygon, which lays on ray defined by x,y and dx,dy.

"dist" is the distance of the polygon point, "edge" is the number of the edge, on which intersection occurs, "norm" is the normal in that place, "refl" is reflected direction.

Works with simple polygons only.

Parameters

Examples

//={dist:0, edge:0, norm:{x:0, y:0}, refl:{x:0, y:0}}

Returns Raycast

ClosestEdge

Finds the point on polygon edges, which is closest to [x,y]. Returns an object in this format

"dist" is the distance of the polygon point, "edge" is the number of the closest edge, "point" is the closest point on that edge, "norm" is the normal from "point" to [x,y].

Parameters

Examples

//={dist:0, edge:0, point:{x:0, y:0}, norm:{x:0, y:0}}

Returns ClosestEdge

Reverse

Reverse

Parameters