Intersecting a Ray with a Cube

The intersection algorithm must decide whether a given ray intersects any of the cube’s six faces or whether the ray misses the cube altogether. Treat those two cases as tests, starting with the first one: a ray intersecting a cube.

Test #1: A Ray Intersects a Cube

Show that the local_intersect function for a cube correctly identifies intersections on any face.

This test creates a single cube and then casts a ray at each of its faces to show that the algorithm works correctly from all six directions.

 Scenario Outline​: A ray intersects a cube
 Given​ c ← cube()
 And​ r ← ray(<origin>, <direction>)
 When​ xs ← local_intersect(c, r)
 Then​ xs.count = 2
 And​ xs[0].t = <t1>
 And ...

Get The Ray Tracer Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.