Size: 1465 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/shapes/plane_test.cc
#include "cs/renderer/shapes/plane.hh"

#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;

using ::cs::renderer::shapes::Plane;

TEST(Plane, IntersectionOnXAxis) {
  r3 ray(p3(), p3(1, 0, 0));
  Plane plane(p3(1, 0, 0).unit(), -2);

  p3 intersection;
  v3 normal;
  EXPECT_TRUE(
      plane.intersected_by(ray, &intersection, &normal));

  EXPECT_EQ(intersection, p3(2, 0, 0));
  EXPECT_EQ(normal, v3(p3(-1, 0, 0)));
}

TEST(Plane, RejectsNonUnitNormal) {
  r3 ray(p3(), p3(1, 0, 0));
  Plane plane(p3(2, 0, 0), -2);
  p3 intersection;
  v3 normal;
  EXPECT_FALSE(
      plane.intersected_by(ray, &intersection, &normal));
}

TEST(Plane, RejectsNonUnitRay) {
  r3 ray(p3(), p3(1, 0, 0));
  ray.direction = v3(1.0f, 1.0f, 0.0f);
  Plane plane(p3(1, 0, 0).unit(), -2);
  p3 intersection;
  v3 normal;
  EXPECT_FALSE(
      plane.intersected_by(ray, &intersection, &normal));
}

TEST(Plane, RejectsParallelRay) {
  r3 ray(p3(), p3(1, 0, 0));
  Plane plane(p3(0, 1, 0).unit(), -2);
  p3 intersection;
  v3 normal;
  EXPECT_FALSE(
      plane.intersected_by(ray, &intersection, &normal));
}

TEST(Plane, RejectsIntersectionBehindRay) {
  r3 ray(p3(), p3(-1, 0, 0));
  Plane plane(p3(1, 0, 0).unit(), -2);
  p3 intersection;
  v3 normal;
  EXPECT_FALSE(
      plane.intersected_by(ray, &intersection, &normal));
}
v0 (commit) © 2025 @p13i.io | Load balancer proxied to: cs-code-viewer-1:8080 in 1ms.