gl3n

gl3n.math

Provides nearly all GLSL functions, according to spec 4.1, it also publically imports other useful functions (from std.math, core.stdc.math, std.alogrithm) so you only have to import this file to get all mathematical functions you need.

Publically imports: PI, sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh, asinh, acosh, atanh, pow, exp, log, exp2, log2, sqrt, abs, floor, trunc, round, ceil, modf, fmodf, min, max.

Authors
David Herberth
License
MIT

real PI_180;

PI / 180 at compiletime, used for degrees/radians conversion.


real _180_PI;

180 / PI at compiletime, used for degrees/radians conversion.


T mod(T)(T x, T y);

Modulus. Returns x - y * floor(x/y).


T abs(T)(T t);

Calculates the absolute value.


T abs(T)(T vec);
T abs(T)(T quat);

Calculates the absolute value per component.


pure nothrow @safe real inversesqrt(real x);

Returns 1/sqrt(x), results are undefined if x <= 0.


float sign(T)(T x);

Returns 1.0 if x > 0, 0.0 if x = 0, or -1.0 if x < 0.


bool almost_equal(T, S)(T a, S b, float epsilon = 1e-06F);
bool almost_equal(T, S)(T a, S b, float epsilon = 1e-06F);

Compares to values and returns true if the difference is epsilon or smaller.


pure nothrow @safe real radians(real degrees);

Converts degrees to radians.


real cradians(real degrees)();

Compiletime version of radians.


pure nothrow @safe real degrees(real radians);

Converts radians to degrees.


real cdegrees(real radians)();

Compiletime version of degrees.


auto clamp(T1, T2, T3)(T1 x, T2 min_val, T3 max_val);

Returns min(max(x, min_val), max_val), Results are undefined if min_val > max_val.


float step(T1, T2)(T1 edge, T2 x);

Returns 0.0 if x < edge, otherwise it returns 1.0.


auto smoothstep(T1, T2, T3)(T1 edge0, T2 edge1, T3 x);

Returns 0.0 if x <= edge0 and 1.0 if x >= edge1 and performs smooth hermite interpolation between 0 and 1 when edge0 < x < edge1. This is useful in cases where you would want a threshold function with a smooth transition.