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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@papit/sat

v0.0.2

Published

Separating Axis Theorem collision for polygons, returning the contact normal and overlap. Reach for it to detect and resolve collisions, concave polygons included when they are split into convex pieces.

Readme

@papit/sat

Separating Axis Theorem collision for polygons, returning the contact normal and overlap. Reach for it to detect and resolve collisions, concave polygons included when they are split into convex pieces.

Logo


Type Tests NPM version


Installation

npm install @papit/sat

Usage

import { SAT } from "@papit/sat";
import { Polygon } from "@papit/polygon";

const a = new Polygon({ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 }, { x: 0, y: 10 });
const b = new Polygon({ x: 8, y: 0 }, { x: 18, y: 0 }, { x: 18, y: 10 }, { x: 8, y: 10 });

const contact = SAT(a, b); // { normal: Vector2 (1, 0), overlap: 2 }

if (contact)
{
  a.move(-contact.normal.x * contact.overlap, -contact.normal.y * contact.overlap);
}

A plain convex shape works too:

SAT({ vertices: [{ x: 0, y: 0 }, { x: 10, y: 0 }, { x: 10, y: 10 }] }, other);

npm run view opens a demo: click to place vertices, click the first one to close, then drag polygons into each other.

API

SAT

SAT(polygonA: Polygon, polygonB: Polygon): { normal: Vector2, overlap: number } | false

Returns false when the polygons don't touch. Otherwise normal is a unit vector pointing from A towards B, and overlap is how far they intersect along it.

Polygon

vertices is all that's required. A concave polygon needs its convex pieces, and the first of these found is used:

| Field or method | Description | | ---------------------- | -------------------------------------------------------------- | | getShape(index) | One convex piece, as vertices or { vertices } | | shapes | The pieces, as shapes, vertex groups or index lists | | getTriangle(index) | One triangle | | triangles | Flat vertex indices, three per triangle |

@papit/polygon provides these for you.

Design notes

  • 2D only: for 3D, rotated boxes or curved shapes use @papit/gjk.
  • Broad phase first: bounding boxes are compared before any axis is tested.
  • Convex pieces: each piece of A is tested against each piece of B, so the cost grows with pieces A × B × edges.

License

Licensed under the @Papit License 1.0 - Copyright (c) 2024 Henry Pap (@onkelhoy)

Key points:

  • ✅ Free to use in commercial projects
  • ✅ Free to modify and distribute
  • ✅ Attribution required
  • ❌ Cannot resell the component itself as a standalone product

See the LICENSE file for full details.

Related