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

hexr-hshg

v1.0.0

Published

Hierachical Spatial Hash Grid

Downloads

5

Readme

Hexr-HSHG

Hierachical Spatial Hash Grid, original source code from Andrew Pertsen's Gist.

This is a hacked, modified version which forms the broad-phase collision detection part of "hexr-shit-physics" which is an incredibly shit arcade physics system that barely works, but it'll be coming to an npm repository near you soon. Sorry, world.

I really haven't put too much thought into whether this is remotely performant or even if it's even vaguely the correct solution for the particular problem I'm trying to solve. But... here it is.

Hack One:

It now accepts objects that have a body which contains a structure called AABB that contains two arrays, min and max representing the bounding box, and a boolean 'static' flag.

{
  body : {
    AABB : {
      min: [minx, miny],
      max: [maxy, maxy]
    },
    static : boolean
  }
}

Interesting technical note: In a WebGL world where +y is upwards, you'll want your 'min' co-ords to be the bottom left and the 'max' co-ords to be the top right. Just telling you this to spare you the many hours of pain this caused me.

Other interesting technical note: The original HSHG is already set up for you to override this stuff without needing to hack at the actual library but it was the middle of a Ludum Dare competition and didn't notice.

Hack Two:

Objects flagged as static will never show as being in collision with each other.

## Hack Three:

Long forgotten things that are long forgotten.

API:

var HSHG = require('hexr-hshg')

var shitGrid = new HSHG();

shitGrid.addObject( someObjectWithThePreviouslyMentionedBodyAndBoundingBox )
shitGrid.addObject( someOtherObjectThatAlsoHasThatStuff )

// Lots of exciting things happen here, including a change to the bounding box for one of those objects!

// get the grid to make sure it's all up to date..
shitGrid.update();

// right then. Are any of these bounding boxes overlapping? 
var collisionPairs = shitGrid.getCollisionPairs();

I'll leave what happened to collisionPairs as a sort of exciting dramatic cliffhanger for another day.

Actually Using This Thing

It sort of makes sense, if you're using this in a game, to pass that list of collisions around to all entities that are doing any sort of collision detection so that they've got a sigificantly shorter list of things to be interested in.

At least, that's how I've used it.

License

I have no idea. Nothign on the original Gist so let's say MIT and hope that no-one gets angry.

## Contributing

You probably shouldn't.