Skip to content

Commit 5119b05

Browse files
committed
Fix & simplify hittable_list::bounding_box()
Resolves #435
1 parent 8050a26 commit 5119b05

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Change Log -- Ray Tracing in One Weekend
22
====================================================================================================
33

4+
----------------------------------------------------------------------------------------------------
5+
# v3.0.2 (in progress)
6+
7+
### _The Next Week_
8+
- Fix `shared_ptr` dereference and simplify code in `hittable_list::bounding_box()` (#435)
9+
10+
411
----------------------------------------------------------------------------------------------------
512
# v3.0.1 (2020-03-31)
613

books/RayTracingTheNextWeek.html

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,17 +663,12 @@
663663
if (objects.empty()) return false;
664664

665665
aabb temp_box;
666-
bool first_true = objects[0]->bounding_box(t0, t1, temp_box);
667-
668-
if (!first_true)
669-
return false;
670-
671-
output_box = temp_box;
666+
bool first_box = true;
672667

673668
for (const auto& object : objects) {
674-
if (!objects[i]->bounding_box(t0, t1, temp_box))
675-
return false;
676-
output_box = surrounding_box(output_box, temp_box);
669+
if (!object->bounding_box(t0, t1, temp_box)) return false;
670+
output_box = first_box ? temp_box : surrounding_box(output_box, temp_box);
671+
first_box = false;
677672
}
678673

679674
return true;

src/TheNextWeek/hittable_list.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,12 @@ bool hittable_list::bounding_box(double t0, double t1, aabb& output_box) const {
5555
if (objects.empty()) return false;
5656

5757
aabb temp_box;
58-
bool first_true = objects[0]->bounding_box(t0, t1, temp_box);
59-
60-
if (!first_true)
61-
return false;
62-
63-
output_box = temp_box;
58+
bool first_box = true;
6459

6560
for (const auto& object : objects) {
66-
if (!object->bounding_box(t0, t1, temp_box))
67-
return false;
68-
output_box = surrounding_box(output_box, temp_box);
61+
if (!object->bounding_box(t0, t1, temp_box)) return false;
62+
output_box = first_box ? temp_box : surrounding_box(output_box, temp_box);
63+
first_box = false;
6964
}
7065

7166
return true;

0 commit comments

Comments
 (0)