mirror of
https://github.com/g-truc/glm.git
synced 2024-11-26 18:24:35 +00:00
Merge branch '0.9.3' into swizzle
This commit is contained in:
commit
283f7882da
@ -92,8 +92,8 @@ GLM_FUNC_QUALIFIER genType gaussRand
|
||||
|
||||
do
|
||||
{
|
||||
x1 = compRand1(genType(-1), genType(1));
|
||||
x2 = compRand1(genType(-1), genType(1));
|
||||
x1 = linearRand(genType(-1), genType(1));
|
||||
x2 = linearRand(genType(-1), genType(1));
|
||||
|
||||
w = x1 * x1 + x2 * x2;
|
||||
} while(w > genType(1));
|
||||
@ -141,7 +141,7 @@ GLM_FUNC_QUALIFIER detail::tvec4<T> gaussRand
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
GLM_FUNC_QUALIFIER detail::tvec3<T> diskRand
|
||||
GLM_FUNC_QUALIFIER detail::tvec2<T> diskRand
|
||||
(
|
||||
T const & Radius
|
||||
)
|
||||
@ -151,7 +151,7 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> diskRand
|
||||
|
||||
do
|
||||
{
|
||||
Result = compRand2(-Radius, Radius);
|
||||
Result = linearRand(detail::tvec2<T>(-Radius), detail::tvec2<T>(Radius));
|
||||
LenRadius = length(Result);
|
||||
}
|
||||
while(LenRadius > Radius);
|
||||
@ -170,7 +170,7 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> ballRand
|
||||
|
||||
do
|
||||
{
|
||||
Result = compRand3(-Radius, Radius);
|
||||
Result = linearRand(detail::tvec3<T>(-Radius), detail::tvec3<T>(Radius));
|
||||
LenRadius = length(Result);
|
||||
}
|
||||
while(LenRadius > Radius);
|
||||
@ -194,8 +194,8 @@ GLM_FUNC_QUALIFIER detail::tvec3<T> sphericalRand
|
||||
T const & Radius
|
||||
)
|
||||
{
|
||||
T z = compRand1(T(-1), T(1));
|
||||
T a = compRand1(T(0), T(6.283185307179586476925286766559f));
|
||||
T z = linearRand(T(-1), T(1));
|
||||
T a = linearRand(T(0), T(6.283185307179586476925286766559f));
|
||||
|
||||
T r = sqrt(T(1) - z * z);
|
||||
|
||||
|
@ -695,52 +695,52 @@ GLM_FUNC_QUALIFIER T simplex(detail::tvec3<T> const & v)
|
||||
detail::tvec4<T> const D(0.0, 0.5, 1.0, 2.0);
|
||||
|
||||
// First corner
|
||||
detail::tvec3<T> i = floor(v + dot(v, detail::tvec3<T>(C.y)));
|
||||
detail::tvec3<T> x0 = v - i + dot(i, detail::tvec3<T>(C.x));
|
||||
detail::tvec3<T> i(floor(v + dot(v, detail::tvec3<T>(C.y))));
|
||||
detail::tvec3<T> x0(v - i + dot(i, detail::tvec3<T>(C.x)));
|
||||
|
||||
// Other corners
|
||||
detail::tvec3<T> g = step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0);
|
||||
detail::tvec3<T> l = T(1) - g;
|
||||
detail::tvec3<T> i1 = min(g, detail::tvec3<T>(l.z, l.x, l.y));
|
||||
detail::tvec3<T> i2 = max(g, detail::tvec3<T>(l.z, l.x, l.y));
|
||||
detail::tvec3<T> g(step(detail::tvec3<T>(x0.y, x0.z, x0.x), x0));
|
||||
detail::tvec3<T> l(T(1) - g);
|
||||
detail::tvec3<T> i1(min(g, detail::tvec3<T>(l.z, l.x, l.y)));
|
||||
detail::tvec3<T> i2(max(g, detail::tvec3<T>(l.z, l.x, l.y)));
|
||||
|
||||
// x0 = x0 - 0.0 + 0.0 * C.xxx;
|
||||
// x1 = x0 - i1 + 1.0 * C.xxx;
|
||||
// x2 = x0 - i2 + 2.0 * C.xxx;
|
||||
// x3 = x0 - 1.0 + 3.0 * C.xxx;
|
||||
detail::tvec3<T> x1 = x0 - i1 + C.x;
|
||||
detail::tvec3<T> x2 = x0 - i2 + C.y; // 2.0*C.x = 1/3 = C.y
|
||||
detail::tvec3<T> x3 = x0 - D.y; // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
detail::tvec3<T> x1(x0 - i1 + C.x);
|
||||
detail::tvec3<T> x2(x0 - i2 + C.y); // 2.0*C.x = 1/3 = C.y
|
||||
detail::tvec3<T> x3(x0 - D.y); // -1.0+3.0*C.x = -0.5 = -D.y
|
||||
|
||||
// Permutations
|
||||
i = mod289(i);
|
||||
detail::tvec4<T> p = permute(permute(permute(
|
||||
detail::tvec4<T> p(permute(permute(permute(
|
||||
i.z + detail::tvec4<T>(T(0), i1.z, i2.z, T(1))) +
|
||||
i.y + detail::tvec4<T>(T(0), i1.y, i2.y, T(1))) +
|
||||
i.x + detail::tvec4<T>(T(0), i1.x, i2.x, T(1)));
|
||||
i.x + detail::tvec4<T>(T(0), i1.x, i2.x, T(1))));
|
||||
|
||||
// Gradients: 7x7 points over a square, mapped onto an octahedron.
|
||||
// The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
|
||||
T n_ = T(0.142857142857); // 1.0/7.0
|
||||
detail::tvec3<T> ns = n_ * detail::tvec3<T>(D.w, D.y, D.z) - detail::tvec3<T>(D.x, D.z, D.x);
|
||||
detail::tvec3<T> ns(n_ * detail::tvec3<T>(D.w, D.y, D.z) - detail::tvec3<T>(D.x, D.z, D.x));
|
||||
|
||||
detail::tvec4<T> j = p - T(49) * floor(p * ns.z * ns.z); // mod(p,7*7)
|
||||
detail::tvec4<T> j(p - T(49) * floor(p * ns.z * ns.z)); // mod(p,7*7)
|
||||
|
||||
detail::tvec4<T> x_ = floor(j * ns.z);
|
||||
detail::tvec4<T> y_ = floor(j - T(7) * x_); // mod(j,N)
|
||||
detail::tvec4<T> x_(floor(j * ns.z));
|
||||
detail::tvec4<T> y_(floor(j - T(7) * x_)); // mod(j,N)
|
||||
|
||||
detail::tvec4<T> x = x_ * ns.x + ns.y;
|
||||
detail::tvec4<T> y = y_ * ns.x + ns.y;
|
||||
detail::tvec4<T> h = T(1) - abs(x) - abs(y);
|
||||
detail::tvec4<T> x(x_ * ns.x + ns.y);
|
||||
detail::tvec4<T> y(y_ * ns.x + ns.y);
|
||||
detail::tvec4<T> h(T(1) - abs(x) - abs(y));
|
||||
|
||||
detail::tvec4<T> b0(x.x, x.y, y.x, y.y);
|
||||
detail::tvec4<T> b1(x.z, x.w, y.z, y.w);
|
||||
|
||||
// vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
|
||||
// vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
|
||||
detail::tvec4<T> s0 = floor(b0) * T(2) + T(1);
|
||||
detail::tvec4<T> s1 = floor(b1) * T(2) + T(1);
|
||||
detail::tvec4<T> sh = -step(h, detail::tvec4<T>(0.0));
|
||||
detail::tvec4<T> s0(floor(b0) * T(2) + T(1));
|
||||
detail::tvec4<T> s1(floor(b1) * T(2) + T(1));
|
||||
detail::tvec4<T> sh(-step(h, detail::tvec4<T>(0.0)));
|
||||
|
||||
detail::tvec4<T> a0 = detail::tvec4<T>(b0.x, b0.z, b0.y, b0.w) + detail::tvec4<T>(s0.x, s0.z, s0.y, s0.w) * detail::tvec4<T>(sh.x, sh.x, sh.y, sh.y);
|
||||
detail::tvec4<T> a1 = detail::tvec4<T>(b1.x, b1.z, b1.y, b1.w) + detail::tvec4<T>(s1.x, s1.z, s1.y, s1.w) * detail::tvec4<T>(sh.z, sh.z, sh.w, sh.w);
|
||||
|
@ -12,13 +12,36 @@
|
||||
#include <cstdio>
|
||||
|
||||
static int test_vec3_operators()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f);
|
||||
glm::vec3 B(1.0f);
|
||||
bool R = A != B;
|
||||
bool S = A == B;
|
||||
|
||||
return (S && !R) ? 0 : 1;
|
||||
Error += (S && !R) ? 0 : 1;
|
||||
}
|
||||
|
||||
{
|
||||
glm::vec3 A(1.0f, 2.0f, 3.0f);
|
||||
glm::vec3 B(4.0f, 5.0f, 6.0f);
|
||||
|
||||
glm::vec3 C = A + B;
|
||||
Error += C == glm::vec3(5, 7, 9) ? 0 : 1;
|
||||
|
||||
glm::vec3 D = B - A;
|
||||
Error += D == glm::vec3(3, 3, 3) ? 0 : 1;
|
||||
|
||||
glm::vec3 E = A * B;
|
||||
Error += E == glm::vec3(4, 10, 18) ? 0 : 1;
|
||||
|
||||
glm::vec3 F = B / A;
|
||||
Error += F == glm::vec3(4, 2.5, 2) ? 0 : 1;
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_vec3_size()
|
||||
|
@ -32,8 +32,8 @@ int test_linearRand()
|
||||
|
||||
return Error;
|
||||
}
|
||||
/*
|
||||
int test_normalizedRand2()
|
||||
|
||||
int test_circularRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@ -41,21 +41,23 @@ int test_normalizedRand2()
|
||||
std::size_t Max = 100000;
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
double Radius = 2.0f;
|
||||
|
||||
for(std::size_t i = 0; i < Max; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::normalizedRand2(1.0f, 1.0f));
|
||||
ResultDouble += glm::length(glm::normalizedRand2(1.0f, 1.0f));
|
||||
ResultFloat += glm::length(glm::circularRand(1.0f));
|
||||
ResultDouble += glm::length(glm::circularRand(Radius));
|
||||
}
|
||||
|
||||
Error += glm::equalEpsilon(ResultFloat, float(Max), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDouble, double(Max), 0.01) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDouble, double(Max) * double(Radius), 0.01) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_normalizedRand3()
|
||||
int test_sphericalRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
@ -67,35 +69,82 @@ int test_normalizedRand3()
|
||||
double ResultDoubleA = 0.0f;
|
||||
double ResultDoubleB = 0.0f;
|
||||
double ResultDoubleC = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < Max; ++i)
|
||||
{
|
||||
ResultFloatA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
|
||||
ResultDoubleA += glm::length(glm::normalizedRand3(1.0f, 1.0f));
|
||||
ResultFloatB += glm::length(glm::normalizedRand3(2.0f, 2.0f));
|
||||
ResultDoubleB += glm::length(glm::normalizedRand3(2.0, 2.0));
|
||||
ResultFloatC += glm::length(glm::normalizedRand3(1.0f, 3.0f));
|
||||
ResultDoubleC += glm::length(glm::normalizedRand3(1.0, 3.0));
|
||||
ResultFloatA += glm::length(glm::sphericalRand(1.0f));
|
||||
ResultDoubleA += glm::length(glm::sphericalRand(1.0));
|
||||
ResultFloatB += glm::length(glm::sphericalRand(2.0f));
|
||||
ResultDoubleB += glm::length(glm::sphericalRand(2.0));
|
||||
ResultFloatC += glm::length(glm::sphericalRand(3.0f));
|
||||
ResultDoubleC += glm::length(glm::sphericalRand(3.0));
|
||||
}
|
||||
|
||||
Error += glm::equalEpsilon(ResultFloatA, float(Max), 100.0f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 100.0) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 100.0001f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 100.0001) ? 0 : 1;
|
||||
Error += (ResultFloatC >= float(Max) && ResultFloatC <= float(Max * 3)) ? 0 : 1;
|
||||
Error += (ResultDoubleC >= double(Max) && ResultDoubleC <= double(Max * 3)) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatA, float(Max), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleA, double(Max), 0.0001) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatB, float(Max * 2), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleB, double(Max * 2), 0.0001) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultFloatC, float(Max * 3), 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(ResultDoubleC, double(Max * 3), 0.01) ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
*/
|
||||
|
||||
int test_diskRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < 100000; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::diskRand(2.0f));
|
||||
ResultDouble += glm::length(glm::diskRand(2.0));
|
||||
}
|
||||
|
||||
Error += ResultFloat < 200000.f ? 0 : 1;
|
||||
Error += ResultDouble < 200000.0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_ballRand()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
float ResultFloat = 0.0f;
|
||||
double ResultDouble = 0.0f;
|
||||
|
||||
for(std::size_t i = 0; i < 100000; ++i)
|
||||
{
|
||||
ResultFloat += glm::length(glm::ballRand(2.0f));
|
||||
ResultDouble += glm::length(glm::ballRand(2.0));
|
||||
}
|
||||
|
||||
Error += ResultFloat < 200000.f ? 0 : 1;
|
||||
Error += ResultDouble < 200000.0 ? 0 : 1;
|
||||
assert(!Error);
|
||||
}
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
Error += test_linearRand();
|
||||
//Error += test_normalizedRand2();
|
||||
//Error += test_normalizedRand3();
|
||||
Error += test_circularRand();
|
||||
Error += test_sphericalRand();
|
||||
Error += test_diskRand();
|
||||
Error += test_ballRand();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user