-
Notifications
You must be signed in to change notification settings - Fork 0
/
sphere_test.cpp
98 lines (87 loc) · 2.63 KB
/
sphere_test.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <gtest/gtest.h>
#include "local_geometry.cpp"
#include "primitive.cpp"
#include "sphere.cpp"
TEST(Sphere, Intersection) {
Vector pos = Vector(0.f, 0.f, 0.f);
Vector dir = Vector(0.f, 1.f, 0.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Sphere sphere = Sphere(dir, 0.15f);
LocalGeometry local = LocalGeometry();
ASSERT_TRUE(sphere.intersect(ray, local));
}
TEST(Sphere, Intersection2) {
Vector pos = Vector(0.f, 0.f, -4.f);
Vector dir = Vector(0.f, 0.f, 1.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Sphere sphere = Sphere(Vector(0.f, 0.f, 0.f), 0.15f);
LocalGeometry local = LocalGeometry();
ASSERT_TRUE(sphere.intersect(ray, local));
}
TEST(Sphere, IntersectionTangent) {
Vector pos = Vector(0.f, 0.f, 0.f);
Vector dir = Vector(0.15f, 1.f, 0.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Vector center = Vector(0.f, 1.f, 0.f);
Sphere sphere = Sphere(center, 0.15f);
LocalGeometry local = LocalGeometry();
ASSERT_TRUE(sphere.intersect(ray, local));
}
TEST(Sphere, IntersectionTangentNegative) {
Vector pos = Vector(0.f, 0.f, 0.f);
Vector dir = Vector(0.16f, 1.f, 0.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Vector center = Vector(0.f, 1.f, 0.f);
Sphere sphere = Sphere(center, 0.15f);
LocalGeometry local = LocalGeometry();
ASSERT_FALSE(sphere.intersect(ray, local));
}
TEST(Sphere, IntersectionNegative) {
Vector pos = Vector(0.f, 0.f, 0.f);
Vector dir = Vector(0.f, 1.f, 0.f);
Ray ray = Ray(pos, dir, T_MIN, T_MAX);
Sphere sphere = Sphere(Vector(4.f,-5.f,1.f), 0.15f);
LocalGeometry local = LocalGeometry();
ASSERT_FALSE(sphere.intersect(ray, local));
}
TEST(Sphere, GetIntersecitonPoint) {
float a=1.f;
float b=-2.f;
float c=1.f;
float result = 1.f;
Vector intersection(0.f, 0.f, 0.f);
ASSERT_EQ(Sphere::getIntersectionPoint(a, b, c), result);
}
TEST(Sphere, GetIntersecitonPointTwoRootsSame) {
float a=2.f;
float b=-4.f;
float c=2.f;
float result = 1.f;
ASSERT_EQ(Sphere::getIntersectionPoint(a, b, c), result);
}
TEST(Sphere, GetIntersecitonPointTwoPositiveRoots) {
float a=1.f;
float b=-4.f;
float c=3.f;
float result = 1.f;
ASSERT_EQ(Sphere::getIntersectionPoint(a, b, c), result);
}
TEST(Sphere, GetIntersecitonPointOnePositiveOneNegativeRoot) {
float a=1.f;
float b=1.f;
float c=-6.f;
float result = 2.f;
ASSERT_EQ(Sphere::getIntersectionPoint(a, b, c), result);
}
TEST(Sphere, CheckIfDiscriminantNegative) {
float a=4.f;
float b=4.f;
float c=2.f;
ASSERT_FALSE(Sphere::isDiscriminantPositive(a, b, c));
}
TEST(Sphere, CheckIfDiscriminantPositive) {
float a=1.f;
float b=4.f;
float c=2.f;
ASSERT_TRUE(Sphere::isDiscriminantPositive(a, b, c));
}