gl3n.math

gl3n.math

Discussion

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

  • Declaration

    enum real PI_180;

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

  • Declaration

    enum real _180_PI;

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

  • mod

    Declaration

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

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

  • abs

    Declaration

    T abs(T)(T t) if (!is_vector!T && !is_quaternion!T && !is_matrix!T);

    Calculates the absolute value.

  • abs

    Declaration

    T abs(T)(T vec) if (is_vector!T);
    T abs(T)(T quat) if (is_quaternion!T);

    Calculates the absolute value per component.

  • Declaration

    pure nothrow @safe real inversesqrt(real x);

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

  • Declaration

    float sign(T)(T x);

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

  • Declaration

    bool almost_equal(T, S)(T a, S b, float epsilon = 1e-06F) if (!is_vector!T && !is_quaternion!T);
    bool almost_equal(T, S)(T a, S b, float epsilon = 1e-06F) if (is_vector!T && is_vector!S && (T.dimension == S.dimension));

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

  • Declaration

    pure nothrow @safe real radians(real degrees);

    Converts degrees to radians.

  • Declaration

    real cradians(real degrees)();

    Compiletime version of radians.

  • Declaration

    pure nothrow @safe real degrees(real radians);

    Converts radians to degrees.

  • Declaration

    real cdegrees(real radians)();

    Compiletime version of degrees.

  • Declaration

    CommonType!(T1, T2, T3) 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.

  • Declaration

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

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

  • Declaration

    CommonType!(T1, T2, T3) 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.