15#include <jau/test/catch2_ext.hpp>
28 bool __attribute__ ((noinline))
31 return hi.x >= o.lo.x &&
36 bool __attribute__ ((noinline))
39 return !(
hi.x < o.lo.x ||
44 bool __attribute__ ((noinline))
49 return lo_.
x <= hi_.
x && lo_.
y <= hi_.
y;
54 return hi.x >= o.
lo.
x &&
61 return !(
hi.x < o.
lo.
x ||
70 return lo_.
x <= hi_.
x && lo_.
y <= hi_.
y;
76TEST_CASE(
"Float Math Bench 04a",
"[intersect][benchmark][arithmetic][math]" ) {
80 std::uniform_int_distribution<int32_t> rint(0,50);
82 const int loops = catch_auto_run ? 1000 : 1000000;
84 std::vector<AABBox2f> va0, vb0;
85 std::vector<AABBox> va, vb;
86 for(
int i=0; i<
loops; ++i) {
87 Point2f lo((
float)rint(rng), (
float)rint(rng));
88 Point2f hi(lo.
x+(
float)rint(rng), lo.
y+(
float)rint(rng));
89 AABBox a { .lo=lo, .hi=hi };
91 lo =
Point2f((
float)rint(rng), (
float)rint(rng));
92 hi =
Point2f(lo.
x+(
float)rint(rng), lo.
y+(
float)rint(rng));
94 AABBox b { .lo=lo, .hi=hi };
99 bool i0 = a0.intersects(b0);
100 bool i1a = a.intersects1a(b);
101 bool i1b = a.intersects1b(b);
102 bool i1c = a.intersects1c(b);
109 REQUIRE( i1a == i1b );
110 REQUIRE( i1a == i1c );
111 REQUIRE( i1a == i0 );
113 bool i2a = a.intersects2a(b);
114 bool i2b = a.intersects2b(b);
115 bool i2c = a.intersects2c(b);
116 REQUIRE( i1a == i2a );
117 REQUIRE( i2a == i2b );
118 REQUIRE( i2a == i2c );
119 REQUIRE( i2a == i0 );
121 std::cout <<
"isect_count " << isect_count <<
"/" << va.size() <<
", " << 100.0f*( (float)isect_count / (float)va.size() ) <<
"%" << std::endl;
123 BENCHMARK(
"Intersect0 Benchmark") {
125 for(
size_t i = 0; i < va0.size(); ++i) {
132 BENCHMARK(
"Intersect1a Benchmark") {
134 for(
size_t i = 0; i < va.size(); ++i) {
141 BENCHMARK(
"Intersect1b Benchmark") {
143 for(
size_t i = 0; i < va.size(); ++i) {
150 BENCHMARK(
"Intersect1c Benchmark") {
152 for(
size_t i = 0; i < va.size(); ++i) {
159 BENCHMARK(
"Intersect2a Benchmark") {
161 for(
size_t i = 0; i < va.size(); ++i) {
168 BENCHMARK(
"Intersect2b Benchmark") {
170 for(
size_t i = 0; i < va.size(); ++i) {
177 BENCHMARK(
"Intersect2c Benchmark") {
179 for(
size_t i = 0; i < va.size(); ++i) {
Axis Aligned Bounding Box.
constexpr bool intersects(const AABBox2f &o) const noexcept
constexpr T min(const T x, const T y) noexcept
Returns the minimum of two integrals (w/ branching) in O(1)
constexpr T max(const T x, const T y) noexcept
Returns the maximum of two integrals (w/ branching) in O(1)
__pack(...): Produces MSVC, clang and gcc compatible lead-in and -out macros.
bool intersects1b(const AABBox &o) const
bool intersects2c(const AABBox &o) const
bool intersects1c(const AABBox &o) const
bool intersects2b(const AABBox &o) const
bool intersects1a(const AABBox &o) const
bool intersects2a(const AABBox &o) const
TEST_CASE("Float Math Bench 04a", "[intersect][benchmark][arithmetic][math]")