summaryrefslogtreecommitdiff
path: root/test_vec.cpp
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-16 14:30:23 +0800
committerKeuin <[email protected]>2022-04-16 14:30:23 +0800
commit8d39a453c515b18cd10079ec4b7e45f315f466da (patch)
tree2b1d0677925ba987f5dc1ec401ccb1da2f3de0e2 /test_vec.cpp
parentbcd21b9aa9a5186af9ca666756aa253dbace4c68 (diff)
Add vec3::refract<Enable_TIR>, vec3::valid, float-point validity assertion in vec3 operations, and tests.
Diffstat (limited to 'test_vec.cpp')
-rw-r--r--test_vec.cpp23
1 files changed, 18 insertions, 5 deletions
diff --git a/test_vec.cpp b/test_vec.cpp
index 143d5b3..9739160 100644
--- a/test_vec.cpp
+++ b/test_vec.cpp
@@ -77,18 +77,18 @@ TEST(Vec, Mod2) {
}
TEST(Vec, IsZero) {
- vec3i a{1,0,0}, b{0,-1,0}, c{1,2,3};
+ vec3i a{1, 0, 0}, b{0, -1, 0}, c{1, 2, 3};
ASSERT_FALSE(a.is_zero());
ASSERT_FALSE(b.is_zero());
ASSERT_FALSE(c.is_zero());
- vec3d d{0.1,0,0}, e{0,-0.1,0},f{0.1,0.1,0.1};
+ vec3d d{0.1, 0, 0}, e{0, -0.1, 0}, f{0.1, 0.1, 0.1};
ASSERT_FALSE(d.is_zero());
ASSERT_FALSE(e.is_zero());
ASSERT_FALSE(f.is_zero());
- vec3i g{0,0,0};
- vec3d h{0,0,0}, i{1e-10,0,0}, j{1e-10,1e-10,1e-10};
+ vec3i g{0, 0, 0};
+ vec3d h{0, 0, 0}, i{1e-10, 0, 0}, j{1e-10, 1e-10, 1e-10};
ASSERT_TRUE(g.is_zero());
ASSERT_TRUE(h.is_zero());
ASSERT_TRUE(i.is_zero());
@@ -96,6 +96,19 @@ TEST(Vec, IsZero) {
}
TEST(Vec, Reflect) {
- vec3d n{1,0,0}, u{-1,1.1,0}, v{1,1.1,0};
+ vec3d n{1, 0, 0}, u{-1, 1.1, 0}, v{1, 1.1, 0};
ASSERT_EQ(v, n.reflect(u));
+}
+
+TEST(Vec, Refract) {
+ vec3d n{1, 0, 0}, u{-1, 0, -1}, v{-sqrt(14), 0, -sqrt(2)};
+ ASSERT_EQ(u.unit_vec(), n.refract<true>(u.unit_vec(), 1).unit_vec());
+ ASSERT_EQ(u.unit_vec(), n.refract<false>(u.unit_vec(), 1).unit_vec());
+ ASSERT_EQ(v.unit_vec(), n.refract<true>(u.unit_vec(), 0.5).unit_vec());
+ ASSERT_EQ(v.unit_vec(), n.refract<false>(u.unit_vec(), 0.5).unit_vec());
+}
+
+TEST(Vec, Refract_TIR) {
+ vec3d n{1, 0, 0}, u{-1, 0, -sqrt(3)}, v{1, 0, -sqrt(3)};
+ ASSERT_EQ(v.unit_vec(), n.refract<true>(u.unit_vec(), 2));
} \ No newline at end of file