Size: 1656 bytes.


 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
// cs/renderer/geo/ray3_test.cc
#include "cs/renderer/geo/ray3.h"

#include "cs/renderer/math/constants.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"

using p3 = ::cs::renderer::geo::Point3;
using v3 = ::cs::renderer::geo::Vector3;
using r3 = ::cs::renderer::geo::Ray3;

TEST(Ray3, DirectionVectorIsUnit) {
  r3 ray(p3(), p3(1, 1, 1));
  EXPECT_EQ(ray.direction, ray.direction.unit());
  EXPECT_EQ(ray.direction,
            v3(0.57735026918962576450914878050196,
               0.57735026918962576450914878050196,
               0.57735026918962576450914878050196));
}

TEST(Ray3, OperatorTimeOneComponent) {
  r3 ray(p3(), p3(1, 0, 0));
  EXPECT_EQ(ray(3), p3(3, 0, 0));
}

TEST(Ray3, OperatorTimeOnUnitVector) {
  r3 ray(p3(), p3(1, 1, 1));
  EXPECT_EQ(ray(3), p3(1.7320508075688772935274463415059,
                       1.7320508075688772935274463415059,
                       1.7320508075688772935274463415059));
}

TEST(Ray3, ThetaIsPiOver2) {
  r3 ray(p3(), PIf / 2.f, 0);
  v3 expected(1, 0, 0);
  EXPECT_EQ(ray.direction, expected);
}

TEST(Ray3, ThetaIsPiOver4) {
  r3 ray(p3(), PIf / 4.f, 0);
  v3 expected(p3(sqrtf(2) / 2.f, 0, sqrtf(2) / 2.f));
  EXPECT_EQ(ray.direction, expected);
}

TEST(Ray3, PiOver2PhiStillPointsToZ) {
  r3 ray(p3(), 0, PIf / 2.f);
  v3 expected(p3(0, 0, 1));
  EXPECT_EQ(ray.direction, expected);
}

TEST(Ray3, ThetaAndPhiArePiOver2) {
  r3 ray(p3(), PIf / 2.f, PIf / 2.f);
  v3 expected(p3(0, 1, 0));
  EXPECT_EQ(ray.direction, expected);
}

TEST(Ray3, ThetaAndPhiArePiOver4) {
  r3 ray(p3(), PIf / 4.f, PIf / 4.f);
  v3 expected(p3(1 / 2.f, 1 / 2.f, sqrtf(2) / 2.f));
  EXPECT_EQ(ray.direction, expected);
}
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-2:8080 in 4ms.