Commit a071a775 authored by Philip Trettner's avatar Philip Trettner
Browse files

Merge remote-tracking branch 'origin/agrabowy' into develop

parents 5db7cee5 33801c9d
Pipeline #13564 failed with stage
in 6 minutes and 14 seconds
glow-extras @ 2f3aa099
Subproject commit a821ee75e99e1303060aed3048732b35e01adab4
Subproject commit 2f3aa099ae50bed454a76911421db7279782464b
polymesh @ feb3d897
Subproject commit 567b64bf34667d95b834fbd01db24c2d18aff21d
Subproject commit feb3d897362c7985cc74f170f0411bfda1bc5366
typed-geometry @ b12ec805
Subproject commit 9849f4f05262ca94a55a3027ea04d5e38f62d542
Subproject commit b12ec80542d08fbf917e2927696d53a53f9acf2c
......@@ -15,7 +15,7 @@ TG_FUZZ_TEST(TypedGeometry, Area)
auto alpha = tg::radians(tg::abs(uniform(rng, box1).x) * tg::pi_scalar<tg::f32>);
auto rotation = tg::mat2::from_cols(tg::vec2(tg::cos(alpha), -sin(alpha)), tg::vec2(sin(alpha), cos(alpha)));
tg::f32 randomScale = 0;
int max = 10;
auto max = 10.f;
while (randomScale == 0)
randomScale = max * uniform(rng, box1).x;
auto scale = tg::mat2::from_cols(tg::vec2(randomScale, 0), tg::vec2(0, randomScale));
......@@ -67,7 +67,7 @@ TG_FUZZ_TEST(TypedGeometry, Area)
auto rotation = rotation_x(alpha) * rotation_y(alpha) * rotation_z(alpha);
tg::f32 randomScale = 0;
int max = 10;
auto max = 10.f;
while (randomScale == 0)
randomScale = max * uniform(rng, box1).x;
......
......@@ -52,7 +52,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// 3D
auto a = uniform(rng, rBox3);
auto dir = normalize(tg::vec3(uniform(rng, rBox3)));
auto rd = tg::uniform(rng, rBox1).x;
auto rd = uniform(rng, rBox1).x;
auto b = a + dir * rd;
CHECK(distance(a, b) == approx(tg::abs(rd)));
......@@ -69,7 +69,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// 2D
auto a = uniform(rng, rBox2);
auto dir = normalize(tg::vec2(uniform(rng, rBox2)));
auto rd = tg::uniform(rng, rBox1).x;
auto rd = uniform(rng, rBox1).x;
auto b = a + dir * rd;
CHECK(distance(a, b) == approx(tg::abs(rd)));
......@@ -86,7 +86,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// 1D
auto a = uniform(rng, rBox1);
auto dir = normalize(tg::vec1(uniform(rng, rBox1)));
auto rd = tg::uniform(rng, rBox1).x;
auto rd = uniform(rng, rBox1).x;
auto b = a + dir * rd;
CHECK(distance(a, b) == approx(tg::abs(rd)));
......@@ -103,17 +103,17 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// distance to origin
{
auto p = uniform(rng, rBox1);
auto d = tg::distance_to_origin(p);
auto d = distance_to_origin(p);
CHECK(d == approx(tg::length(tg::vec1(p))));
}
{
auto p = uniform(rng, rBox2);
auto d = tg::distance_to_origin(p);
auto d = distance_to_origin(p);
CHECK(d == approx(tg::length(tg::vec2(p))));
}
{
auto p = uniform(rng, rBox3);
auto d = tg::distance_to_origin(p);
auto d = distance_to_origin(p);
CHECK(d == approx(tg::length(tg::vec3(p))));
}
......@@ -153,8 +153,8 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// inf_cone and pos
{
auto icone = tg::inf_cone3(tg::pos3(uniform(rng, rBox3)), tg::normalize(tg::vec3(uniform(rng, rBox3))),
uniform(rng, tg::angle::from_degree(1.f), tg::angle::from_degree(179.f)));
auto icone = tg::inf_cone_boundary<3, float>(tg::pos3(uniform(rng, rBox3)), normalize(tg::vec3(uniform(rng, rBox3))),
uniform(rng, tg::angle::from_degree(1.f), tg::angle::from_degree(179.f)));
auto l = uniform(rng, 0.1f, 2.f);
auto pt = icone.apex - l * icone.opening_dir;
auto d2 = distance_sqr(pt, icone);
......@@ -170,9 +170,9 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
CHECK(d2 > 0);
l = uniform(rng, 0.f, 10.f);
auto r = tg::tan(icone.opening_angle / 2) * l;
auto rand_dir = tg::normalize(tg::vec3(uniform(rng, rBox3)));
auto rand_n = tg::normalize(tg::cross(rand_dir, icone.opening_dir));
auto ortho_dir = tg::normalize(tg::cross(rand_n, icone.opening_dir));
auto rand_dir = normalize(tg::vec3(uniform(rng, rBox3)));
auto rand_n = normalize(cross(rand_dir, icone.opening_dir));
auto ortho_dir = normalize(cross(rand_n, icone.opening_dir));
pt = icone.apex + l * icone.opening_dir + r * ortho_dir;
d = distance(pt, icone);
d2 = distance_sqr(pt, icone);
......@@ -182,7 +182,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
d = distance(icone.apex, icone);
CHECK(d == approx(0).epsilon(0.01));
pt = {2, -4, 0};
icone = tg::inf_cone3({0, 0, 0}, {0, 0, 1}, tg::angle::from_degree(90));
icone = tg::inf_cone_boundary<3, float>({0, 0, 0}, {0, 0, 1}, tg::angle::from_degree(90));
d2 = distance_sqr(pt, icone);
CHECK(d2 == approx(10));
l = uniform(rng, 0.f, 10.f);
......@@ -196,7 +196,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
{
auto sp = tg::sphere_boundary<3, tg::f32>(tg::pos3(uniform(rng, rBox3)), uniform(rng, 0.f, 10.f));
auto l = uniform(rng, 0.f, 10.f);
auto rand_dir = tg::normalize(tg::vec3(uniform(rng, rBox3)));
auto rand_dir = normalize(tg::vec3(uniform(rng, rBox3)));
auto pt = sp.center + l * rand_dir;
auto d2 = distance_sqr(pt, sp);
auto d = distance(pt, sp);
......@@ -209,7 +209,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
CHECK(d == approx(0).epsilon(0.01));
auto sp2 = tg::sphere_boundary<2, tg::f32>(tg::pos2(uniform(rng, rBox2)), uniform(rng, 0.f, 10.f));
l = uniform(rng, 0.f, 10.f);
auto rand_dir2 = tg::normalize(tg::vec2(uniform(rng, rBox2)));
auto rand_dir2 = normalize(tg::vec2(uniform(rng, rBox2)));
auto pt2 = sp2.center + l * rand_dir2;
d2 = distance_sqr(pt2, sp2);
d = distance(pt2, sp2);
......@@ -221,9 +221,9 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// inf_cylinder and pos
{
auto itube = tg::inf_cylinder3({tg::pos3(uniform(rng, rBox3)), tg::normalize(tg::vec3(uniform(rng, rBox3)))}, uniform(rng, 0.f, 10.f));
auto rand_dir = tg::normalize(tg::vec3(uniform(rng, rBox3)));
auto rand_n = tg::normalize(tg::cross(rand_dir, itube.axis.dir));
auto itube = tg::inf_cylinder3({tg::pos3(uniform(rng, rBox3)), normalize(tg::vec3(uniform(rng, rBox3)))}, uniform(rng, 0.f, 10.f));
auto rand_dir = normalize(tg::vec3(uniform(rng, rBox3)));
auto rand_n = normalize(cross(rand_dir, itube.axis.dir));
auto ortho_dir = tg::normalize(tg::cross(rand_n, itube.axis.dir));
auto l = uniform(rng, -10.f, 10.f);
auto r = uniform(rng, 0.f, 10.f);
......@@ -234,7 +234,7 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
CHECK(d * d == approx(d2));
CHECK(d == approx(sqrt(d2)));
auto itube2 = tg::inf_cylinder<2, tg::f32>({tg::pos2(uniform(rng, rBox2)), tg::normalize(tg::vec2(uniform(rng, rBox2)))}, uniform(rng, 0.f, 10.f));
auto itube2 = tg::inf_cylinder<2, tg::f32>({tg::pos2(uniform(rng, rBox2)), normalize(tg::vec2(uniform(rng, rBox2)))}, uniform(rng, 0.f, 10.f));
tg::vec2 ortho_dir2 = {-itube2.axis.dir[1], itube2.axis.dir[0]};
l = uniform(rng, -10.f, 10.f);
r = uniform(rng, 0.f, 10.f);
......@@ -248,12 +248,11 @@ TG_FUZZ_TEST(TypedGeometry, Distance)
// cylinder and pos
{
auto c = tg::cylinder3({-1, -2, -3}, {5, -2, -3}, 2);
auto c = tg::cylinder_boundary<3, float>({-1, -2, -3}, {5, -2, -3}, 2);
CHECK(distance(tg::pos3(-1, -2, -3), c) == approx(0));
CHECK(distance(tg::pos3(5, -2, -3), c) == approx(0));
// TODO pos3 inside cylinder, distance to hull is approx(1)
// current tg: distance(..) = approx(0)
//CHECK(distance(tg::pos3(0, -2, -3), c) == approx(1));
CHECK(distance(tg::pos3(0, -2, -3), c) == approx(1));
CHECK(distance(tg::pos3(2, -2, -3), c) == approx(2));
CHECK(distance(tg::pos3(-1, -3, -3), c) == approx(0));
}
}
......@@ -15,7 +15,7 @@ TG_FUZZ_TEST(TypedGeometry, Interpolate)
auto alpha = tg::radians(tg::abs(uniform(rng, box1).x) * tg::pi_scalar<tg::f32>);
auto rotation = tg::mat2::from_cols(tg::vec2(tg::cos(alpha), -sin(alpha)), tg::vec2(sin(alpha), cos(alpha)));
tg::f32 randomScale = 0;
int max = 10;
auto max = 10.f;
while (randomScale == 0)
randomScale = max * uniform(rng, box1).x;
auto scale = tg::mat2::from_cols(tg::vec2(randomScale, 0), tg::vec2(0, randomScale));
......@@ -62,7 +62,7 @@ TG_FUZZ_TEST(TypedGeometry, Interpolate)
auto rotation = rotation_x(alpha) * rotation_y(alpha) * rotation_z(alpha);
tg::f32 randomScale = 0;
int max = 10;
auto max = 10.f;
while (randomScale == 0)
randomScale = max * uniform(rng, box1).x;
......
#include "test.hh"
TG_FUZZ_TEST(TypedGeometry, Project)
#include <typed-geometry/tg-std.hh>
#include <iostream>
TG_FUZZ_TEST_MAX_ITS(TypedGeometry, Project, 20)
{
auto const test_obj = [&rng](auto p, auto o) {
auto proj = project(p, o);
// Projected point lies in the object
auto dist = distance_sqr(proj, o);
CHECK(dist == approx(0.0f));
CHECK(contains(o, proj, 0.01f));
dist = distance_sqr(proj, p);
if (contains(o, p)) // If inside by chance, the projection does not change anything
CHECK(dist == approx(0.0f));
else // Otherwise all other points inside are not closer than the projection
for (auto i = 0; i < 256; i++)
{
auto q = uniform(rng, o);
CHECK(distance_sqr(q, p) >= approx(dist));
}
// Projection of points already sampled from inside changes nothing
auto pInside = uniform(rng, o);
proj = project(pInside, o);
dist = distance_sqr(proj, pInside);
CHECK(dist == approx(0.0f));
};
auto const test_obj_and_boundary = [&test_obj](auto p, auto o) {
test_obj(p, o);
test_obj(p, boundary_of(o));
};
auto const test_obj_and_boundary_no_caps = [&test_obj](auto p, auto o) {
test_obj(p, o);
test_obj(p, boundary_of(o));
test_obj(p, boundary_no_caps_of(o));
};
const auto r = uniform(rng, 0.0f, 10.0f);
const auto n2 = tg::dir(uniform(rng, tg::sphere_boundary<2, float>::unit));
const auto n3 = tg::dir(uniform(rng, tg::sphere_boundary<3, float>::unit));
const auto range1 = tg::aabb1(tg::pos1(-10), tg::pos1(10));
const auto range2 = tg::aabb2(tg::pos2(-10), tg::pos2(10));
const auto range3 = tg::aabb3(tg::pos3(-10), tg::pos3(10));
const auto range4 = tg::aabb4(tg::pos4(-10), tg::pos4(10));
const auto p1 = uniform(rng, range1);
const auto p2 = uniform(rng, range2);
const auto p3 = uniform(rng, range3);
const auto p4 = uniform(rng, range4);
const auto pos10 = uniform(rng, range1);
const auto pos11 = uniform(rng, range1);
const auto pos20 = uniform(rng, range2);
const auto pos21 = uniform(rng, range2);
const auto pos22 = uniform(rng, range2);
const auto pos30 = uniform(rng, range3);
const auto pos31 = uniform(rng, range3);
const auto pos32 = uniform(rng, range3);
const auto pos40 = uniform(rng, range4);
const auto pos41 = uniform(rng, range4);
const auto minPos1 = min(pos10, pos11);
const auto maxPos1 = max(pos10, pos11);
const auto minPos2 = min(pos20, pos21);
const auto maxPos2 = max(pos20, pos21);
const auto minPos3 = min(pos30, pos31);
const auto maxPos3 = max(pos30, pos31);
const auto minPos4 = min(pos40, pos41);
const auto maxPos4 = max(pos40, pos41);
const auto axis0 = tg::segment3(pos30, pos31);
const auto disk0 = tg::sphere2in3(pos30, r, n3);
auto d1 = tg::uniform<tg::dir1>(rng);
auto m1 = tg::mat1();
m1[0] = d1 * uniform(rng, 1.0f, 3.0f);
auto d20 = tg::uniform<tg::dir2>(rng);
auto d21 = perpendicular(d20);
auto m2 = tg::mat2();
m2[0] = d20 * uniform(rng, 1.0f, 3.0f);
m2[1] = d21 * uniform(rng, 1.0f, 3.0f);
auto d30 = tg::uniform<tg::dir3>(rng);
auto d31 = any_normal(d30);
auto d32 = normalize(cross(d30, d31));
auto m3 = tg::mat3();
m3[0] = d30 * uniform(rng, 1.0f, 3.0f);
m3[1] = d31 * uniform(rng, 1.0f, 3.0f);
m3[2] = d32 * uniform(rng, 1.0f, 3.0f);
auto m23 = tg::mat2x3();
m23[0] = d30 * uniform(rng, 1.0f, 3.0f);
m23[1] = d31 * uniform(rng, 1.0f, 3.0f);
// aabb
// TODO: And boundary
test_obj(p1, tg::aabb1(minPos1, maxPos1));
test_obj(p2, tg::aabb2(minPos2, maxPos2));
test_obj(p3, tg::aabb3(minPos3, maxPos3));
test_obj(p4, tg::aabb4(minPos4, maxPos4));
// box
// TODO: And boundary
test_obj(p1, tg::box1(pos10, m1));
test_obj(p2, tg::box2(pos20, m2));
test_obj(p3, tg::box3(pos30, m3));
// TODO: box4
// test_obj(p3, tg::box2in3(pos30, m23)); // TODO: box2in3
// capsule
test_obj_and_boundary(p3, tg::capsule3(axis0, r));
// cone
// TODO: And boundary no caps
// test_obj(p3, tg::cone3(disk0, r)); // TODO: solid cone
test_obj(p3, tg::cone_boundary_no_caps<3, float>(disk0, r));
// cylinder
test_obj_and_boundary_no_caps(p3, tg::cylinder3(axis0, r));
// hemisphere
// TODO: And boundary no caps
// test_obj(p1, tg::hemisphere1(pos10, r, n1));
test_obj(p2, tg::hemisphere2(pos20, r, n2));
test_obj(p3, tg::hemisphere3(pos30, r, n3));
// test_obj(p4, tg::hemisphere4(pos40, r, n4));
// TODO: pyramid once implemented
// test_obj(p3, tg::pyramid3(rect0, r));
// segment
test_obj(p1, tg::segment1(pos10, pos11));
test_obj(p2, tg::segment2(pos20, pos21));
test_obj(p3, tg::segment3(pos30, pos31));
test_obj(p4, tg::segment4(pos40, pos41));
// sphere
test_obj_and_boundary(p1, tg::sphere1(pos10, r));
test_obj_and_boundary(p2, tg::sphere2(pos20, r));
test_obj_and_boundary(p3, tg::sphere3(pos30, r));
test_obj_and_boundary(p4, tg::sphere4(pos40, r));
test_obj_and_boundary(p3, tg::sphere2in3(pos30, r, n3));
// triangle
(void)pos22;
(void)pos32;
// FIXME: test_obj(p2, tg::triangle2(pos20, pos21, pos22));
// FIXME: test_obj(p3, tg::triangle3(pos30, pos31, pos32));
// test_obj(p4, tg::triangle4(pos40, pos41, pos42));
}
TG_FUZZ_TEST(TypedGeometry, ProjectObjects)
{
auto range1 = tg::aabb1(tg::pos1(-10), tg::pos1(10));
auto range2 = tg::aabb2(tg::pos2(-10), tg::pos2(10));
......@@ -18,14 +172,14 @@ TG_FUZZ_TEST(TypedGeometry, Project)
auto p = uniform(rng, range3);
auto pp = tg::project(p, pl);
auto pp = project(p, pl);
// distance initial point to plane
auto dist0 = tg::distance(p, pl);
auto dist0 = distance(p, pl);
// distance initial point to point on plane
auto dist1 = tg::distance(p, pp);
auto dist1 = distance(p, pp);
// distance point on plane to plane
auto dist2 = tg::distance(pp, pl);
auto dist2 = distance(pp, pl);
CHECK(dist0 == approx(dist1));
CHECK(dist2 == approx(0.0f));
......@@ -53,8 +207,8 @@ TG_FUZZ_TEST(TypedGeometry, Project)
auto pn = p + normalize(ortho);
// project that point back, it should lie at p's position
pn = tg::project(pn, line);
auto dist1 = tg::distance_sqr(p, pn);
pn = project(pn, line);
auto dist1 = distance_sqr(p, pn);
CHECK(dist1 == approx(0.0f));
}
......@@ -70,11 +224,11 @@ TG_FUZZ_TEST(TypedGeometry, Project)
auto p = uniform(rng, range3);
auto projLine = tg::project(p, line);
auto projRay = tg::project(p, ray);
auto projLine = project(p, line);
auto projRay = project(p, ray);
// The projection onto the ray is the same as onto the line if in positive direction, otherwise at the ray origin
auto diff = tg::distance_sqr(projRay,dot(p - pos, dir) > 0 ? projLine : pos);
auto diff = distance_sqr(projRay, dot(p - pos, dir) > 0 ? projLine : pos);
CHECK(diff == approx(0.0f));
}
}
......@@ -37,6 +37,144 @@ TG_FUZZ_TEST(TypedGeometry, Uniform)
CHECK(r <= b);
}
TG_FUZZ_TEST_MAX_ITS(TypedGeometry, UniformGeneralProperties, 100)
{
const auto tolerance = 0.01f;
const tg::u64 sampleSize = 32;
auto const test_obj = [&rng, tolerance](auto samples, auto o) {
for (tg::u64 i = 0; i < samples.size(); ++i)
{
auto p = uniform(rng, o);
CHECK(contains(o, p, tolerance));
for (tg::u64 j = 0; j < i; ++j)
CHECK(p != samples[j]);
samples[i] = p;
}
};
auto const test_obj_and_boundary = [&test_obj](auto p, auto o) {
test_obj(p, o);
test_obj(p, boundary_of(o));
};
auto const test_obj_and_boundary_no_caps = [&test_obj](auto p, auto o) {
test_obj(p, o);
test_obj(p, boundary_of(o));
test_obj(p, boundary_no_caps_of(o));
};
auto samples1 = tg::array<tg::pos1, sampleSize>();
auto samples2 = tg::array<tg::pos2, sampleSize>();
auto samples3 = tg::array<tg::pos3, sampleSize>();
auto samples4 = tg::array<tg::pos4, sampleSize>();
const auto r = uniform(rng, 0.0f, 10.0f);
const auto n2 = tg::dir(uniform(rng, tg::sphere_boundary<2, float>::unit));
const auto n3 = tg::dir(uniform(rng, tg::sphere_boundary<3, float>::unit));
const auto range1 = tg::aabb1(tg::pos1(-10), tg::pos1(10));
const auto range2 = tg::aabb2(tg::pos2(-10), tg::pos2(10));
const auto range3 = tg::aabb3(tg::pos3(-10), tg::pos3(10));
const auto range4 = tg::aabb4(tg::pos4(-10), tg::pos4(10));
const auto pos10 = uniform(rng, range1);
const auto pos11 = uniform(rng, range1);
const auto pos20 = uniform(rng, range2);
const auto pos21 = uniform(rng, range2);
const auto pos22 = uniform(rng, range2);
const auto pos30 = uniform(rng, range3);
const auto pos31 = uniform(rng, range3);
const auto pos32 = uniform(rng, range3);
const auto pos40 = uniform(rng, range4);
const auto pos41 = uniform(rng, range4);
const auto minPos1 = min(pos10, pos11);
const auto maxPos1 = max(pos10, pos11);
const auto minPos2 = min(pos20, pos21);
const auto maxPos2 = max(pos20, pos21);
const auto minPos3 = min(pos30, pos31);
const auto maxPos3 = max(pos30, pos31);
const auto minPos4 = min(pos40, pos41);
const auto maxPos4 = max(pos40, pos41);
const auto axis0 = tg::segment3(pos30, pos31);
const auto disk0 = tg::sphere2in3(pos30, r, n3);
auto d1 = tg::uniform<tg::dir1>(rng);
auto m1 = tg::mat1();
m1[0] = d1 * uniform(rng, 1.0f, 3.0f);
auto d20 = tg::uniform<tg::dir2>(rng);
auto d21 = perpendicular(d20);
auto m2 = tg::mat2();
m2[0] = d20 * uniform(rng, 1.0f, 3.0f);
m2[1] = d21 * uniform(rng, 1.0f, 3.0f);
auto d30 = tg::uniform<tg::dir3>(rng);
auto d31 = any_normal(d30);
auto d32 = normalize(cross(d30, d31));
auto m3 = tg::mat3();
m3[0] = d30 * uniform(rng, 1.0f, 3.0f);
m3[1] = d31 * uniform(rng, 1.0f, 3.0f);
m3[2] = d32 * uniform(rng, 1.0f, 3.0f);
auto m23 = tg::mat2x3();
m23[0] = d30 * uniform(rng, 1.0f, 3.0f);
m23[1] = d31 * uniform(rng, 1.0f, 3.0f);
// aabb
// TODO: And boundary
test_obj(samples1, tg::aabb1(minPos1, maxPos1));
test_obj(samples2, tg::aabb2(minPos2, maxPos2));
test_obj(samples3, tg::aabb3(minPos3, maxPos3));
test_obj(samples4, tg::aabb4(minPos4, maxPos4));
// box
// TODO: And boundary
test_obj(samples1, tg::box1(pos10, m1));
test_obj(samples2, tg::box2(pos20, m2));
test_obj(samples3, tg::box3(pos30, m3));
// TODO: box4
// test_obj(samples3, tg::box2in3(pos30, m23)); // TODO: box2in3
// capsule
test_obj_and_boundary(samples3, tg::capsule3(axis0, r));
// cone
// TODO: And boundary no caps
// test_obj(samples3, tg::cone3(disk0, r)); // TODO: solid cone
test_obj(samples3, tg::cone_boundary_no_caps<3, float>(disk0, r));
// cylinder
test_obj_and_boundary_no_caps(samples3, tg::cylinder3(axis0, r));
// hemisphere
// TODO: And boundary no caps
//test_obj(samples1, tg::hemisphere1(pos10, r, n1));
test_obj(samples2, tg::hemisphere2(pos20, r, n2));
test_obj(samples3, tg::hemisphere3(pos30, r, n3));
//test_obj(samples4, tg::hemisphere4(pos40, r, n4));
// TODO: pyramid once implemented
// test_obj(samples3, tg::pyramid3(rect0, r));
// segment
test_obj(samples1, tg::segment1(pos10, pos11));
test_obj(samples2, tg::segment2(pos20, pos21));
test_obj(samples3, tg::segment3(pos30, pos31));
test_obj(samples4, tg::segment4(pos40, pos41));
// sphere
test_obj(samples1, tg::sphere1(pos10, r)); // sphere1_boundary consists of only 2 points and therefore collisions in the samples are unavoidable
test_obj_and_boundary(samples2, tg::sphere2(pos20, r));
test_obj_and_boundary(samples3, tg::sphere3(pos30, r));
test_obj_and_boundary(samples4, tg::sphere4(pos40, r));
test_obj_and_boundary(samples3, tg::sphere2in3(pos30, r, n3));
// triangle
test_obj(samples2, tg::triangle2(pos20, pos21, pos22));
test_obj(samples3, tg::triangle3(pos30, pos31, pos32));
// test_obj(samples4, tg::triangle4(pos40, pos41, pos42));
}
TG_FUZZ_TEST(TypedGeometry, UniformObjects)
{
auto range2 = tg::aabb2(tg::pos2(-10), tg::pos2(10));
......@@ -46,7 +184,7 @@ TG_FUZZ_TEST(TypedGeometry, UniformObjects)
auto c3 = uniform(rng, range3);
auto r = uniform(rng, 0.0f, 10.0f);
auto n = tg::uniform<tg::dir3>(rng);
auto tolerance = 0.01f;
auto n2 = tg::uniform<tg::dir2>(rng);
{
auto v = uniform_vec(rng, tg::sphere_boundary<3, float>::unit);
......@@ -56,43 +194,20 @@ TG_FUZZ_TEST(TypedGeometry, UniformObjects)
auto v = uniform_vec(rng, tg::sphere_boundary<3, float>::unit);
CHECK(length(v) <= 1.00001f);
}
{
auto pos0 = uniform(rng, range3);
auto pos1 = uniform(rng, range3);
auto seg = tg::segment3(pos0, pos1);
auto p1 = uniform(rng, seg);
auto p2 = uniform(rng, seg);
CHECK(contains(seg, p1, tolerance));
CHECK(contains(seg, p2, tolerance));
CHECK(p1 != p2);
}
{
auto circle = tg::sphere_boundary<2, float, 3>(c3, r, n);
auto p1 = uniform(rng, circle);
auto p2 = uniform(rng, circle);
CHECK(contains(circle, p1, tolerance));
CHECK(contains(circle, p2, tolerance));
CHECK(p1 != p2);
CHECK(distance(c3, p1) == approx(r));
CHECK(distance(c3, p2) == approx(r));
}
{
auto circle = tg::sphere_boundary<2, float>(c2, r);
auto p1 = uniform(rng, circle);
auto p2 = uniform(rng, circle);
CHECK(contains(circle, p1, tolerance));
CHECK(contains(circle, p2, tolerance));
CHECK(p1 != p2);
CHECK(distance(c2, p1) == approx(r));
CHECK(distance(c2, p2) == approx(r));
}
{
auto disk = tg::sphere2in3(c3, r, n);
auto p1 = uniform(rng, disk);