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

@wentools/spatial

v0.1.1

Published

Pure 2D geometry primitives — points, vectors, rectangles, circles, lines, and distance metrics

Readme

@wentools/spatial

Pure 2D geometry primitives: points, vectors, rectangles, circles, lines, and distance metrics.

Zero dependencies. Works in Deno, Node, and the browser. All functions are pure, operate in continuous 2D coordinate space, and take angles in radians.

Install

# npm
npm install @wentools/spatial

# Deno / JSR
deno add jsr:@wentools/spatial

Usage

import {
  createPoint,
  createRectangle,
  isPointInRectangle,
  euclideanDistance,
} from '@wentools/spatial'

const point = createPoint(5, 3)
const rect = createRectangle(0, 0, 10, 10)

isPointInRectangle(point, rect) // true
euclideanDistance(point, createPoint(0, 0)) // 5.83...

Types

Point2D ({ x, y }), Vector2D ({ x, y }), Rectangle ({ x, y, width, height }), Circle ({ x, y, radius }) and Line ({ start, end }).

API

Point

| Function | Description | |----------|-------------| | createPoint(x, y) | Create a point | | createOrigin() | Create a point at (0, 0) | | translatePoint(point, dx, dy) | Translate a point by an offset | | pointsEqual(a, b) | Check equality | | lerpPoint(a, b, t) | Linear interpolation between two points | | midpoint(a, b) | Point halfway between two points | | rotatePoint(point, angle, origin?) | Rotate around an origin (default 0, 0) | | clampPoint(point, bounds) | Clamp a point inside rectangular bounds |

Vector

| Function | Description | |----------|-------------| | createVector(x, y) | Create a vector | | createZeroVector() | Create a zero vector | | vectorMagnitude(v) | Length of a vector | | addVectors(a, b) | Add two vectors | | subtractVectors(a, b) | Subtract vectors | | scaleVector(v, scalar) | Scale a vector | | normalizeVector(v) | Normalize to unit length | | dotProduct(a, b) | Dot product | | crossProduct2D(a, b) | 2D cross product (a scalar) | | perpendicular(v) | Vector rotated 90 degrees counter-clockwise | | vectorFromAngle(angle, magnitude?) | Vector from an angle and length (default 1) | | vectorToAngle(v) | Angle of a vector | | rotateVector(v, angle) | Rotate a vector |

Rectangle

| Function | Description | |----------|-------------| | createRectangle(x, y, w, h) | Create a rectangle | | createRectangleFromPoints(tl, br) | From two corner points | | getRectangleArea(rect) | Area | | getRectanglePerimeter(rect) | Perimeter | | getRectangleCenter(rect) | Center point | | getRectangleCorners(rect) | The four corner points | | isPointInRectangle(point, rect) | Point containment | | rectanglesOverlap(a, b) | Overlap test | | rectangleContains(outer, inner) | Full containment | | rectangleIntersection(a, b) | Intersection rectangle, or null | | rectangleUnion(a, b) | Union bounding box | | translateRectangle(rect, dx, dy) | Move a rectangle | | expandRectangle(rect, amount) | Grow on every side | | insetRectangle(rect, amount) | Shrink on every side | | scaleRectangle(rect, factor, origin?) | Scale around an origin | | centerRectangleInContainer(container, inner) | Top-left point that centers inner (whole pixels) | | centerHorizontally(ref, el) | X position that centers el on ref | | centerVertically(ref, el) | Y position that centers el on ref |

Circle

| Function | Description | |----------|-------------| | createCircle(x, y, r) | Create a circle | | createCircleFromPoint(center, r) | From a point and radius | | getCircleArea(circle) | Area | | getCircleCircumference(circle) | Circumference | | getCircleCenter(circle) | Center point | | isPointInCircle(point, circle) | Point containment | | circlesOverlap(a, b) | Overlap test | | circleContains(outer, inner) | Full containment |

Line

A line is a segment from start to end.

| Function | Description | |----------|-------------| | createLine(start, end) | Create a line segment | | createLineFromCoords(x1, y1, x2, y2) | From coordinates | | getLineLength(line) | Length | | getLineMidpoint(line) | Midpoint | | getLineSlope(line) | Slope (Infinity for vertical lines) | | isPointOnLine(point, line, tolerance?) | Point-on-segment test (default tolerance 0.001) |

Distance

| Function | Description | |----------|-------------| | manhattanDistance(a, b) | L1 norm | | euclideanDistance(a, b) | L2 norm | | euclideanDistanceSquared(a, b) | Squared L2 (no sqrt) | | chebyshevDistance(a, b) | L-infinity norm | | createDistanceChecker(threshold, metric?) | Returns a function that tests whether two points are within a threshold ('euclidean' by default) |

Intersection

| Function | Description | |----------|-------------| | circleRectangleOverlap(circle, rect) | Circle and rectangle overlap test | | lineLineIntersection(a, b) | Intersection point of two segments, or null | | closestPointOnLine(point, line) | Closest point on a segment | | closestPointOnRectangle(point, rect) | Closest point on a rectangle's boundary |

Bounding box

| Function | Description | |----------|-------------| | getBoundingBox(points) | Tight bounding box for points, or null for an empty list |

License

MIT