Skip to content

Commit

Permalink
Merge pull request #730 from RayTracing/no-modify-objects-list
Browse files Browse the repository at this point in the history
bvh_node: don't modify source object list
  • Loading branch information
hollasch committed Sep 27, 2020
2 parents 8cce2f6 + f571316 commit d7e3745
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Change Log -- Ray Tracing in One Weekend
- Fix: Listings 33, 39: Add consistent function signature for `trilinear_interp` (#722)

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

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


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

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

### _In One Weekend_
Expand Down
7 changes: 5 additions & 2 deletions books/RayTracingTheNextWeek.html
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,7 @@
#define BVH_H

#include "rtweekend.h"

#include "hittable.h"
#include "hittable_list.h"

Expand All @@ -869,12 +870,12 @@
public:
bvh_node();

bvh_node(hittable_list& list, double time0, double time1)
bvh_node(const hittable_list& list, double time0, double time1)
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
{}

bvh_node(
std::vector<shared_ptr<hittable>>& objects,
const std::vector<shared_ptr<hittable>>& src_objects,
size_t start, size_t end, double time0, double time1);

virtual bool hit(
Expand Down Expand Up @@ -951,6 +952,8 @@
std::vector<shared_ptr<hittable>>& objects,
size_t start, size_t end, double time0, double time1
) {
auto objects = src_objects; // Create a modifiable array of the source scene objects

int axis = random_int(0,2);
auto comparator = (axis == 0) ? box_x_compare
: (axis == 1) ? box_y_compare
Expand Down
8 changes: 5 additions & 3 deletions src/TheNextWeek/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class bvh_node : public hittable {
public:
bvh_node();

bvh_node(hittable_list& list, double time0, double time1)
bvh_node(const hittable_list& list, double time0, double time1)
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
{}

bvh_node(
std::vector<shared_ptr<hittable>>& objects,
const std::vector<shared_ptr<hittable>>& src_objects,
size_t start, size_t end, double time0, double time1);

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


bvh_node::bvh_node(
std::vector<shared_ptr<hittable>>& objects,
const std::vector<shared_ptr<hittable>>& src_objects,
size_t start, size_t end, double time0, double time1
) {
auto objects = src_objects; // Create a modifiable array of the source scene objects

int axis = random_int(0,2);
auto comparator = (axis == 0) ? box_x_compare
: (axis == 1) ? box_y_compare
Expand Down
9 changes: 6 additions & 3 deletions src/TheRestOfYourLife/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "rtweekend.h"

#include "hittable.h"
#include "hittable_list.h"

#include <algorithm>

Expand All @@ -22,12 +23,12 @@ class bvh_node : public hittable {
public:
bvh_node();

bvh_node(hittable_list& list, double time0, double time1)
bvh_node(const hittable_list& list, double time0, double time1)
: bvh_node(list.objects, 0, list.objects.size(), time0, time1)
{}

bvh_node(
std::vector<shared_ptr<hittable>>& objects,
const std::vector<shared_ptr<hittable>>& src_objects,
size_t start, size_t end, double time0, double time1);

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


bvh_node::bvh_node(
std::vector<shared_ptr<hittable>>& objects,
const std::vector<shared_ptr<hittable>>& src_objects,
size_t start, size_t end, double time0, double time1
) {
auto objects = src_objects; // Create a modifiable array of the source scene objects

int axis = random_int(0,2);
auto comparator = (axis == 0) ? box_x_compare
: (axis == 1) ? box_y_compare
Expand Down

0 comments on commit d7e3745

Please sign in to comment.