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

polygon-pathfinding

v0.1.3

Published

A pathfinding algorithm for 2d polygons

Downloads

3

Readme

Polygon Pathfinding

This document presents a simple algorithm for a pathfinding algorithm done for non-degenerate polygons.

API

In order to make a searcher we first need to declare a polygon.

const { Point, Polygon, Search } = require('polygon-pathfinding');

let polygon = new Polygon();

// Push points from a polygon.

// Push is boolean method that returns true if the point has been pushed to the polygon
// or it returns false in case the point will make the polygon degenerate (self intersecting).
// The check can be deactivated by pushing with "polygon.push(0, 0, woChecker = true);"
polygon.push(0, 0);
polygon.push(5, 0);
polygon.push(5, 5);
polygon.push(2, 5);
polygon.push(2, 3);
polygon.push(0, 3);
polygon.closePolygon(); // This method closes the polygon and completes it. The push method will return false in case (y, x) is point that already exists in the polygon.

polygon.triangulate();

let searcher = new Search(polygon);

// This will return a path of points that will represent a path between (0.3, 2.7) and (2.4, 4.5).
console.log(searcher.searchForPath(new Point(0.3, 2.7), new Point(2.4, 4.5)))

And the graphical representation of this simple polygon is. image

Testing

You can test this pathfinding algorithm on this page: https://soucupb.github.io/BoringPathfinding/ image

Here is a simple example of a drawn polygon. And here is a simple path for it. The path are the lines with yellow.

image

Support and notes

| Version | Navmesh Polygon Triangulation | Holes Support | Triangle Searching Complexity | Searching Algorithm | Searching Algorithm Complexity | Point push in polygon complexity | | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | --------------- | | 0.1.0 | ✔️ | ❌ | O(n) (where n is the number of triangles) | AStar | O(m ^ 2) (where m is the number of triangles in a path found) | O(n ^ 2) (where n is the number of points in the polygon) (O(n) in case of using woChecker=true) |

Contribution

If you're intrested in upgrading this package with better performing algorithms, adding new features or solving bugs, do not hesitate to create issues and then, making pull request for them.