benevolent's typescript math library for games
common numerical structures
Tip
until real docs are written, see the relevant sourcecode in s/core/
- mutable by default.
operations happen in-place, for efficiency (we're trying to reduce gc churn).// allocate a single vector instance const vector = new Vec2(0, 0) .add({x: 1, y: 2}) .multiplyBy(2)
- explicit cloning.
use.clone()to avoid mutating the original.// modify a clone (not the original) const vector2 = vector .clone() .normalize()
- underscore-suffixed methods take direct args.
- methods normally take in other class instances:
vectorA.add(vectorB)
- but underscore-suffixed methods take raw naked args (helping you avoid making instances)
vectorA.add_(x, y)
- methods normally take in other class instances:
handy utilities
Tip
until real docs are written, see the relevant sourcecode in s/tools/
- Radians
- Degrees
- Turns
- Arcseconds
geometric concepts
Tip
until real docs are written, see the relevant sourcecode in s/shapes/
- Edge β a line segment
- Pill β a fat line segment (like a sausage)
- Rect β a rectangle
- Circle β a point with a radius
- Segment β a line segment
- Capsule β a fat line segment (like a hoagie)
- Box β a cuboid
- Sphere β a point with a radius
spatial optimization data structures
Tip
until real docs are written, see the relevant sourcecode in s/optimizers/
functionality for doing basic physics
Tip
until real docs are written, see the relevant sourcecode in s/physics/
star this on github if you use it π