Skip to content

Commit d7e3745

Browse files
authored
Merge pull request #730 from RayTracing/no-modify-objects-list
bvh_node: don't modify source object list
2 parents 8cce2f6 + f571316 commit d7e3745

File tree

4 files changed

+24
-10
lines changed

4 files changed

+24
-10
lines changed

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Change Log -- Ray Tracing in One Weekend
1717
- Fix: Listings 33, 39: Add consistent function signature for `trilinear_interp` (#722)
1818

1919
### _The Next Week_
20+
- Change: `bvh_node` no longer reorders the source vector of scene objects; uses local copy
21+
instead (#701)
2022
- Delete: Remove unused u,v,w variables in initial `perlin::noise()` function (#684)
2123
- Fix: Listing 15: In `bvh.h`, add missing `hittable_list.h` include (#690)
2224
- Fix: Listing 33, 34, 38: Change implicit casts to explicit ones (#692)
@@ -29,6 +31,10 @@ Change Log -- Ray Tracing in One Weekend
2931
### _The Rest of Your Life_
3032
- Fix: Fix errors in citation section (#721)
3133

34+
### _The Next Week_
35+
- Change: `bvh_node` no longer reorders the source vector of scene objects; uses local copy
36+
instead (#701)
37+
3238

3339
----------------------------------------------------------------------------------------------------
3440
# v3.2.0 (2020-07-18)
@@ -69,8 +75,6 @@ significant change and improvement. We're hoping that changes to books one and t
6975
but that's never worked out for us before. Ah, dreams.
7076

7177
### Common
72-
- Bug: Found a bug in book 3 source `isotropic::scatter()` method. Commented out, using default
73-
(as it was previously). (#669)
7478
- Delete: vestigial `vec3::write_color()` method (now in color.h)
7579
- Change: All images and figures renamed to follow more logical convention, using the following
7680
pattern: `{fig,img}-<book>.<sequence>-<title>.<filetype>` (#495)
@@ -86,6 +90,8 @@ but that's never worked out for us before. Ah, dreams.
8690
because it already caught an existing bug in _The Rest of Your Life_ source. This change
8791
includes commenting out the book 3 `isotropic::scatter()` method, which was accidentally ignored
8892
anyway. (#639, #669)
93+
- Fix: Found a bug in book 3 source `isotropic::scatter()` method. Commented out, using default
94+
(as it was previously). (#669)
8995
- New: each book gets a section of recommended citation examples (#500)
9096

9197
### _In One Weekend_

books/RayTracingTheNextWeek.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@
861861
#define BVH_H
862862

863863
#include "rtweekend.h"
864+
864865
#include "hittable.h"
865866
#include "hittable_list.h"
866867

@@ -869,12 +870,12 @@
869870
public:
870871
bvh_node();
871872

872-
bvh_node(hittable_list& list, double time0, double time1)
873+
bvh_node(const hittable_list& list, double time0, double time1)
873874
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
874875
{}
875876

876877
bvh_node(
877-
std::vector<shared_ptr<hittable>>& objects,
878+
const std::vector<shared_ptr<hittable>>& src_objects,
878879
size_t start, size_t end, double time0, double time1);
879880

880881
virtual bool hit(
@@ -951,6 +952,8 @@
951952
std::vector<shared_ptr<hittable>>& objects,
952953
size_t start, size_t end, double time0, double time1
953954
) {
955+
auto objects = src_objects; // Create a modifiable array of the source scene objects
956+
954957
int axis = random_int(0,2);
955958
auto comparator = (axis == 0) ? box_x_compare
956959
: (axis == 1) ? box_y_compare

src/TheNextWeek/bvh.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ class bvh_node : public hittable {
2323
public:
2424
bvh_node();
2525

26-
bvh_node(hittable_list& list, double time0, double time1)
26+
bvh_node(const hittable_list& list, double time0, double time1)
2727
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
2828
{}
2929

3030
bvh_node(
31-
std::vector<shared_ptr<hittable>>& objects,
31+
const std::vector<shared_ptr<hittable>>& src_objects,
3232
size_t start, size_t end, double time0, double time1);
3333

3434
virtual bool hit(
@@ -68,9 +68,11 @@ bool box_z_compare (const shared_ptr<hittable> a, const shared_ptr<hittable> b)
6868

6969

7070
bvh_node::bvh_node(
71-
std::vector<shared_ptr<hittable>>& objects,
71+
const std::vector<shared_ptr<hittable>>& src_objects,
7272
size_t start, size_t end, double time0, double time1
7373
) {
74+
auto objects = src_objects; // Create a modifiable array of the source scene objects
75+
7476
int axis = random_int(0,2);
7577
auto comparator = (axis == 0) ? box_x_compare
7678
: (axis == 1) ? box_y_compare

src/TheRestOfYourLife/bvh.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "rtweekend.h"
1515

1616
#include "hittable.h"
17+
#include "hittable_list.h"
1718

1819
#include <algorithm>
1920

@@ -22,12 +23,12 @@ class bvh_node : public hittable {
2223
public:
2324
bvh_node();
2425

25-
bvh_node(hittable_list& list, double time0, double time1)
26+
bvh_node(const hittable_list& list, double time0, double time1)
2627
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
2728
{}
2829

2930
bvh_node(
30-
std::vector<shared_ptr<hittable>>& objects,
31+
const std::vector<shared_ptr<hittable>>& src_objects,
3132
size_t start, size_t end, double time0, double time1);
3233

3334
virtual bool hit(
@@ -67,9 +68,11 @@ bool box_z_compare (const shared_ptr<hittable> a, const shared_ptr<hittable> b)
6768

6869

6970
bvh_node::bvh_node(
70-
std::vector<shared_ptr<hittable>>& objects,
71+
const std::vector<shared_ptr<hittable>>& src_objects,
7172
size_t start, size_t end, double time0, double time1
7273
) {
74+
auto objects = src_objects; // Create a modifiable array of the source scene objects
75+
7376
int axis = random_int(0,2);
7477
auto comparator = (axis == 0) ? box_x_compare
7578
: (axis == 1) ? box_y_compare

0 commit comments

Comments
 (0)