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 270
270
public:
271
271
double e[3];
272
272
};
273
+
274
+ // Type aliases for vec3
275
+ using point3 = vec3; // 3D point
276
+ using color = vec3; // RGB color
273
277
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
274
278
[Listing [vec3-class]: < kbd> [vec3.h]</ kbd> `vec3` class]
275
279
</ div>
276
280
277
281
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:
279
290
280
291
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
281
292
// vec3 Utility Functions
Original file line number Diff line number Diff line change @@ -86,6 +86,11 @@ class vec3 {
86
86
};
87
87
88
88
89
+ // Type aliases for vec3
90
+ using point3 = vec3; // 3D point
91
+ using color = vec3; // RGB color
92
+
93
+
89
94
// vec3 Utility Functions
90
95
91
96
inline std::ostream& operator <<(std::ostream &out, const vec3 &v) {
You can’t perform that action at this time.
0 commit comments