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

@woven-canvas/math

v0.1.0

Published

Math utilities for 2D vector operations

Readme

@woven-canvas/math

Memory-efficient math utilities used by woven-canvas.

Installation

npm install @woven-canvas/math

Usage

import { Vec2, Rect, Aabb, Mat2 } from "@woven-canvas/math";

// Vector operations (mutating API - modifies first argument in place)
const a = Vec2.create(10, 20);
const b = Vec2.create(5, 10);
Vec2.add(a, b); // a is now [15, 30]

// Axis-aligned bounding box
const aabb = Aabb.fromPoints([a, b]);
const contains = Aabb.containsPoint(aabb, Vec2.create(7, 15));

// Rectangle geometry (position + size based)
const position: Vec2 = [0, 0];
const size: Vec2 = [100, 50];
const center: Vec2 = [0, 0];
Rect.getCenter(position, size, center);

// Matrix transformations (2x3 affine matrix)
const mat = Mat2.fromRotation(Math.PI / 4);
const point = Vec2.create(10, 0);
Mat2.transformPoint(mat, point);

Modules

Vec2

2D vector as tuple [x, y]. Operations are mutating (modify first argument in place).

  • Creation: create, zero, clone
  • Geometry: dot, length, lengthSq, distance, distanceSq, midPoint, angle, angleTo, fromPolar
  • Mutation: set, copy, add, addScalar, sub, scale, multiply, divide, negate, normalize, rotate, rotateAround

Rect

Rectangle as position [x, y] + size [width, height], with optional rotation.

  • Getters: getCenter, getCorners, getAabb
  • UV conversion: uvToWorld, worldToUv, getUvToWorldMatrix
  • Tests: containsPoint, intersectsAabb
  • Mutation: setCenter, translate, scaleBy, scaleAround, rotateAround, boundPoints

Aabb

Axis-aligned bounding box as tuple [left, top, right, bottom].

  • Creation: create, zero, clone, fromPoints, fromPositionSize
  • Getters: left, top, right, bottom, width, height, center, size, corners
  • Tests: containsPoint, contains, intersects, distanceToPoint
  • Mutation: set, copy, expand, union, intersection, pad, setFromPoints, translate, scale

Mat2

2x3 affine transformation matrix [a, b, c, d, tx, ty] (compatible with CSS matrix()).

  • Creation: create, identity, clone, fromTranslation, fromScale, fromRotation, fromSkew, fromCssMatrix
  • Getters: getTranslation, getScale, getRotation, determinant
  • Mutation: set, copy, setIdentity, multiply, premultiply, invert, translate, scale, rotate, skew
  • Transform: transformPoint, transformVector, inverseTransformPoint
  • Utility: equals, isIdentity, toCssMatrix

Arc

Arc (curved line through 3 points) as tuple [aX, aY, bX, bY, cX, cY, thickness].

  • Creation: create, zero, clone
  • Getters: a, b, c, thickness
  • Computed: isCollinear, computeCenter, compute (returns ArcComputed with center, radius, angles)
  • Tests: containsPoint, intersectsAabb, intersectsCapsule, inArcAngle
  • Intersection: intersectSegment, intersectRect
  • Parametric: pointToParametric, parametricToPoint, length, directionAt
  • Bounds: extremaPoints, getExtrema
  • Mutation: set, copy, setA, setB, setC, setThickness, setFromPoints, trim

Capsule

Capsule (stadium shape) as tuple [ax, ay, bx, by, radius]. Used for swept collision detection.

  • Creation: create, fromPoints, clone
  • Getters: pointA, pointB, radius, center, length, bounds, getExtrema
  • Collision: closestPointOnSegmentParam, closestPointOnCenterLine, distanceToPoint, containsPoint, intersectsAabb, intersectsCapsule, segmentToSegmentDistance
  • Mutation: set, copy, translate, trim

Ray

Ray as tuple [originX, originY, directionX, directionY].

  • Creation: create, fromPoints, zero, clone
  • Getters: origin, direction, pointAt
  • Intersection: intersectSegment, intersectAabb, intersectRect (returns RayIntersection with point and distance)
  • Mutation: set, copy, setOrigin, setDirection

Scalar

Scalar math utilities:

  • clamp, lerp
  • normalizeAngle, normalizeAngleSigned, anglesApproxEqual, approxEqual
  • Constant: TAU (2π)

License

MIT