Skip to content

Commit 7ac4ad9

Browse files
authored
Merge pull request #814 from RayTracing/clean-virtual
Remove virtual keyword for override methods
2 parents 11aa341 + 6888ce1 commit 7ac4ad9

25 files changed

+201
-289
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Change Log -- Ray Tracing in One Weekend
1010
- Change: Class public/private access labels get two-space indents (#782)
1111
- Change: `interval::clamp()` replaces standalone `clamp` utility function
1212
- New: `rtw_image` class for easier image data loading, searches more locations (#807)
13+
- Fix: Remove redundant `virtual` keyword for methods with `override` (#805)
1314

1415
### In One Weekend
1516
- Added: More commentary about the choice between `double` and `float` (#752)

books/RayTracingInOneWeekend.html

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,7 @@
892892
sphere() {}
893893
sphere(point3 ctr, double r) : center(ctr), radius(r) {};
894894

895-
virtual bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec)
896-
const override;
895+
bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override;
897896

898897
public:
899898
point3 center;
@@ -1067,8 +1066,7 @@
10671066
void clear() { objects.clear(); }
10681067
void add(shared_ptr<hittable> object) { objects.push_back(object); }
10691068

1070-
virtual bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec)
1071-
const override;
1069+
bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override;
10721070

10731071
public:
10741072
std::vector<shared_ptr<hittable>> objects;
@@ -1326,7 +1324,7 @@
13261324
class hittable_list : public hittable {
13271325
...
13281326
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1329-
virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
1327+
bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
13301328
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13311329
...
13321330
};
@@ -1362,7 +1360,7 @@
13621360
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13631361
class sphere : public hittable {
13641362
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
1365-
virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
1363+
bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
13661364
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
13671365
...
13681366
};
@@ -2106,7 +2104,7 @@
21062104
: center(ctr), radius(r), mat_ptr(m) {};
21072105
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
21082106

2109-
virtual bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
2107+
bool hit(const ray& r, interval ray_t, hit_record& rec) const override;
21102108

21112109
public:
21122110
point3 center;
@@ -2146,9 +2144,8 @@
21462144
public:
21472145
lambertian(const color& a) : albedo(a) {}
21482146

2149-
virtual bool scatter(
2150-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2151-
) const override {
2147+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2148+
const override {
21522149
auto scatter_direction = rec.normal + random_unit_vector();
21532150
scattered = ray(rec.p, scatter_direction);
21542151
attenuation = albedo;
@@ -2192,9 +2189,8 @@
21922189
public:
21932190
lambertian(const color& a) : albedo(a) {}
21942191

2195-
virtual bool scatter(
2196-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2197-
) const override {
2192+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2193+
const override {
21982194
auto scatter_direction = rec.normal + random_unit_vector();
21992195

22002196

@@ -2248,9 +2244,8 @@
22482244
public:
22492245
metal(const color& a) : albedo(a) {}
22502246

2251-
virtual bool scatter(
2252-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2253-
) const override {
2247+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2248+
const override {
22542249
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
22552250
scattered = ray(rec.p, reflected);
22562251
attenuation = albedo;
@@ -2395,9 +2390,8 @@
23952390
metal(const color& a, double f) : albedo(a), fuzz(f < 1 ? f : 1) {}
23962391
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
23972392

2398-
virtual bool scatter(
2399-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2400-
) const override {
2393+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2394+
const override {
24012395
vec3 reflected = reflect(unit_vector(r_in.direction()), rec.normal);
24022396
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
24032397
scattered = ray(rec.p, reflected + fuzz*random_in_unit_sphere());
@@ -2533,9 +2527,8 @@
25332527
public:
25342528
dielectric(double index_of_refraction) : ir(index_of_refraction) {}
25352529

2536-
virtual bool scatter(
2537-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2538-
) const override {
2530+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2531+
const override {
25392532
attenuation = color(1.0, 1.0, 1.0);
25402533
double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
25412534

@@ -2645,9 +2638,8 @@
26452638
public:
26462639
dielectric(double index_of_refraction) : ir(index_of_refraction) {}
26472640

2648-
virtual bool scatter(
2649-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2650-
) const override {
2641+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2642+
const override {
26512643
attenuation = color(1.0, 1.0, 1.0);
26522644
double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
26532645

@@ -2709,9 +2701,8 @@
27092701
public:
27102702
dielectric(double index_of_refraction) : ir(index_of_refraction) {}
27112703

2712-
virtual bool scatter(
2713-
const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered
2714-
) const override {
2704+
bool scatter(const ray& r_in, const hit_record& rec, color& attenuation, ray& scattered)
2705+
const override {
27152706
attenuation = color(1.0, 1.0, 1.0);
27162707
double refraction_ratio = rec.front_face ? (1.0/ir) : ir;
27172708

0 commit comments

Comments
 (0)