Skip to content

atl/util.hpp

sm.util and sm.noise: interpolation, hashing, UTF-8 helpers and noise functions.

inline double smoothstep(double edge0, double edge1, double x);

Smooth Hermite step from 0 at edge0 to 1 at edge1. See also sm::lerp and sm::clamp.

Parameters

  • edge0 (double)
  • edge1 (double)
  • x (double)

Returns double

inline double smootherstep(double edge0, double edge1, double x);

Like smoothstep, with zero first and second derivatives at the edges.

Parameters

  • edge0 (double)
  • edge1 (double)
  • x (double)

Returns double

inline int positiveModulo(int x, int n);

x mod n, always in 0..n-1 (unlike C's %).

Parameters

  • x (int)
  • n (int)

Returns int

inline double bezier2(double c0, double c1, double c2, double t);

Quadratic Bezier interpolation of scalars at t (0..1).

Parameters

  • c0 (double)
  • c1 (double)
  • c2 (double)
  • t (double)

Returns double

inline double bezier3(double c0, double c1, double c2, double c3, double t);

Cubic Bezier interpolation of scalars at t (0..1).

Parameters

  • c0 (double)
  • c1 (double)
  • c2 (double)
  • c3 (double)
  • t (double)

Returns double

inline double easing(StringView curve, double p);

An easing curve by name ("easeInOutQuad", "easeOutBounce", ...) at progress p (0..1).

Parameters

  • curve (StringView): The easing function name.
  • p (double): The easing function input.

Returns double

Lua: sm.util.easing

inline Quat axesToQuat(Vec3 xAxis, Vec3 yAxis);

A rotation from two perpendicular axes.

Parameters

  • xAxis (Vec3): The X axis.
  • yAxis (Vec3): The Z axis.

Returns Quat

Lua: sm.util.axesToQuat

template <class... A> int hash(const A &...values);

The engine's hash of any values, stable across clients.

Parameters

  • values (const A &...): The arguments to be hashed.

Returns int

Lua: sm.util.hash

inline Vec3 geometricMedian(const Vector<Vec3> &points, Optional<Vec3> initialGuess = atl::none, Optional<int> iterations = atl::none);

An approximation of the point with the smallest total distance to points.

Parameters

  • points (const Vector<Vec3> &)
  • initialGuess (Optional<Vec3>): A guessed position to start searching from. (Optional)
  • iterations (Optional<int>): The number of iterations. (Defaults to 1)

Returns Vec3

Lua: sm.util.geometricMedian

inline int utf8Length(StringView s);

Length of UTF-8 text in characters, not bytes.

Parameters

  • s (StringView): The input string.

Returns int

Lua: sm.util.utf8StringLength

inline String utf8Clamp(StringView s, int maxChars);

UTF-8 text cut to at most maxChars characters.

Parameters

  • s (StringView): The input string.
  • maxChars (int): The maximum number of UTF-8 characters.

Returns String

Lua: sm.util.clampUtf8String

inline double perlin(double x, double y, int seed);

2D Perlin noise.

Parameters

  • x (double): The X value.
  • y (double): The Y value.
  • seed (int): The seed.

Returns double

Lua: sm.noise.perlinNoise2d

inline double octave(double x, double y, int octaves, int seed);

2D Perlin noise summed over several octaves.

Parameters

  • x (double): The X value.
  • y (double): The Y value.
  • octaves (int): The octaves.
  • seed (int): The seed.

Returns double

Lua: sm.noise.octaveNoise2d

inline double simplex(double x);

1D, 2D and 3D simplex noise.

Parameters

  • x (double)

Returns double

Lua: sm.noise.simplexNoise1d

inline double simplex(double x, double y);

1D, 2D and 3D simplex noise.

Parameters

  • x (double)
  • y (double)

Returns double

Lua: sm.noise.simplexNoise2d

inline double simplex(double x, double y, double z);

1D, 2D and 3D simplex noise.

Parameters

  • x (double)
  • y (double)
  • z (double)

Returns double

Lua: sm.noise.simplexNoise3d

inline int intNoise(double x, double y, int seed);

Deterministic integer and float noise per point: the same inputs give the same output.

Parameters

  • x (double): The X value.
  • y (double): The Y value.
  • seed (int): The seed.

Returns int

Lua: sm.noise.intNoise2d

inline double floatNoise(double x, double y, int seed);

Deterministic integer and float noise per point: the same inputs give the same output.

Parameters

  • x (double): The X value.
  • y (double): The Y value.
  • seed (int): The seed.

Returns double

Lua: sm.noise.floatNoise2d

inline double randomRange(double a, double b);

A random number between a and b.

Parameters

  • a (double): The lower bound.
  • b (double): The upper bound.

Returns double

Lua: sm.noise.randomRange

inline double randomNormal(double mean, double deviation);

A random number from a normal distribution.

Parameters

  • mean (double): The mean.
  • deviation (double): The deviation.

Returns double

Lua: sm.noise.randomNormalDistribution

inline Vec3 gunSpread(Vec3 direction, double degrees);

A direction randomly spread within degrees of direction.

Parameters

  • direction (Vec3): The direction.
  • degrees (double): The spread angle in degrees.

Returns Vec3

Lua: sm.noise.gunSpread