39 using u8 = std::uint8_t;
40 using i32 = std::int32_t;
41 using u32 = std::uint32_t;
47 using ivec2 = i32vec2;
48 using ivec3 = i32vec3;
49 using ivec4 = i32vec4;
51 using uvec2 = u32vec2;
52 using uvec3 = u32vec3;
53 using uvec4 = u32vec4;
65 inline constexpr f32 F32_LOWEST = std::numeric_limits<f32>::lowest();
66 inline constexpr f32 F32_MAX = std::numeric_limits<f32>::max();
67 inline constexpr f32 F32_MIN_NORMAL = std::numeric_limits<f32>::min();
68 inline constexpr f32 F32_DENORM_MIN = std::numeric_limits<f32>::denorm_min();
69 inline constexpr f32 F32_EPSILON = std::numeric_limits<f32>::epsilon();
70 inline constexpr f32 F32_INFINITY = std::numeric_limits<f32>::infinity();
71 inline constexpr f32 F32_QUIET_NAN = std::numeric_limits<f32>::quiet_NaN();
75 inline constexpr f32 F32_COMPARE_EPSILON = 1e-6f;
79 inline constexpr f32 E = 2.7182818284590452354f;
80 inline constexpr f32 LOG2_E = 1.4426950408889634074f;
81 inline constexpr f32 LOG10_E = 0.43429448190325182765f;
82 inline constexpr f32 LN_2 = 0.69314718055994530942f;
83 inline constexpr f32 LN_10 = 2.30258509299404568402f;
85 inline constexpr f32 PI = 3.14159265358979323846f;
86 inline constexpr f32 TWO_PI = 6.2831853071795864769f;
87 inline constexpr f32 PI_OVER_2 = 1.57079632679489661923f;
88 inline constexpr f32 PI_OVER_4 = 0.78539816339744830962f;
89 inline constexpr f32 ONE_OVER_PI = 0.31830988618379067154f;
90 inline constexpr f32 TWO_OVER_PI = 0.63661977236758134308f;
91 inline constexpr f32 TWO_OVER_SQRT_PI = 1.12837916709551257390f;
93 inline constexpr f32 SQRT_2 = 1.41421356237309504880f;
94 inline constexpr f32 ONE_OVER_SQRT_2 = 0.70710678118654752440f;
138 f32vec3(f32 x_, f32 y_, f32 z_);
159 f32vec4(f32 x_, f32 y_, f32 z_, f32 w_);
266 std::string to_string(
const f32vec2& v);
267 std::string to_string(
const f32vec3& v);
268 std::string to_string(
const f32vec4& v);
271 const f32* value_ptr(
const f32vec2& v);
273 const f32* value_ptr(
const f32vec3& v);
275 const f32* value_ptr(
const f32vec4& v);
277 f32vec2 make_vec2(
const f32* ptr);
278 f32vec3 make_vec3(
const f32* ptr);
279 f32vec4 make_vec4(
const f32* ptr);
385 std::string to_string(
const i32vec2& v);
386 std::string to_string(
const i32vec3& v);
387 std::string to_string(
const i32vec4& v);
390 const i32* value_ptr(
const i32vec2& v);
392 const i32* value_ptr(
const i32vec3& v);
394 const i32* value_ptr(
const i32vec4& v);
396 i32vec2 make_vec2(
const i32* ptr);
397 i32vec3 make_vec3(
const i32* ptr);
398 i32vec4 make_vec4(
const i32* ptr);
500 std::string to_string(
const u32vec2& v);
501 std::string to_string(
const u32vec3& v);
502 std::string to_string(
const u32vec4& v);
505 const u32* value_ptr(
const u32vec2& v);
507 const u32* value_ptr(
const u32vec3& v);
509 const u32* value_ptr(
const u32vec4& v);
511 u32vec2 make_vec2(
const u32* ptr);
512 u32vec3 make_vec3(
const u32* ptr);
513 u32vec4 make_vec4(
const u32* ptr);
631 const u8* value_ptr(
const u8vec2& v);
634 const u8* value_ptr(
const u8vec3& v);
637 const u8* value_ptr(
const u8vec4& v);
639 u8vec2 make_vec2(
const u8* ptr);
640 u8vec3 make_vec3(
const u8* ptr);
641 u8vec4 make_vec4(
const u8* ptr);
643 std::string to_string(
const u8vec2& v);
644 std::string to_string(
const u8vec3& v);
645 std::string to_string(
const u8vec4& v);
711 f32 determinant(
const f32mat2& m);
712 f32 determinant(
const f32mat3& m);
713 f32 determinant(
const f32mat4& m);
726 std::string to_string(
const f32mat2& m,
unsigned pad = 10);
727 std::string to_string(
const f32mat3& m,
unsigned pad = 10);
728 std::string to_string(
const f32mat4& m,
unsigned pad = 10);
731 const f32* value_ptr(
const f32mat2& m);
733 const f32* value_ptr(
const f32mat3& m);
735 const f32* value_ptr(
const f32mat4& m);
737 f32mat2 make_mat2(
const f32* ptr);
738 f32mat3 make_mat3(
const f32* ptr);
739 f32mat4 make_mat4(
const f32* ptr);
746 f32quat(f32 w_, f32 x_, f32 y_, f32 z_);
782 std::string to_string(
const f32quat& q);
785 const f32* value_ptr(
const f32quat& q);
787 f32quat make_quat(
const f32* ptr);
791 f32mat4 perspective(f32 fovy, f32 aspect, f32 z_near, f32 z_far);
792 f32mat4 ortho(f32 left, f32 right, f32 bottom, f32 top, f32 z_near, f32 z_far);
802 f32 uniform_01(std::mt19937* gen);
805 f32 uniform_n11(std::mt19937* gen);
807 u8 uniform_linear(u8 min, u8 max);
808 u8 uniform_linear(std::mt19937* gen, u8 min, u8 max);
810 u32 uniform_linear(u32 min, u32 max);
811 u32 uniform_linear(std::mt19937* gen, u32 min, u32 max);
813 i32 uniform_linear(i32 min, i32 max);
814 i32 uniform_linear(std::mt19937* gen, i32 min, i32 max);
816 f32 uniform_linear(f32 min, f32 max);
817 f32 uniform_linear(std::mt19937* gen, f32 min, f32 max);
828 f32vec2 uniform_circular(f32 radius);
829 f32vec2 uniform_circular(std::mt19937* gen, f32 radius);
831 f32vec3 uniform_spherical(f32 radius);
832 f32vec3 uniform_spherical(std::mt19937* gen, f32 radius);
834 f32vec2 uniform_disk(f32 radius);
835 f32vec2 uniform_disk(std::mt19937* gen, f32 radius);
837 f32vec3 uniform_ball(f32 radius);
838 f32vec3 uniform_ball(std::mt19937* gen, f32 radius);
840 f32 gaussian(f32 mean, f32 deviation, f32 min, f32 max);
841 f32 gaussian(std::mt19937* gen, f32 mean, f32 deviation, f32 min, f32 max);
843 bool bernoulli(f32 p);
844 bool bernoulli(std::mt19937* gen, f32 p);
850 f32 lerp(f32 a, f32 b, f32 t);
851 f32 lerp_01(f32 a, f32 b, f32 t);
862 f32 inverse_lerp(f32 a, f32 b, f32 v);
863 f32 inverse_lerp_01(f32 a, f32 b, f32 v);
865 f32 remap(f32 in_a, f32 in_b, f32 out_a, f32 out_b, f32 v);
866 f32 remap_01(f32 in_a, f32 in_b, f32 out_a, f32 out_b, f32 v);
868 f32 step(f32 edge, f32 x);
870 f32 smoothstep(f32 t);
871 f32 smoothstep_01(f32 t);
873 f32 smootherstep(f32 t);
874 f32 smootherstep_01(f32 t);
876 f32 smoothstep(f32 edge0, f32 edge1, f32 x);
877 f32 smoothstep_unclamped(f32 edge0, f32 edge1, f32 x);
879 f32 smootherstep(f32 edge0, f32 edge1, f32 x);
880 f32 smootherstep_unclamped(f32 edge0, f32 edge1, f32 x);
882 f32 ease_linear(f32 t);
883 f32 ease_linear_01(f32 t);
885 f32 ease_in_quadratic(f32 t);
886 f32 ease_out_quadratic(f32 t);
887 f32 ease_in_out_quadratic(f32 t);
889 f32 ease_in_cubic(f32 t);
890 f32 ease_out_cubic(f32 t);
891 f32 ease_in_out_cubic(f32 t);
893 f32 ease_in_quartic(f32 t);
894 f32 ease_out_quartic(f32 t);
895 f32 ease_in_out_quartic(f32 t);
897 f32 ease_in_quintic(f32 t);
898 f32 ease_out_quintic(f32 t);
899 f32 ease_in_out_quintic(f32 t);
901 f32 ease_in_sine(f32 t);
902 f32 ease_out_sine(f32 t);
903 f32 ease_in_out_sine(f32 t);
905 f32 ease_in_circular(f32 t);
906 f32 ease_out_circular(f32 t);
907 f32 ease_in_out_circular(f32 t);
909 f32 ease_in_exponential(f32 t);
910 f32 ease_out_exponential(f32 t);
911 f32 ease_in_out_exponential(f32 t);
913 f32 ease_in_back(f32 t, f32 overshoot = 1.70158f);
914 f32 ease_out_back(f32 t, f32 overshoot = 1.70158f);
915 f32 ease_in_out_back(f32 t, f32 overshoot = 1.70158f);
917 f32 ease_in_elastic(f32 t);
918 f32 ease_out_elastic(f32 t);
919 f32 ease_in_out_elastic(f32 t);
921 f32 ease_in_bounce(f32 t);
922 f32 ease_out_bounce(f32 t);
923 f32 ease_in_out_bounce(f32 t);
933 f32 srgb_to_linear(f32 v);
934 f32 linear_to_srgb(f32 v);
945 f32 luminance_rec709(
const f32vec3& rgb);
946 f32 luminance_rec709(
const f32vec4& rgba);
959 f32 radians(f32 degrees);
960 f32 degrees(f32 radians);
970 f32 atan2(f32 y, f32 x);
980 bool equal(f32 a, f32 b, f32 eps = F32_COMPARE_EPSILON);
992 f32 pow(f32 x, f32 y);
1006 constexpr T min(T a, T b) {
1007 return (b < a) ? b : a;
1011 constexpr T max(T a, T b) {
1012 return (a < b) ? b : a;
1016 constexpr T clamp(T v, T lo, T hi) {
1017 return (v < lo) ? lo : (hi < v) ? hi : v;
1020 f32 clamp_01(f32 t);
1021 f32vec2 clamp_01(
const f32vec2& v);
1022 f32vec3 clamp_01(
const f32vec3& v);
1023 f32vec4 clamp_01(
const f32vec4& v);
1027 f32 fmod(f32 x, f32 y);
1028 f32 mod(f32 x, f32 y);
1029 f32 wrap(f32 x, f32 lo, f32 hi);
1034 bool is_infinite(f32 n);
1035 bool is_finite(f32 n);
1036 bool sign_bit(f32 n);
1040 void swap(f32& a, f32& b);
1042 template<
class T2, std::
size_t N>
1043 void swap(T2 (&a)[N], T2 (&b)[N]) {
1044 for (std::size_t i = 0; i < N; ++i) {
1045 std::swap(a[i], b[i]);
const f32vec2 & operator[](std::size_t i) const
f32vec2 & operator[](std::size_t i)
f32vec3 & operator[](std::size_t i)
f32vec4 & operator[](std::size_t i)
f32 & operator[](std::size_t i)
f32 & operator[](std::size_t i)
f32 & operator[](std::size_t i)
f32 & operator[](std::size_t i)
i32 & operator[](std::size_t i)
const i32 & operator[](std::size_t i) const
i32 & operator[](std::size_t i)
const i32 & operator[](std::size_t i) const
i32 & operator[](std::size_t i)
u32 & operator[](std::size_t i)
u32 & operator[](std::size_t i)
u32 & operator[](std::size_t i)
u8 & operator[](std::size_t i)
u8 & operator[](std::size_t i)
u8 & operator[](std::size_t i)