1#include <Core/Geometry/RayCast.hpp>
2#include <Core/Math/Math.hpp>
3#include <catch2/catch_test_macros.hpp>
5TEST_CASE(
"Core/Geometry/RayCast",
"[unittests][Core][Core/Geometry][RayCast]" ) {
7 Aabb ones( -Vector3::Ones(), Vector3::Ones() );
9 for (
int i = 0; i < 3; ++i ) {
11 for (
int sig = -1; sig < 2; sig += 2 ) {
12 Vector3 s = 3 * sig * Vector3::Unit( i );
13 Vector3 d = -sig * Vector3::Unit( i );
15 for (
int p = -10; p < 11; p++ ) {
16 for (
int q = -10; q < 11; q++ ) {
17 Vector3 dir = d + Scalar( p ) / 10_ra * Vector3::Unit( ( i + 1 ) % 3 ) +
18 Scalar( q ) / 10_ra * Vector3::Unit( ( i + 2 ) % 3 );
22 Eigen::ParametrizedLine<Scalar, 3> r( s, dir.normalized() );
25 Vector3 n = Vector3::Zero();
26 const bool result = Geometry::RayCastAabb( r, ones, t, n );
28 if ( std::abs( p ) <= 5 && std::abs( q ) <= 5 ) {
33 Math::areApproxEqual( n.dot( sig * Vector3::Unit( i ) ), 1_ra ) );
35 REQUIRE( Math::areApproxEqual( r.pointAt( t )[i], Scalar( sig ) ) );
37 else { REQUIRE( !result ); }
42 Eigen::ParametrizedLine<Scalar, 3> r( s, -dir.normalized() );
46 const bool result = Geometry::RayCastAabb( r, ones, t, n );
54 Eigen::ParametrizedLine<Scalar, 3> r( Vector3::Zero(), dir.normalized() );
57 Vector3 n { 0, 0, 0 };
58 const bool result = Geometry::RayCastAabb( r, ones, t, n );
63 REQUIRE( Math::areApproxEqual( t, 0_ra ) );
65 REQUIRE( Math::areApproxEqual( n.dot( dir.normalized() ), -1_ra ) );
This namespace contains everything "low level", related to data, datastuctures, and computation.