Skip to content

Commit bb11cea

Browse files
committed
Introduce point3 and color
1 parent 2c95eb8 commit bb11cea

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,23 @@
270270
public:
271271
double e[3];
272272
};
273+
274+
// Type aliases for vec3
275+
using point3 = vec3; // 3D point
276+
using color = vec3; // RGB color
273277
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274278
[Listing [vec3-class]: <kbd>[vec3.h]</kbd> `vec3` class]
275279
</div>
276280

277281
We use `double` here, but some ray tracers use `float`. Either one is fine -- follow your own
278-
tastes. The second part of the header file contains vector utility functions:
282+
tastes.
283+
284+
You'll notice that we also create two type aliases for `vec3`: `point3` and `color` (you may be
285+
familiar with the older `typedef` keyword). In C++, these create weak type aliases — passing a
286+
`color` for a `vec3` parameter is legal, and will generate no warnings. We use them solely as a way
287+
to clarify intent and use.
288+
289+
The second part of the header file contains vector utility functions:
279290

280291
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
281292
// vec3 Utility Functions

src/common/vec3.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class vec3 {
8686
};
8787

8888

89+
// Type aliases for vec3
90+
using point3 = vec3; // 3D point
91+
using color = vec3; // RGB color
92+
93+
8994
// vec3 Utility Functions
9095

9196
inline std::ostream& operator<<(std::ostream &out, const vec3 &v) {

0 commit comments

Comments
 (0)