metis.math

Extends the default math library with additional utility functions.

This module re-exports any function defined in math, and so may shadow the math global.

local math = require "metis.math"
print(math.min(0, 10))
clamp(value, min, max)Clamp a value within a range.
wrap(value, min, max)Wrap a value around a range.
clamp(value, min, max)Source

Clamp a value within a range. This limits the given value to be between min and max (inclusive).

Parameters

  1. value number The value to clamp.
  2. min number The lower bound of the permitted values.
  3. max number The upper bound of the permitted values.

Returns

  1. number The clamped value.

Usage

wrap(value, min, max)Source

Wrap a value around a range. This is equivalent to the modulo operator (%), but for any lower and upper bound.

Parameters

  1. value number The value to wrap.
  2. min number The lower bound of the permitted values.
  3. max number The upper bound of the permitted values.

Usage