Skip to content

Commit 76e4c82

Browse files
authored
Fix up rtweekend.h introduction and use
We had neglected to delete inclusions and declarations from headers where they are now defined in `rtweekend.h`.
1 parent 2102854 commit 76e4c82

File tree

14 files changed

+79
-37
lines changed

14 files changed

+79
-37
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,19 +1391,20 @@
13911391
We need some math constants that we conveniently define in their own header file. For now we only
13921392
need infinity, but we will also throw our own definition of pi in there, which we will need later.
13931393
There is no standard portable definition of pi, so we just define our own constant for it. We'll
1394-
throw common useful constants and future utility functions in `rtweekend.h`, our general main header
1395-
file.
1394+
also throw common useful constants and future utility functions in `rtweekend.h`, our general main
1395+
header file.
13961396

13971397
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13981398
#ifndef RTWEEKEND_H
13991399
#define RTWEEKEND_H
14001400

14011401
#include <cmath>
1402+
#include <iostream>
14021403
#include <limits>
14031404
#include <memory>
14041405

14051406

1406-
// Usings
1407+
// C++ Std Usings
14071408

14081409
using std::shared_ptr;
14091410
using std::make_shared;
@@ -1429,8 +1430,56 @@
14291430
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
14301431
[Listing [rtweekend-initial]: <kbd>[rtweekend.h]</kbd> The rtweekend.h common header]
14311432

1433+
All main program files will include `rtweekend.h` first, so most other header files (where the bulk
1434+
of our code will reside) can assume that these definitions are already available. (Headers included
1435+
inside `rtweekend.h` still need to include any of their dependencies.) We'll make some updates with
1436+
this assumption in mind.
1437+
1438+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1439+
#include "vec3.h"
1440+
1441+
#include <iostream>
1442+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1443+
[Listing [assume-rtw-color]: <kbd>[color.h]</kbd> Assume rtweekend.h in color.h]
1444+
1445+
1446+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1447+
#include "ray.h"
1448+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1449+
[Listing [assume-rtw-hittable]: <kbd>[hittable.h]</kbd> Assume rtweekend.h in hittable.h]
1450+
1451+
1452+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1453+
#include <memory>
1454+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
1455+
#include <vector>
1456+
1457+
1458+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1459+
using std::shared_ptr;
1460+
using std::make_shared;
1461+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1462+
[Listing [assume-rtw-hittable-list]: <kbd>[hittable_list.h]</kbd>
1463+
Assume rtweekend.h in hittable_list.h
1464+
]
1465+
1466+
1467+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1468+
#include "vec3.h"
1469+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1470+
[Listing [assume-rtw-sphere]: <kbd>[sphere.h]</kbd> Assume rtweekend.h in sphere.h]
1471+
1472+
1473+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
1474+
#include <cmath>
1475+
#include <iostream>
1476+
1477+
using std::sqrt;
1478+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1479+
[Listing [assume-rtw-vec3]: <kbd>[vec3.h]</kbd> Assume rtweekend.h in vec3.h]
1480+
14321481
<div class='together'>
1433-
And the new main:
1482+
And now the new main:
14341483

14351484
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
14361485
#include "rtweekend.h"
@@ -1443,7 +1492,10 @@
14431492
#include "sphere.h"
14441493
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
14451494

1495+
1496+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
14461497
#include <iostream>
1498+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
14471499

14481500

14491501
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ delete
@@ -2884,6 +2936,23 @@
28842936
In service of this, we'll create a new vector method -- `vec3::near_zero()` -- that returns true if
28852937
the vector is very close to zero in all dimensions.
28862938

2939+
We'll need to use the C++ standard library function `std::fabs`, which returns the absolute value of
2940+
its input. We'll add this to `rtweekend.h` since we'll use this in several future locations.
2941+
2942+
2943+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2944+
// C++ Std Usings
2945+
2946+
2947+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
2948+
using std::fabs;
2949+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
2950+
using std::make_shared;
2951+
using std::shared_ptr;
2952+
using std::sqrt;
2953+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2954+
[Listing [declare-fabs]: <kbd>rtweekend.h</kbd> Declaring std::fabs()
2955+
28872956
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
28882957
class vec3 {
28892958
...

books/RayTracingTheNextWeek.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@
845845
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
846846
#include "hittable.h"
847847

848-
#include <memory>
849848
#include <vector>
850849

851850
class hittable_list : public hittable {
@@ -2499,8 +2498,6 @@
24992498
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25002499
[Listing [perlin-turb]: <kbd>[perlin.h]</kbd> Turbulence function]
25012500

2502-
Here `fabs()` is the absolute value function defined in `<cmath>`. Now we'll use the new Perlin
2503-
turbulence function to update our Perlin sphere:
25042501

25052502
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
25062503
class noise_texture : public texture {

src/InOneWeekend/color.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1212
//==============================================================================================
1313

14-
#include "vec3.h"
15-
16-
#include <iostream>
17-
1814
using color = vec3;
1915

2016
inline double linear_to_gamma(double linear_component)

src/InOneWeekend/hittable_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "hittable.h"
1717

18-
#include <memory>
1918
#include <vector>
2019

2120

src/InOneWeekend/rtweekend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
#include <cmath>
1313
#include <cstdlib>
14+
#include <iostream>
1415
#include <limits>
1516
#include <memory>
1617

1718

18-
// Usings
19+
// C++ Std Usings
1920

2021
using std::shared_ptr;
2122
using std::make_shared;

src/InOneWeekend/vec3.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1212
//==============================================================================================
1313

14-
#include <cmath>
15-
#include <iostream>
16-
17-
using std::sqrt;
1814
using std::fabs;
1915

2016
class vec3 {

src/TheNextWeek/color.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1212
//==============================================================================================
1313

14-
#include "vec3.h"
15-
16-
#include <iostream>
17-
1814
using color = vec3;
1915

2016
inline double linear_to_gamma(double linear_component)

src/TheNextWeek/hittable_list.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "aabb.h"
1717
#include "hittable.h"
1818

19-
#include <memory>
2019
#include <vector>
2120

2221

src/TheNextWeek/rtweekend.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@
1111

1212
#include <cmath>
1313
#include <cstdlib>
14+
#include <iostream>
1415
#include <limits>
1516
#include <memory>
1617

1718

18-
// Usings
19+
// C++ Std Usings
1920

2021
using std::shared_ptr;
2122
using std::make_shared;

src/TheNextWeek/vec3.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
// along with this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
1212
//==============================================================================================
1313

14-
#include <cmath>
15-
#include <iostream>
16-
17-
using std::sqrt;
1814
using std::fabs;
1915

2016
class vec3 {

0 commit comments

Comments
 (0)