File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 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
277281We 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
Original file line number Diff line number Diff 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
9196inline std::ostream& operator <<(std::ostream &out, const vec3 &v) {
You can’t perform that action at this time.
0 commit comments