Skip to content

Commit fc08f65

Browse files
committed
Declare image parameters as const
1 parent 910220f commit fc08f65

File tree

4 files changed

+48
-44
lines changed

4 files changed

+48
-44
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
#include <iostream>
7171

7272
int main() {
73-
int image_width = 200;
74-
int image_height = 100;
73+
const int image_width = 200;
74+
const int image_height = 100;
7575

7676
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
7777

@@ -318,8 +318,8 @@
318318
#include <iostream>
319319

320320
int main() {
321-
int image_width = 200;
322-
int image_height = 100;
321+
const int image_width = 200;
322+
const int image_height = 100;
323323

324324
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
325325

@@ -419,9 +419,11 @@
419419
}
420420

421421
int main() {
422-
int image_width = 200;
423-
int image_height = 100;
422+
const int image_width = 200;
423+
const int image_height = 100;
424+
424425
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
426+
425427
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
426428
vec3 lower_left_corner(-2.0, -1.0, -1.0);
427429
vec3 horizontal(4.0, 0.0, 0.0);
@@ -1078,8 +1080,8 @@
10781080
}
10791081

10801082
int main() {
1081-
int image_width = 200;
1082-
int image_height = 100;
1083+
const int image_width = 200;
1084+
const int image_height = 100;
10831085

10841086
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
10851087

@@ -1260,10 +1262,10 @@
12601262

12611263
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12621264
int main() {
1263-
int image_width = 200;
1264-
int image_height = 100;
1265+
const int image_width = 200;
1266+
const int image_height = 100;
12651267
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1266-
int samples_per_pixel = 100;
1268+
const int samples_per_pixel = 100;
12671269
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
12681270

12691271
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
@@ -1425,11 +1427,11 @@
14251427
}
14261428
...
14271429
int main() {
1428-
int image_width = 200;
1429-
int image_height = 100;
1430-
int samples_per_pixel = 100;
1430+
const int image_width = 200;
1431+
const int image_height = 100;
1432+
const int samples_per_pixel = 100;
14311433
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1432-
int max_depth = 50;
1434+
const int max_depth = 50;
14331435
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
14341436

14351437
...
@@ -1897,10 +1899,11 @@
18971899

18981900
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
18991901
int main() {
1900-
int image_width = 200;
1901-
int image_height = 100;
1902-
int samples_per_pixel = 100;
1903-
int max_depth = 50;
1902+
const int image_width = 200;
1903+
const int image_height = 100;
1904+
const int samples_per_pixel = 100;
1905+
const int max_depth = 50;
1906+
19041907
std::cout << "P3\n" << image_width << " " << image_height << "\n255\n";
19051908

19061909

src/InOneWeekend/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ hittable_list random_scene() {
8282

8383

8484
int main() {
85-
int image_width = 1200;
86-
int image_height = 800;
87-
int samples_per_pixel = 10;
88-
int max_depth = 50;
85+
const int image_width = 1200;
86+
const int image_height = 800;
87+
const int samples_per_pixel = 10;
88+
const int max_depth = 50;
8989

9090
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
9191

src/TheNextWeek/main.cc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,26 @@ hittable_list final_scene() {
346346

347347

348348
int main() {
349-
int image_width = 600;
350-
int image_height = 600;
351-
int samples_per_pixel = 100;
352-
int max_depth = 50;
353-
354-
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
349+
const int image_width = 600;
350+
const int image_height = 600;
351+
const int samples_per_pixel = 100;
352+
const int max_depth = 50;
355353

356354
hittable_list world;
357355

356+
vec3 lookfrom(278, 278, -800);
357+
//vec3 lookfrom(478, 278, -600);
358+
//vec3 lookfrom(0, 0, 6);
359+
vec3 lookat(278,278,0);
360+
//vec3 lookat(0,0,0);
361+
vec3 vup(0,1,0);
362+
auto dist_to_focus = 10.0;
363+
auto aperture = 0.0;
364+
auto vfov = 40.0;
365+
366+
auto aspect_ratio = double(image_width) / image_height;
367+
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
368+
358369
switch (0) {
359370
case 1:
360371
world = random_scene();
@@ -398,18 +409,8 @@ int main() {
398409
break;
399410
}
400411

401-
vec3 lookfrom(278, 278, -800);
402-
//vec3 lookfrom(478, 278, -600);
403-
//vec3 lookfrom(0, 0, 6);
404-
vec3 lookat(278,278,0);
405-
//vec3 lookat(0,0,0);
406-
vec3 vup(0,1,0);
407-
auto dist_to_focus = 10.0;
408-
auto aperture = 0.0;
409-
auto vfov = 40.0;
410412

411-
auto aspect_ratio = double(image_width) / image_height;
412-
camera cam(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, 0.0, 1.0);
413+
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
413414

414415
for (int j = image_height-1; j >= 0; --j) {
415416
std::cerr << "\rScanlines remaining: " << j << ' ' << std::flush;

src/TheRestOfYourLife/main.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ hittable_list cornell_box(camera& cam, double aspect) {
9191

9292

9393
int main() {
94-
int image_width = 600;
95-
int image_height = 600;
96-
int samples_per_pixel = 100;
97-
int max_depth = 50;
94+
const int image_width = 600;
95+
const int image_height = 600;
96+
const int samples_per_pixel = 100;
97+
const int max_depth = 50;
9898

9999
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
100100

0 commit comments

Comments
 (0)