Add test for intersection and fix data in raytracer test.
This commit is contained in:
parent
413ff4e558
commit
80d0e1c336
2 changed files with 44 additions and 12 deletions
|
@ -71,7 +71,7 @@ namespace curry {
|
||||||
assert(not (std::abs(r_cross_s) <= FLT_EPSILON));
|
assert(not (std::abs(r_cross_s) <= FLT_EPSILON));
|
||||||
const auto inv_r_cross_s = 1.0f / r_cross_s;
|
const auto inv_r_cross_s = 1.0f / r_cross_s;
|
||||||
const auto t = cross(q - p, s) * inv_r_cross_s;
|
const auto t = cross(q - p, s) * inv_r_cross_s;
|
||||||
const auto u = cross(q - p, r) * inv_r_cross_s;
|
//const auto u = cross(q - p, r) * inv_r_cross_s;
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
//if (0.0f <= t and t <= 1.0f and 0.0f <= u and u <= 1.0f)
|
//if (0.0f <= t and t <= 1.0f and 0.0f <= u and u <= 1.0f)
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "tileproperty.hpp"
|
#include "tileproperty.hpp"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
TEST_CASE ("Check that 2D raytracing works", "[raytracing, geometry]") {
|
TEST_CASE ("Check that 2D raytracing works", "[raytracing][geometry]") {
|
||||||
using curry::for_each_voxel_under_segment;
|
using curry::for_each_voxel_under_segment;
|
||||||
using curry::vec2us;
|
using curry::vec2us;
|
||||||
using curry::vec2f;
|
using curry::vec2f;
|
||||||
|
@ -32,16 +32,16 @@ TEST_CASE ("Check that 2D raytracing works", "[raytracing, geometry]") {
|
||||||
|
|
||||||
curry::WorldGrid world(vec2us(64));
|
curry::WorldGrid world(vec2us(64));
|
||||||
world.set_layers(vec2us(10, 10), std::vector<std::vector<curry::TileIndex>>( {{
|
world.set_layers(vec2us(10, 10), std::vector<std::vector<curry::TileIndex>>( {{
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
}}));
|
}}));
|
||||||
world.set_tile_properties(std::vector<curry::TileProperty>({ curry::TileProperty() }));
|
world.set_tile_properties(std::vector<curry::TileProperty>({ curry::TileProperty() }));
|
||||||
|
|
||||||
|
@ -74,3 +74,35 @@ TEST_CASE ("Check that 2D raytracing works", "[raytracing, geometry]") {
|
||||||
CHECK(expected == diagonal);
|
CHECK(expected == diagonal);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE ("Check that segment intersection code used by the raytracing code works", "[geometry][intersection]") {
|
||||||
|
using curry::vec2f;
|
||||||
|
using curry::segment_intersection;
|
||||||
|
|
||||||
|
{
|
||||||
|
//Two segments crossing at <0, 0>
|
||||||
|
const vec2f a0(-1.0f, 0.0f);
|
||||||
|
const vec2f a1(2.0f, 0.0f);
|
||||||
|
const vec2f b0(0.0f, 1.0f);
|
||||||
|
const vec2f b1(0.0f, -2.0f);
|
||||||
|
|
||||||
|
const float t1 = segment_intersection(a0, a1, b0, b1);
|
||||||
|
CHECK(0.5f == t1);
|
||||||
|
CHECK(vec2f(0.0f) == a0 + t1 * a1);
|
||||||
|
const float t2 = segment_intersection(b0, b1, a0, a1);
|
||||||
|
CHECK(0.5f == t2);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
//a diagonal segment starting off from a vertical segment
|
||||||
|
const vec2f a0(-1.0f, 0.0f);
|
||||||
|
const vec2f a1(3.0f, 2.0f);
|
||||||
|
const vec2f b0(-1.0f, 1.0f);
|
||||||
|
const vec2f b1(0.0f, -2.0f);
|
||||||
|
|
||||||
|
const float t1 = segment_intersection(a0, a1, b0, b1);
|
||||||
|
CHECK(0.0f == t1);
|
||||||
|
const float t2 = segment_intersection(b0, b1, a0, a1);
|
||||||
|
CHECK(0.5f == t2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue