-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplane_test.cc
72 lines (53 loc) · 1.91 KB
/
plane_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "intersection.hh"
#include "plane.hh"
#include "ray.hh"
#include "shape.hh"
#include <gtest/gtest.h>
#include <algorithm> // sort
using namespace wt;
TEST(PlaneTest, RayParallel) {
shape p{plane{}};
ray r{pnt3{0, 10, 0}, vec3{0, 0, 1}};
ray object_ray{inv_tform(p) * r.origin, inv_tform(p) * r.direction};
std::vector<intersection> world_isecs;
intersect(p, object_ray, 0, world_isecs);
std::sort(world_isecs.begin(), world_isecs.end());
EXPECT_EQ(world_isecs.size(), 0);
}
TEST(PlaneTest, RayCoplanar) {
shape p{plane{}};
ray r{pnt3{0, 0, 0}, vec3{0, 0, 1}};
ray object_ray{inv_tform(p) * r.origin, inv_tform(p) * r.direction};
std::vector<intersection> world_isecs;
intersect(p, object_ray, 0, world_isecs);
std::sort(world_isecs.begin(), world_isecs.end());
EXPECT_EQ(world_isecs.size(), 0);
}
TEST(PlaneTest, RayFromAbove) {
shape p{plane{}};
ray r{pnt3{0, 1, 0}, vec3{0, -1, 0}};
ray object_ray{inv_tform(p) * r.origin, inv_tform(p) * r.direction};
std::vector<intersection> world_isecs;
intersect(p, object_ray, 0, world_isecs);
std::sort(world_isecs.begin(), world_isecs.end());
EXPECT_EQ(world_isecs.size(), 1);
EXPECT_EQ(world_isecs[0].t, 1);
pnt3 pos = position(r.origin, r.direction, world_isecs[0].t);
EXPECT_EQ(pos.x, 0.f);
EXPECT_EQ(pos.y, 0.f);
EXPECT_EQ(pos.z, 0.f);
}
TEST(PlaneTest, RayFromBelow) {
shape p{plane{}};
ray r{pnt3{0, -1, 0}, vec3{0, 1, 0}};
ray object_ray{inv_tform(p) * r.origin, inv_tform(p) * r.direction};
std::vector<intersection> world_isecs;
intersect(p, object_ray, 0, world_isecs);
std::sort(world_isecs.begin(), world_isecs.end());
EXPECT_EQ(world_isecs.size(), 1);
EXPECT_EQ(world_isecs[0].t, 1);
pnt3 pos = position(r.origin, r.direction, world_isecs[0].t);
EXPECT_EQ(pos.x, 0.f);
EXPECT_EQ(pos.y, 0.f);
EXPECT_EQ(pos.z, 0.f);
}