From aa45681e5055afd63ceb83e8d09c06307e99b0fd Mon Sep 17 00:00:00 2001 From: Steve Hollasch Date: Thu, 28 Mar 2024 19:55:26 -0700 Subject: [PATCH] Fix up rtweekend.h introduction and use Resolves #1473 --- books/RayTracingInOneWeekend.html | 69 +++++++++++++++++++++++++-- books/RayTracingTheNextWeek.html | 2 - src/InOneWeekend/color.h | 4 -- src/InOneWeekend/hittable_list.h | 1 - src/InOneWeekend/rtweekend.h | 3 +- src/InOneWeekend/vec3.h | 4 -- src/TheNextWeek/color.h | 4 -- src/TheNextWeek/hittable_list.h | 1 - src/TheNextWeek/rtweekend.h | 3 +- src/TheNextWeek/vec3.h | 4 -- src/TheRestOfYourLife/color.h | 4 -- src/TheRestOfYourLife/hittable_list.h | 1 - src/TheRestOfYourLife/rtweekend.h | 3 +- src/TheRestOfYourLife/vec3.h | 4 -- 14 files changed, 71 insertions(+), 36 deletions(-) diff --git a/books/RayTracingInOneWeekend.html b/books/RayTracingInOneWeekend.html index e4dac7ee..b499fc4f 100644 --- a/books/RayTracingInOneWeekend.html +++ b/books/RayTracingInOneWeekend.html @@ -1391,19 +1391,20 @@ We need some math constants that we conveniently define in their own header file. For now we only need infinity, but we will also throw our own definition of pi in there, which we will need later. There is no standard portable definition of pi, so we just define our own constant for it. We'll -throw common useful constants and future utility functions in `rtweekend.h`, our general main header -file. +also throw common useful constants and future utility functions in `rtweekend.h`, our general main +header file. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ #ifndef RTWEEKEND_H #define RTWEEKEND_H #include + #include #include #include - // Usings + // C++ Std Usings using std::shared_ptr; using std::make_shared; @@ -1429,8 +1430,56 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [rtweekend-initial]: [rtweekend.h] The rtweekend.h common header] +For all main program files, we will include `rtweekend.h` first, so most other header files (where +the bulk of our code will reside) can assume that they are free to assume that these definitions are +already available. (Headers included inside `rtweekend.h` still need to include any of their +dependencies.) Because of this, we'll make some updates with this assumption in mind. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + #include "vec3.h" + + #include + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [assume-rtw-color]: [color.h] Assume rtweekend.h in color.h] + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + #include "ray.h" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [assume-rtw-hittable]: [hittable.h] Assume rtweekend.h in hittable.h] + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + #include + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ + #include + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + using std::shared_ptr; + using std::make_shared; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [assume-rtw-hittable-list]: [hittable_list.h] + Assume rtweekend.h in hittable_list.h + ] + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + #include "vec3.h" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [assume-rtw-sphere]: [sphere.h] Assume rtweekend.h in sphere.h] + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete + #include + #include + + using std::sqrt; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [assume-rtw-vec3]: [vec3.h] Assume rtweekend.h in vec3.h] +
-And the new main: +And now the new main: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight #include "rtweekend.h" @@ -1443,7 +1492,10 @@ #include "sphere.h" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete #include + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete @@ -2884,6 +2936,15 @@ In service of this, we'll create a new vector method -- `vec3::near_zero()` -- that returns true if the vector is very close to zero in all dimensions. +We'll need to use the C++ standard library function `std::fabs`, which returns the absolute value of +its input. We'll add this to `rtweekend.h` since we'll need this in several locations as we proceed. + + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ + XXXX + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + [Listing [declare-fabs]: rtweekend.h Declaring std::fabs() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class vec3 { ... diff --git a/books/RayTracingTheNextWeek.html b/books/RayTracingTheNextWeek.html index 06963109..486f3179 100644 --- a/books/RayTracingTheNextWeek.html +++ b/books/RayTracingTheNextWeek.html @@ -842,7 +842,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ #include "hittable.h" - #include #include class hittable_list : public hittable { @@ -2484,7 +2483,6 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Listing [perlin-turb]: [perlin.h] Turbulence function] -Here `fabs()` is the absolute value function defined in ``. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ class noise_texture : public texture { diff --git a/src/InOneWeekend/color.h b/src/InOneWeekend/color.h index 53c8ce28..b473bf73 100644 --- a/src/InOneWeekend/color.h +++ b/src/InOneWeekend/color.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include "vec3.h" - -#include - using color = vec3; inline double linear_to_gamma(double linear_component) diff --git a/src/InOneWeekend/hittable_list.h b/src/InOneWeekend/hittable_list.h index 713e5923..c2b0a46d 100644 --- a/src/InOneWeekend/hittable_list.h +++ b/src/InOneWeekend/hittable_list.h @@ -15,7 +15,6 @@ #include "hittable.h" -#include #include diff --git a/src/InOneWeekend/rtweekend.h b/src/InOneWeekend/rtweekend.h index d10c37e8..1175425a 100644 --- a/src/InOneWeekend/rtweekend.h +++ b/src/InOneWeekend/rtweekend.h @@ -11,11 +11,12 @@ #include #include +#include #include #include -// Usings +// C++ Std Usings using std::shared_ptr; using std::make_shared; diff --git a/src/InOneWeekend/vec3.h b/src/InOneWeekend/vec3.h index 37ea370f..e95fb28e 100644 --- a/src/InOneWeekend/vec3.h +++ b/src/InOneWeekend/vec3.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include -#include - -using std::sqrt; using std::fabs; class vec3 { diff --git a/src/TheNextWeek/color.h b/src/TheNextWeek/color.h index 53c8ce28..b473bf73 100644 --- a/src/TheNextWeek/color.h +++ b/src/TheNextWeek/color.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include "vec3.h" - -#include - using color = vec3; inline double linear_to_gamma(double linear_component) diff --git a/src/TheNextWeek/hittable_list.h b/src/TheNextWeek/hittable_list.h index a856936b..c3756567 100644 --- a/src/TheNextWeek/hittable_list.h +++ b/src/TheNextWeek/hittable_list.h @@ -16,7 +16,6 @@ #include "aabb.h" #include "hittable.h" -#include #include diff --git a/src/TheNextWeek/rtweekend.h b/src/TheNextWeek/rtweekend.h index 1269c358..c5c94506 100644 --- a/src/TheNextWeek/rtweekend.h +++ b/src/TheNextWeek/rtweekend.h @@ -11,11 +11,12 @@ #include #include +#include #include #include -// Usings +// C++ Std Usings using std::shared_ptr; using std::make_shared; diff --git a/src/TheNextWeek/vec3.h b/src/TheNextWeek/vec3.h index 37ea370f..e95fb28e 100644 --- a/src/TheNextWeek/vec3.h +++ b/src/TheNextWeek/vec3.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include -#include - -using std::sqrt; using std::fabs; class vec3 { diff --git a/src/TheRestOfYourLife/color.h b/src/TheRestOfYourLife/color.h index 3b4d4b5b..f767e735 100644 --- a/src/TheRestOfYourLife/color.h +++ b/src/TheRestOfYourLife/color.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include "vec3.h" - -#include - using color = vec3; inline double linear_to_gamma(double linear_component) diff --git a/src/TheRestOfYourLife/hittable_list.h b/src/TheRestOfYourLife/hittable_list.h index 1f3605ce..8f98ee8a 100644 --- a/src/TheRestOfYourLife/hittable_list.h +++ b/src/TheRestOfYourLife/hittable_list.h @@ -16,7 +16,6 @@ #include "aabb.h" #include "hittable.h" -#include #include diff --git a/src/TheRestOfYourLife/rtweekend.h b/src/TheRestOfYourLife/rtweekend.h index 1269c358..c5c94506 100644 --- a/src/TheRestOfYourLife/rtweekend.h +++ b/src/TheRestOfYourLife/rtweekend.h @@ -11,11 +11,12 @@ #include #include +#include #include #include -// Usings +// C++ Std Usings using std::shared_ptr; using std::make_shared; diff --git a/src/TheRestOfYourLife/vec3.h b/src/TheRestOfYourLife/vec3.h index d09bbebc..a96bc9c6 100644 --- a/src/TheRestOfYourLife/vec3.h +++ b/src/TheRestOfYourLife/vec3.h @@ -11,10 +11,6 @@ // along with this software. If not, see . //============================================================================================== -#include -#include - -using std::sqrt; using std::fabs; class vec3 {