Commit 490fd596 authored by Philip Trettner's avatar Philip Trettner
Browse files

adapting tg restructure

parent 03eafc87
ctracer @ f5c89c5a
Subproject commit 56d33f9b69854c7339e8ddd71fe81095ddd5cc41
Subproject commit f5c89c5aecf75079a2d1314ebeb9020f1f091bcb
glow @ e1c480ed
Subproject commit 07f89ff39a198aa740e6a373c9c3942c339a4028
Subproject commit e1c480ed87846262c22f71ced91766ed858323aa
glow-extras @ 3901eebe
Subproject commit 4f3ad6e165d1ff6227e73734ebda9945bcb8c5b7
Subproject commit 3901eebe37dc488aff6f1d07a762feccb9626d05
polymesh @ 9cea0cc1
Subproject commit 13ccba8ea146d4520229785006d58ab1a4e24db1
Subproject commit 9cea0cc102096f2cc4a715b2db406803be41d3f6
typed-geometry @ 5bb029fa
Subproject commit 93b0bedbac60264a539c5d116c60769baeeb4638
Subproject commit 5bb029fa1aaca97f8e5bfe7607c46f15a6fedbea
#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));
}
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