Skip to content

benevolent-games/math

Repository files navigation

@benev/math

benevolent's typescript math library for games


🍋 CORE

common numerical structures

Tip

until real docs are written, see the relevant sourcecode in s/core/

🍏 conventions for all core classes

  • 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)

🍏 Vec2

🍏 Vec3

🍏 Vec4

🍏 Quat


🍋 TOOLS

handy utilities

Tip

until real docs are written, see the relevant sourcecode in s/tools/

🍏 Scalar

🍏 Circular

🍏 Randy

🍏 Noise

🍏 Spline

🍏 Angles

  • Radians
  • Degrees
  • Turns
  • Arcseconds

🍋 SHAPES

geometric concepts

Tip

until real docs are written, see the relevant sourcecode in s/shapes/

🍏 2d shapes

  • Edge — a line segment
  • Pill — a fat line segment (like a sausage)
  • Rect — a rectangle
  • Circle — a point with a radius

🍏 3d shapes

  • Segment — a line segment
  • Capsule — a fat line segment (like a hoagie)
  • Box — a cuboid
  • Sphere — a point with a radius

🍋 OPTIMIZERS

spatial optimization data structures

Tip

until real docs are written, see the relevant sourcecode in s/optimizers/

🍏 HashMap

🍏 HashSet

🍏 ZenGrid


🍋 PHYSICS

functionality for doing basic physics

Tip

until real docs are written, see the relevant sourcecode in s/physics/

🍏 collide2d

🍏 collide3d

🍏 intersect2d

🍏 intersect3d


star this on github if you use it 👍

About

ts math utils for games

Resources

License

Stars

Watchers

Forks

Packages

No packages published