Skip to content

Commit f015d68

Browse files
committed
Rename squared_length to length_squared
1 parent eb4bacc commit f015d68

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

books/RayTracingInOneWeekend.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@
245245
}
246246

247247
double length() const {
248-
return sqrt(squared_length());
248+
return sqrt(length_squared());
249249
}
250250

251-
double squared_length() const {
251+
double length_squared() const {
252252
return e[0]*e[0] + e[1]*e[1] + e[2]*e[2];
253253
}
254254

@@ -673,9 +673,9 @@
673673

674674
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
675675
vec3 oc = r.origin() - center;
676-
auto a = r.direction().squared_length();
676+
auto a = r.direction().length_squared();
677677
auto half_b = dot(oc, r.direction());
678-
auto c = oc.squared_length() - radius*radius;
678+
auto c = oc.length_squared() - radius*radius;
679679
auto discriminant = half_b*half_b - a*c;
680680

681681
if (discriminant < 0) {
@@ -749,9 +749,9 @@
749749

750750
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
751751
vec3 oc = r.origin() - center;
752-
auto a = r.direction().squared_length();
752+
auto a = r.direction().length_squared();
753753
auto half_b = dot(oc, r.direction());
754-
auto c = oc.squared_length() - radius*radius;
754+
auto c = oc.length_squared() - radius*radius;
755755
auto discriminant = half_b*half_b - a*c;
756756

757757
if (discriminant > 0) {
@@ -1183,7 +1183,7 @@
11831183
vec3 p;
11841184
do {
11851185
p = vec3::random(-1,1);
1186-
} while (p.squared_length() >= 1.0);
1186+
} while (p.length_squared() >= 1.0);
11871187
return p;
11881188
}
11891189
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1545,9 +1545,9 @@
15451545

15461546
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
15471547
vec3 oc = r.origin() - center;
1548-
auto a = r.direction().squared_length();
1548+
auto a = r.direction().length_squared();
15491549
auto half_b = dot(oc, r.direction());
1550-
auto c = oc.squared_length() - radius*radius;
1550+
auto c = oc.length_squared() - radius*radius;
15511551
auto discriminant = half_b*half_b - a*c;
15521552

15531553
if (discriminant > 0) {

books/RayTracingTheNextWeek.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,9 @@
197197
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
198198
vec3 oc = r.origin() - center(r.time());
199199
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++
200-
auto a = r.direction().squared_length();
200+
auto a = r.direction().length_squared();
201201
auto half_b = dot(oc, r.direction());
202-
auto c = oc.squared_length() - radius*radius;
202+
auto c = oc.length_squared() - radius*radius;
203203
auto discriminant = half_b*half_b - a*c;
204204

205205
if (discriminant > 0) {

books/RayTracingTheRestOfYourLife.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,7 @@
544544
vec3 p;
545545
do {
546546
p = vec3(random_double(-1,1), random_double(-1,1), random_double(-1,1));
547-
} while (p.squared_length() >= 1);
547+
} while (p.length_squared() >= 1);
548548
return p;
549549
}
550550

@@ -1295,7 +1295,7 @@
12951295
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight
12961296
vec3 on_light = vec3(random_double(213,343), 554, random_double(227,332));
12971297
vec3 to_light = on_light - rec.p;
1298-
auto distance_squared = to_light.squared_length();
1298+
auto distance_squared = to_light.length_squared();
12991299
to_light.make_unit_vector();
13001300

13011301
if (dot(to_light, rec.normal) < 0)
@@ -1536,7 +1536,7 @@
15361536
hit_record rec;
15371537
if (this->hit(ray(origin, v), 0.001, infinity, rec)) {
15381538
auto area = (x1-x0)*(z1-z0);
1539-
auto distance_squared = rec.t * rec.t * v.squared_length();
1539+
auto distance_squared = rec.t * rec.t * v.length_squared();
15401540
auto cosine = fabs(dot(v, rec.normal) / v.length());
15411541
return distance_squared / (cosine * area);
15421542
}
@@ -2022,7 +2022,7 @@
20222022
double sphere::pdf_value(const vec3& o, const vec3& v) const {
20232023
hit_record rec;
20242024
if (this->hit(ray(o, v), 0.001, infinity, rec)) {
2025-
auto cos_theta_max = sqrt(1 - radius*radius/(center-o).squared_length());
2025+
auto cos_theta_max = sqrt(1 - radius*radius/(center-o).length_squared());
20262026
auto solid_angle = 2*pi*(1-cos_theta_max);
20272027
return 1 / solid_angle;
20282028
}
@@ -2032,7 +2032,7 @@
20322032

20332033
vec3 sphere::random(const vec3& o) const {
20342034
vec3 direction = center - o;
2035-
auto distance_squared = direction.squared_length();
2035+
auto distance_squared = direction.length_squared();
20362036
onb uvw;
20372037
uvw.build_from_w(direction);
20382038
return uvw.local(random_to_sphere(radius, distance_squared));

src/InOneWeekend/sphere.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class sphere: public hittable {
2828

2929
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
3030
vec3 oc = r.origin() - center;
31-
auto a = r.direction().squared_length();
31+
auto a = r.direction().length_squared();
3232
auto half_b = dot(oc, r.direction());
33-
auto c = oc.squared_length() - radius*radius;
33+
auto c = oc.length_squared() - radius*radius;
3434
auto discriminant = half_b*half_b - a*c;
3535

3636
if (discriminant > 0) {

src/TheNextWeek/sphere.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ bool sphere::bounding_box(double t0, double t1, aabb& output_box) const {
3737

3838
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
3939
vec3 oc = r.origin() - center;
40-
auto a = r.direction().squared_length();
40+
auto a = r.direction().length_squared();
4141
auto half_b = dot(oc, r.direction());
42-
auto c = oc.squared_length() - radius*radius;
42+
auto c = oc.length_squared() - radius*radius;
4343
auto discriminant = half_b*half_b - a*c;
4444

4545
if (discriminant > 0) {

src/TheRestOfYourLife/aarect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class xz_rect: public hittable {
5151
hit_record rec;
5252
if (this->hit(ray(origin, v), 0.001, infinity, rec)) {
5353
auto area = (x1-x0)*(z1-z0);
54-
auto distance_squared = rec.t * rec.t * v.squared_length();
54+
auto distance_squared = rec.t * rec.t * v.length_squared();
5555
auto cosine = fabs(dot(v, rec.normal) / v.length());
5656
return distance_squared / (cosine * area);
5757
}

src/TheRestOfYourLife/sphere.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class sphere: public hittable {
3232
double sphere::pdf_value(const vec3& o, const vec3& v) const {
3333
hit_record rec;
3434
if (this->hit(ray(o, v), 0.001, infinity, rec)) {
35-
auto cos_theta_max = sqrt(1 - radius*radius/(center-o).squared_length());
35+
auto cos_theta_max = sqrt(1 - radius*radius/(center-o).length_squared());
3636
auto solid_angle = 2*pi*(1-cos_theta_max);
3737
return 1 / solid_angle;
3838
}
@@ -42,7 +42,7 @@ double sphere::pdf_value(const vec3& o, const vec3& v) const {
4242

4343
vec3 sphere::random(const vec3& o) const {
4444
vec3 direction = center - o;
45-
auto distance_squared = direction.squared_length();
45+
auto distance_squared = direction.length_squared();
4646
onb uvw;
4747
uvw.build_from_w(direction);
4848
return uvw.local(random_to_sphere(radius, distance_squared));
@@ -58,9 +58,9 @@ bool sphere::bounding_box(double t0, double t1, aabb& output_box) const {
5858

5959
bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
6060
vec3 oc = r.origin() - center;
61-
auto a = r.direction().squared_length();
61+
auto a = r.direction().length_squared();
6262
auto half_b = dot(oc, r.direction());
63-
auto c = oc.squared_length() - radius*radius;
63+
auto c = oc.length_squared() - radius*radius;
6464
auto discriminant = half_b*half_b - a*c;
6565

6666
if (discriminant > 0) {

src/common/vec3.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ class vec3 {
4646
}
4747

4848
double length() const {
49-
return sqrt(squared_length());
49+
return sqrt(length_squared());
5050
}
5151

52-
double squared_length() const {
52+
double length_squared() const {
5353
return e[0]*e[0] + e[1]*e[1] + e[2]*e[2];
5454
}
5555

@@ -135,7 +135,7 @@ vec3 random_in_unit_disk() {
135135
vec3 p;
136136
do {
137137
p = vec3(random_double(-1,1), random_double(-1,1), 0);
138-
} while (p.squared_length() >= 1.0);
138+
} while (p.length_squared() >= 1.0);
139139
return p;
140140
}
141141

@@ -150,7 +150,7 @@ vec3 random_in_unit_sphere() {
150150
vec3 p;
151151
do {
152152
p = vec3::random(-1,1);
153-
} while (p.squared_length() >= 1.0);
153+
} while (p.length_squared() >= 1.0);
154154
return p;
155155
}
156156

0 commit comments

Comments
 (0)