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.
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.
-
Declaration
T
mod
(T)(Tx
, Ty
);Modulus. Returns
x
-y
* floor(x
/y
). -
Declaration
T
abs
(T)(Tt
) if (!is_vector!T && !is_quaternion!T && !is_matrix!T);Calculates the absolute value.
-
Declaration
T
abs
(T)(Tvec
) if (is_vector!T);
Tabs
(T)(Tquat
) if (is_quaternion!T);Calculates the absolute value per component.
-
Declaration
pure nothrow @safe real
inversesqrt
(realx
);Returns 1/sqrt(
x
), results are undefined ifx
<= 0. -
Declaration
float
sign
(T)(Tx
);Returns 1.0 if
x
> 0, 0.0 ifx
= 0, or -1.0 ifx
< 0. -
Declaration
bool
almost_equal
(T, S)(Ta
, Sb
, floatepsilon
= 1e-06F) if (!is_vector!T && !is_quaternion!T);
boolalmost_equal
(T, S)(Ta
, Sb
, floatepsilon
= 1e-06F) if (is_vector!T && is_vector!S && T.dimension == S.dimension);Compares to values and returns
true
if the difference isepsilon
or smaller. -
Declaration
pure nothrow @safe real
radians
(realdegrees
);Converts
degrees
toradians
. -
Declaration
real
cradians
(real degrees)();Compiletime version of radians.
-
Declaration
pure nothrow @safe real
degrees
(realradians
);Converts
radians
todegrees
. -
Declaration
real
cdegrees
(real radians)();Compiletime version of degrees.
-
Declaration
CommonType!(T1, T2, T3)
clamp
(T1, T2, T3)(T1x
, T2min_val
, T3max_val
);Returns min(max(
x
,min_val
),max_val
), Results are undefined ifmin_val
>max_val
. -
Declaration
float
step
(T1, T2)(T1edge
, T2x
);Returns 0.0 if
x
<edge
, otherwise it returns 1.0. -
Declaration
CommonType!(T1, T2, T3)
smoothstep
(T1, T2, T3)(T1edge0
, T2edge1
, T3x
);Returns 0.0 if
x
<=edge0
and 1.0 ifx
>=edge1
and performs smooth hermite interpolation between 0 and 1 whenedge0
<x
<edge1
. This is useful in cases where you would want a threshold function with a smooth transition.