Commit 8e4a9c9c authored by Julian Schakib's avatar Julian Schakib
Browse files

Merge branch 'develop' into add-intersections

parents 160f37cd a5cc5113
Pipeline #13544 failed with stage
in 1 minute and 7 seconds
......@@ -27,7 +27,7 @@ int main()
tg::sphere3 sphere;
tg::box3 box;
tg::cone3 cone;
tg::tube3 tube;
tg::cylinder_boundary_no_caps<3, float> tube;
data() {}
} d;
......@@ -104,7 +104,7 @@ int main()
break;
case 2:
p.type = prim::cone;
p.d.cone = tg::cone3(tg::disk3(uniform(rng, aabb), uniform(rng, 1.0f, 3.0f), tg::uniform<tg::dir3>(rng)), uniform(rng, 1.0f, 3.0f));
p.d.cone = tg::cone3({uniform(rng, aabb), uniform(rng, 1.0f, 3.0f), tg::uniform<tg::dir3>(rng)}, uniform(rng, 1.0f, 3.0f));
break;
case 3:
p.type = prim::tube;
......
......@@ -25,9 +25,9 @@ struct environment
environment()
{
for (auto i = 0; i < 100; ++i)
pts.push_back(uniform(rng, tg::ball3({0, 0, 0}, 1)));
pts.push_back(uniform(rng, tg::sphere3({0, 0, 0}, 1)));
for (auto i = 0; i < 100; ++i)
pts.push_back(uniform(rng, tg::ball3({2, 0, 0}, 1)));
pts.push_back(uniform(rng, tg::sphere3({2, 0, 0}, 1)));
// for (auto i = 0; i < 100; ++i)
// pts.push_back(uniform(rng, tg::aabb3({-1, 0, -1}, {1, 0, 1})));
// for (auto i = 0; i < 100; ++i)
......@@ -58,7 +58,7 @@ struct environment
individual mutated_individual(individual const& id) const
{
auto new_id = id; // copy
new_id.obb.center += tg::uniform_vec(rng, tg::ball3::unit) * 0.1f;
new_id.obb.center += tg::uniform_vec(rng, tg::sphere3::unit) * 0.1f;
auto rot = tg::rotation_around(tg::uniform<tg::dir3>(rng), uniform(rng, 0_deg, 3_deg));
for (auto i = 0; i < 3; ++i)
new_id.obb.half_extents[i] = rot * new_id.obb.half_extents[i] * uniform(rng, 0.9f, 1.1f);
......
#include <doctest.hh>
#include <ctracer/benchmark.hh>
#include <typed-geometry/tg.hh>
#include <thread>
namespace ct
{
sink_t operator<<(sink_t s, tg::vec3 v) { return s << v.x << v.y << v.z; }
}
template <>
struct ct::source<tg::vec3>
{
explicit source(tg::vec3 v) : x(v.x), y(v.y), z(v.z) {}
operator tg::vec3() const { return {x, y, z}; }
private:
source<float> x, y, z;
};
TEST_CASE("benchmark")
{
#ifdef TG_RELEASE
CHECK(ct::benchmark([](tg::vec3 v) { return cross(v, v); }, tg::vec3::zero).cycles_per_sample() < 20);
#endif
return;
// print tests:
ct::benchmark([](int a, int b) { return a % b; }, 17, 5).print_summary("a % b (32bit): ");
ct::benchmark([](int64_t a, int64_t b) { return a % b; }, 17, 5).print_summary("a % b (64bit): ");
ct::benchmark([](double a, double b, double c) { return length(tg::vec(a, b, c)); }, 1, 1, 1).print_summary("tg::length(vec3): ");
ct::benchmark(
[](int c) {
std::vector<float> v;
tg::rng rng;
for (auto i = 0; i < c; ++i)
v.push_back(uniform(rng, 0.0f, 1.0f));
return tg::sum(v);
},
100)
.print_summary("100 randoms: ");
tg::rng rng;
ct::benchmark([&] { return rng(); }).print_summary("rng: ");
ct::benchmark([&] { return uniform(rng, 1, 100); }).print_summary("uniform int: ");
ct::benchmark([](tg::vec3 v) { return cross(v, v); }, tg::vec3::zero).print_summary("cross: ");
}
#pragma once
// include this header temporarily for debugging a test
#include <iostream>
#include <typed-geometry/tg-std.hh>
#include <test.hh>
TEST_CASE("tg::wrap")
{
CHECK(tg::wrap(0.3f, 0.1f, 0.4f) == approx(0.3f));
CHECK(tg::wrap(0.35f, 0.1f, 0.2f) == approx(0.15f));
CHECK(tg::wrap(-.3f, 0.0f, 1.0f) == approx(0.7f));
}
TG_FUZZ_TEST(Wrap, Random)
{
auto range = uniform(rng, 0.1f, 5.0f);
auto vmin = uniform(rng, -10.f, 10.f);
auto vmax = vmin + range;
auto v0 = uniform(rng, vmin, vmax);
auto v1 = v0 + uniform(rng, -10, 10) * range;
CHECK(tg::wrap(v1, vmin, vmax) == approx(v0));
}
#include <test.hh>
#include <typed-geometry/feature/bezier.hh>
TEST_CASE("bezier basics")
{
auto p0 = tg::pos3(1, 0, 0);
auto p1 = tg::pos3(0, 1, 0);
auto p2 = tg::pos3(0, 0, 1);
auto p3 = tg::pos3(1, 1, 1);
auto b = tg::make_bezier(p0, p1, p2, p3);
auto bb = tg::aabb_of(p0, p1, p2, p3);
CHECK(b[0.0f] == approx(p0));
CHECK(b[1.0f] == approx(p3));
tg::rng rng;
for (auto i = 0; i < 100; ++i)
{
auto t = uniform(rng, 0.0f, 1.0f);
CHECK(contains(bb, b[t]));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment