Skip to content

Commit c9ec073

Browse files
committed
Add blank lines for readability
1 parent 5eaeff3 commit c9ec073

File tree

9 files changed

+32
-2
lines changed

9 files changed

+32
-2
lines changed

src/InOneWeekend/sphere.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) cons
4040

4141
if (discriminant > 0) {
4242
auto root = sqrt(discriminant);
43+
4344
auto temp = (-half_b - root)/a;
4445
if (temp < t_max && temp > t_min) {
4546
rec.t = temp;
@@ -49,6 +50,7 @@ bool sphere::hit(const ray& r, double t_min, double t_max, hit_record& rec) cons
4950
rec.mat_ptr = mat_ptr;
5051
return true;
5152
}
53+
5254
temp = (-half_b + root) / a;
5355
if (temp < t_max && temp > t_min) {
5456
rec.t = temp;

src/TheNextWeek/aarect.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,53 +79,62 @@ bool xy_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
7979
auto t = (k-r.origin().z()) / r.direction().z();
8080
if (t < t0 || t > t1)
8181
return false;
82+
8283
auto x = r.origin().x() + t*r.direction().x();
8384
auto y = r.origin().y() + t*r.direction().y();
8485
if (x < x0 || x > x1 || y < y0 || y > y1)
8586
return false;
87+
8688
rec.u = (x-x0)/(x1-x0);
8789
rec.v = (y-y0)/(y1-y0);
8890
rec.t = t;
8991
vec3 outward_normal = vec3(0, 0, 1);
9092
rec.set_face_normal(r, outward_normal);
9193
rec.mat_ptr = mp;
9294
rec.p = r.at(t);
95+
9396
return true;
9497
}
9598

9699
bool xz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
97100
auto t = (k-r.origin().y()) / r.direction().y();
98101
if (t < t0 || t > t1)
99102
return false;
103+
100104
auto x = r.origin().x() + t*r.direction().x();
101105
auto z = r.origin().z() + t*r.direction().z();
102106
if (x < x0 || x > x1 || z < z0 || z > z1)
103107
return false;
108+
104109
rec.u = (x-x0)/(x1-x0);
105110
rec.v = (z-z0)/(z1-z0);
106111
rec.t = t;
107112
vec3 outward_normal = vec3(0, 1, 0);
108113
rec.set_face_normal(r, outward_normal);
109114
rec.mat_ptr = mp;
110115
rec.p = r.at(t);
116+
111117
return true;
112118
}
113119

114120
bool yz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
115121
auto t = (k-r.origin().x()) / r.direction().x();
116122
if (t < t0 || t > t1)
117123
return false;
124+
118125
auto y = r.origin().y() + t*r.direction().y();
119126
auto z = r.origin().z() + t*r.direction().z();
120127
if (y < y0 || y > y1 || z < z0 || z > z1)
121128
return false;
129+
122130
rec.u = (y-y0)/(y1-y0);
123131
rec.v = (z-z0)/(z1-z0);
124132
rec.t = t;
125133
vec3 outward_normal = vec3(1, 0, 0);
126134
rec.set_face_normal(r, outward_normal);
127135
rec.mat_ptr = mp;
128136
rec.p = r.at(t);
137+
129138
return true;
130139
}
131140

src/TheNextWeek/constant_medium.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bool constant_medium::hit(const ray& r, double t_min, double t_max, hit_record&
5555

5656
if (rec1.t >= rec2.t)
5757
return false;
58+
5859
if (rec1.t < 0)
5960
rec1.t = 0;
6061

src/TheNextWeek/moving_sphere.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ bool moving_sphere::hit(const ray& r, double t_min, double t_max, hit_record& re
5959
auto a = dot(r.direction(), r.direction());
6060
auto b = dot(oc, r.direction());
6161
auto c = dot(oc, oc) - radius*radius;
62+
6263
auto discriminant = b*b - a*c;
64+
6365
if (discriminant > 0) {
66+
6467
auto temp = (-b - sqrt(discriminant))/a;
6568
if (temp < t_max && temp > t_min) {
6669
rec.t = temp;
@@ -70,6 +73,7 @@ bool moving_sphere::hit(const ray& r, double t_min, double t_max, hit_record& re
7073
rec.mat_ptr = mat_ptr;
7174
return true;
7275
}
76+
7377
temp = (-b + sqrt(discriminant))/a;
7478
if (temp < t_max && temp > t_min) {
7579
rec.t = temp;
@@ -80,6 +84,7 @@ bool moving_sphere::hit(const ray& r, double t_min, double t_max, hit_record& re
8084
return true;
8185
}
8286
}
87+
8388
return false;
8489
}
8590

src/TheRestOfYourLife/cos_cubed.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818

1919
int main() {
2020
int N = 1000000;
21+
2122
auto sum = 0.0;
2223
for (int i = 0; i < N; i++) {
2324
auto r1 = random_double();
2425
auto r2 = random_double();
2526
auto x = cos(2*pi*r1)*2*sqrt(r2*(1-r2));
2627
auto y = sin(2*pi*r1)*2*sqrt(r2*(1-r2));
2728
auto z = 1 - r2;
29+
2830
sum += z*z*z / (1.0/(2.0*pi));
2931
}
32+
3033
std::cout << std::fixed << std::setprecision(12);
3134
std::cout << "PI/2 = " << pi/2 << '\n';
3235
std::cout << "Estimate = " << sum/N << '\n';

src/TheRestOfYourLife/cos_density.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,20 @@ inline vec3 random_cosine_direction() {
2323
auto phi = 2*pi*r1;
2424
auto x = cos(phi)*sqrt(r2);
2525
auto y = sin(phi)*sqrt(r2);
26+
2627
return vec3(x, y, z);
2728
}
2829

2930

3031
int main() {
3132
int N = 1000000;
33+
3234
auto sum = 0.0;
3335
for (int i = 0; i < N; i++) {
3436
vec3 v = random_cosine_direction();
3537
sum += v.z()*v.z()*v.z() / (v.z()/(pi));
3638
}
39+
3740
std::cout << std::fixed << std::setprecision(12);
3841
std::cout << "PI/2 = " << pi/2 << '\n';
3942
std::cout << "Estimate = " << sum/N << '\n';

src/TheRestOfYourLife/integrate_x_sq.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ int main() {
2525
int inside_circle = 0;
2626
int inside_circle_stratified = 0;
2727
int N = 1;
28+
2829
auto sum = 0.0;
2930
for (int i = 0; i < N; i++) {
30-
auto x = pow(random_double(0,8), 1./3.);
31-
sum += x*x / pdf(x);
31+
auto x = pow(random_double(0,8), 1./3.);
32+
sum += x*x / pdf(x);
3233
}
34+
3335
std::cout << std::fixed << std::setprecision(12);
3436
std::cout << "I = " << sum/N << '\n';
3537
}

src/TheRestOfYourLife/pi.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ int main() {
2121
int inside_circle = 0;
2222
int inside_circle_stratified = 0;
2323
int sqrt_N = 10000;
24+
2425
for (int i = 0; i < sqrt_N; i++) {
2526
for (int j = 0; j < sqrt_N; j++) {
2627
auto x = random_double(-1,1);
2728
auto y = random_double(-1,1);
29+
2830
if (x*x + y*y < 1)
2931
inside_circle++;
32+
3033
x = 2*((i + random_double()) / sqrt_N) - 1;
3134
y = 2*((j + random_double()) / sqrt_N) - 1;
35+
3236
if (x*x + y*y < 1)
3337
inside_circle_stratified++;
3438
}

src/TheRestOfYourLife/sphere_plot.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ int main() {
2222
auto x = cos(2*pi*r1)*2*sqrt(r2*(1-r2));
2323
auto y = sin(2*pi*r1)*2*sqrt(r2*(1-r2));
2424
auto z = 1 - 2*r2;
25+
2526
std::cout << x << " " << y << " " << z << '\n';
2627
}
2728
}

0 commit comments

Comments
 (0)