npm.io
3.6.0 • Published 3 weeks ago

missing-math

Licence
MIT
Version
3.6.0
Deps
0
Size
16 kB
Vulns
0
Weekly
0
Stars
4

missing-math

missing features of the Math built-in object


Usage

Import with a module bundler

$ npm install --save missing-math
// using ES6 module
import { clamp, degrees } from 'missing-math'

// using CommonJS module
var { clamp, degrees } = require('missing-math')
Import from a browser
<script src="https://unpkg.com/missing-math"></script>
<script>
  // all methods are exposed in window.MissingMath
  MissingMath.clamp()
  MissingMath.degrees()
</script>

Methods

  • clamp(value, min, max)
  • wrap(value, min, max)
  • normalize(value, min, max[, clamp = false])
  • map(value, in_min, in_max, out_min, out_max[, clamp = false])
  • lerp(a, b, t)
  • random([a[, b[, rng = Math.random]]])
  • randomInt([a[, b[, rng = Math.random]]])
  • degrees(radians)
  • radians(degrees)
  • roundTo(value, nearest)
  • floorTo(value, nearest)
  • fract(value[, decimals])

License

MIT.