Skip to content

Commit 6812beb

Browse files
committed
Rename refactor: num_samples to samples_per_pixel
1 parent 09f034e commit 6812beb

File tree

6 files changed

+26
-26
lines changed

6 files changed

+26
-26
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,9 +1240,9 @@
12401240
[Listing [clamp]: <kbd>[rtweekend.h]</kbd> The clamp() utility function]
12411241

12421242
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1243-
void write_color(std::ostream &out, int num_samples) {
1243+
void write_color(std::ostream &out, int samples_per_pixel) {
12441244
// Divide the color total by the number of samples.
1245-
auto scale = 1.0 / num_samples;
1245+
auto scale = 1.0 / samples_per_pixel;
12461246
auto r = scale * e[0];
12471247
auto g = scale * e[1];
12481248
auto b = scale * e[2];
@@ -1263,7 +1263,7 @@
12631263
int image_width = 200;
12641264
int image_height = 100;
12651265
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1266-
int num_samples = 100;
1266+
int samples_per_pixel = 100;
12671267
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12681268

12691269
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
@@ -1280,13 +1280,13 @@
12801280
for (int i = 0; i < image_width; ++i) {
12811281
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
12821282
vec3 color(0, 0, 0);
1283-
for (int s = 0; s < num_samples; ++s) {
1283+
for (int s = 0; s < samples_per_pixel; ++s) {
12841284
auto u = (i + random_double()) / image_width;
12851285
auto v = (j + random_double()) / image_height;
12861286
ray r = cam.get_ray(u, v);
12871287
color += ray_color(r, world);
12881288
}
1289-
color.write_color(std::cout, num_samples);
1289+
color.write_color(std::cout, samples_per_pixel);
12901290
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12911291
}
12921292
}
@@ -1427,7 +1427,7 @@
14271427
int main() {
14281428
int image_width = 200;
14291429
int image_height = 100;
1430-
int num_samples = 100;
1430+
int samples_per_pixel = 100;
14311431
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14321432
int max_depth = 50;
14331433
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
@@ -1437,15 +1437,15 @@
14371437
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
14381438
for (int i = 0; i < image_width; ++i) {
14391439
vec3 color(0, 0, 0);
1440-
for (int s = 0; s < num_samples; ++s) {
1440+
for (int s = 0; s < samples_per_pixel; ++s) {
14411441
auto u = (i + random_double()) / image_width;
14421442
auto v = (j + random_double()) / image_height;
14431443
ray r = cam.get_ray(u, v);
14441444
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14451445
color += ray_color(r, world, max_depth);
14461446
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
14471447
}
1448-
color.write_color(std::cout, num_samples);
1448+
color.write_color(std::cout, samples_per_pixel);
14491449
}
14501450
}
14511451

@@ -1473,11 +1473,11 @@
14731473
square-root:
14741474

14751475
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1476-
void write_color(std::ostream &out, int num_samples) {
1476+
void write_color(std::ostream &out, int samples_per_pixel) {
14771477
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14781478
// Divide the color total by the number of samples and gamma-correct
14791479
// for a gamma value of 2.0.
1480-
auto scale = 1.0 / num_samples;
1480+
auto scale = 1.0 / samples_per_pixel;
14811481
auto r = sqrt(scale * e[0]);
14821482
auto g = sqrt(scale * e[1]);
14831483
auto b = sqrt(scale * e[2]);
@@ -1899,7 +1899,7 @@
18991899
int main() {
19001900
int image_width = 200;
19011901
int image_height = 100;
1902-
int num_samples = 100;
1902+
int samples_per_pixel = 100;
19031903
int max_depth = 50;
19041904
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
19051905

@@ -1922,13 +1922,13 @@
19221922
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
19231923
for (int i = 0; i < image_width; ++i) {
19241924
vec3 color(0, 0, 0);
1925-
for (int s = 0; s < num_samples; ++s) {
1925+
for (int s = 0; s < samples_per_pixel; ++s) {
19261926
auto u = (i + random_double()) / image_width;
19271927
auto v = (j + random_double()) / image_height;
19281928
ray r = cam.get_ray(u, v);
19291929
color += ray_color(r, world, max_depth);
19301930
}
1931-
color.write_color(std::cout, num_samples);
1931+
color.write_color(std::cout, samples_per_pixel);
19321932
}
19331933
}
19341934

books/RayTracingTheRestOfYourLife.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@
22542254
`vec3::write_color()` function to replace any NaN components with zero:
22552255

22562256
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2257-
void write_color(std::ostream &out, int num_samples) {
2257+
void write_color(std::ostream &out, int samples_per_pixel) {
22582258
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
22592259
// Replace NaN component values with zero.
22602260
if (e[0] != e[0]) e[0] = 0.0;
@@ -2264,7 +2264,7 @@
22642264

22652265
// Divide the color total by the number of samples and gamma-correct
22662266
// for a gamma value of 2.0.
2267-
auto scale = 1.0 / num_samples;
2267+
auto scale = 1.0 / samples_per_pixel;
22682268
auto r = sqrt(scale * e[0]);
22692269
auto g = sqrt(scale * e[1]);
22702270
auto b = sqrt(scale * e[2]);

src/InOneWeekend/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ hittable_list random_scene() {
8484
int main() {
8585
int image_width = 1200;
8686
int image_height = 800;
87-
int num_samples = 10;
87+
int samples_per_pixel = 10;
8888
int max_depth = 50;
8989

9090
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
@@ -103,13 +103,13 @@ int main() {
103103
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
104104
for (int i = 0; i < image_width; ++i) {
105105
vec3 color;
106-
for (int s = 0; s < num_samples; ++s) {
106+
for (int s = 0; s < samples_per_pixel; ++s) {
107107
auto u = (i + random_double()) / image_width;
108108
auto v = (j + random_double()) / image_height;
109109
ray r = cam.get_ray(u, v);
110110
color += ray_color(r, world, max_depth);
111111
}
112-
color.write_color(std::cout, num_samples);
112+
color.write_color(std::cout, samples_per_pixel);
113113
}
114114
}
115115

src/TheNextWeek/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ hittable_list final_scene() {
348348
int main() {
349349
int image_width = 600;
350350
int image_height = 600;
351-
int num_samples = 100;
351+
int samples_per_pixel = 100;
352352
int max_depth = 50;
353353

354354
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
@@ -389,13 +389,13 @@ int main() {
389389
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
390390
for (int i = 0; i < image_width; ++i) {
391391
vec3 color;
392-
for (int s = 0; s < num_samples; ++s) {
392+
for (int s = 0; s < samples_per_pixel; ++s) {
393393
auto u = (i + random_double()) / image_width;
394394
auto v = (j + random_double()) / image_height;
395395
ray r = cam.get_ray(u, v);
396396
color += ray_color(r, world, max_depth);
397397
}
398-
color.write_color(std::cout, num_samples);
398+
color.write_color(std::cout, samples_per_pixel);
399399
}
400400
}
401401

src/TheRestOfYourLife/main.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ hittable_list cornell_box(camera& cam, double aspect) {
9393
int main() {
9494
int image_width = 600;
9595
int image_height = 600;
96-
int num_samples = 100;
96+
int samples_per_pixel = 100;
9797
int max_depth = 50;
9898

9999
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
@@ -110,13 +110,13 @@ int main() {
110110
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;
111111
for (int i = 0; i < image_width; ++i) {
112112
vec3 color;
113-
for (int s = 0; s < num_samples; ++s) {
113+
for (int s = 0; s < samples_per_pixel; ++s) {
114114
auto u = (i + random_double()) / image_width;
115115
auto v = (j + random_double()) / image_height;
116116
ray r = cam.get_ray(u, v);
117117
color += ray_color(r, world, lights, max_depth);
118118
}
119-
color.write_color(std::cout, num_samples);
119+
color.write_color(std::cout, samples_per_pixel);
120120
}
121121
}
122122

src/common/vec3.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class vec3 {
5353
return e[0]*e[0] + e[1]*e[1] + e[2]*e[2];
5454
}
5555

56-
void write_color(std::ostream &out, int num_samples) {
56+
void write_color(std::ostream &out, int samples_per_pixel) {
5757
// Replace NaN component values with zero.
5858
// See explanation in Ray Tracing: The Rest of Your Life.
5959
if (e[0] != e[0]) e[0] = 0.0;
@@ -62,7 +62,7 @@ class vec3 {
6262

6363
// Divide the color total by the number of samples and gamma-correct
6464
// for a gamma value of 2.0.
65-
auto scale = 1.0 / num_samples;
65+
auto scale = 1.0 / samples_per_pixel;
6666
auto r = sqrt(scale * e[0]);
6767
auto g = sqrt(scale * e[1]);
6868
auto b = sqrt(scale * e[2]);

0 commit comments

Comments
 (0)