Skip to content

Commit

Permalink
src: clean trailing whitespace characters
Browse files Browse the repository at this point in the history
Resolves #218
  • Loading branch information
hollasch committed Oct 20, 2019
1 parent 1673fe4 commit f2f9d11
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 53 deletions.
12 changes: 6 additions & 6 deletions src/TheNextWeek/aarect.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ bool xy_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto x = r.origin().x() + t*r.direction().x();
auto y = r.origin().y() + t*r.direction().y();
if (x < x0 || x > x1 || y < y0 || y > y1)
if (x < x0 || x > x1 || y < y0 || y > y1)
return false;
rec.u = (x-x0)/(x1-x0);
rec.v = (y-y0)/(y1-y0);
rec.v = (y-y0)/(y1-y0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand All @@ -77,10 +77,10 @@ bool xz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto x = r.origin().x() + t*r.direction().x();
auto z = r.origin().z() + t*r.direction().z();
if (x < x0 || x > x1 || z < z0 || z > z1)
if (x < x0 || x > x1 || z < z0 || z > z1)
return false;
rec.u = (x-x0)/(x1-x0);
rec.v = (z-z0)/(z1-z0);
rec.v = (z-z0)/(z1-z0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand All @@ -94,10 +94,10 @@ bool yz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto y = r.origin().y() + t*r.direction().y();
auto z = r.origin().z() + t*r.direction().z();
if (y < y0 || y > y1 || z < z0 || z > z1)
if (y < y0 || y > y1 || z < z0 || z > z1)
return false;
rec.u = (y-y0)/(y1-y0);
rec.v = (z-z0)/(z1-z0);
rec.v = (z-z0)/(z1-z0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand Down
8 changes: 4 additions & 4 deletions src/TheNextWeek/bvh.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ bool bvh_node::hit(const ray& r, double t_min, double t_max, hit_record& rec) co
bool hit_left = left->hit(r, t_min, t_max, left_rec);
bool hit_right = right->hit(r, t_min, t_max, right_rec);
if (hit_left && hit_right) {
if (left_rec.t < right_rec.t)
if (left_rec.t < right_rec.t)
rec = left_rec;
else
else
rec = right_rec;
return true;
}
Expand All @@ -52,7 +52,7 @@ bool bvh_node::hit(const ray& r, double t_min, double t_max, hit_record& rec) co
rec = right_rec;
return true;
}
else
else
return false;
}
else return false;
Expand Down Expand Up @@ -118,7 +118,7 @@ bvh_node::bvh_node(hittable **l, int n, double time0, double time1) {
}
aabb box_left, box_right;
if(!left->bounding_box(time0,time1, box_left) || !right->bounding_box(time0,time1, box_right))
std::cerr << "no bounding box in bvh_node constructor\n";
std::cerr << "no bounding box in bvh_node constructor\n";
box = surrounding_box(box_left, box_right);
}

Expand Down
2 changes: 1 addition & 1 deletion src/TheNextWeek/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class camera {
vec3 rd = lens_radius*random_in_unit_disk();
vec3 offset = u * rd.x() + v * rd.y();
auto time = time0 + random_double()*(time1-time0);
return ray(origin + offset, lower_left_corner + s*horizontal + t*vertical - origin - offset, time);
return ray(origin + offset, lower_left_corner + s*horizontal + t*vertical - origin - offset, time);
}

vec3 origin;
Expand Down
3 changes: 1 addition & 2 deletions src/TheNextWeek/constant_medium.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef CONSTANT_MEDIUM_H
#define CONSTANT_MEDIUM_H
//==================================================================================================
// Written in 2016 by Peter Shirley <ptrshrl@gmail.com>
// Originally written in 2016 by Peter Shirley <ptrshrl@gmail.com>
//
// To the extent possible under law, the author(s) have dedicated all copyright and related and
// neighboring rights to this software to the public domain worldwide. This software is distributed
Expand Down Expand Up @@ -78,5 +78,4 @@ bool constant_medium::hit(const ray& r, double t_min, double t_max, hit_record&
return false;
}


#endif
8 changes: 4 additions & 4 deletions src/TheNextWeek/hittable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct hit_record {
double u;
double v;
vec3 p;
vec3 normal;
vec3 normal;
material *mat_ptr;
};

Expand Down Expand Up @@ -65,7 +65,7 @@ class translate : public hittable {
virtual bool hit(const ray& r, double t_min, double t_max, hit_record& rec) const;
virtual bool bounding_box(double t0, double t1, aabb& box) const;
hittable *ptr;
vec3 offset;
vec3 offset;
};

bool translate::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
Expand Down Expand Up @@ -127,7 +127,7 @@ rotate_y::rotate_y(hittable *p, double angle) : ptr(p) {
}
}
bbox = aabb(min, max);
}
}

bool rotate_y::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
vec3 origin = r.origin();
Expand All @@ -148,7 +148,7 @@ bool rotate_y::hit(const ray& r, double t_min, double t_max, hit_record& rec) co
rec.normal = normal;
return true;
}
else
else
return false;
}

Expand Down
31 changes: 17 additions & 14 deletions src/TheNextWeek/hittable_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,38 @@ class hittable_list: public hittable {

bool hittable_list::bounding_box(double t0, double t1, aabb& box) const {
if (list_size < 1) return false;

aabb temp_box;
bool first_true = list[0]->bounding_box(t0, t1, temp_box);

if (!first_true)
return false;
else
else
box = temp_box;

for (int i = 1; i < list_size; i++) {
if(list[i]->bounding_box(t0, t1, temp_box)) {
if (list[i]->bounding_box(t0, t1, temp_box))
box = surrounding_box(box, temp_box);
}
else
return false;
}

return true;
}

bool hittable_list::hit(const ray& r, double t_min, double t_max, hit_record& rec) const {
hit_record temp_rec;
bool hit_anything = false;
double closest_so_far = t_max;
for (int i = 0; i < list_size; i++) {
if (list[i]->hit(r, t_min, closest_so_far, temp_rec)) {
hit_anything = true;
closest_so_far = temp_rec.t;
rec = temp_rec;
}
hit_record temp_rec;
bool hit_anything = false;
double closest_so_far = t_max;

for (int i = 0; i < list_size; i++) {
if (list[i]->hit(r, t_min, closest_so_far, temp_rec)) {
hit_anything = true;
closest_so_far = temp_rec.t;
rec = temp_rec;
}
return hit_anything;
}
return hit_anything;
}

#endif

18 changes: 9 additions & 9 deletions src/TheNextWeek/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@

vec3 color(const ray& r, hittable *world, int depth) {
hit_record rec;
if (world->hit(r, 0.001, infinity, rec)) {
if (world->hit(r, 0.001, infinity, rec)) {
ray scattered;
vec3 attenuation;
vec3 emitted = rec.mat_ptr->emitted(rec.u, rec.v, rec.p);
if (depth < 50 && rec.mat_ptr->scatter(r, rec, attenuation, scattered))
if (depth < 50 && rec.mat_ptr->scatter(r, rec, attenuation, scattered))
return emitted + attenuation*color(scattered, world, depth+1);
else
else
return emitted;
}
else
else
return vec3(0,0,0);
}

Expand Down Expand Up @@ -231,8 +231,8 @@ hittable *random_scene() {
for (int a = -10; a < 10; a++) {
for (int b = -10; b < 10; b++) {
auto choose_mat = random_double();
vec3 center(a+0.9*random_double(),0.2,b+0.9*random_double());
if ((center-vec3(4,0.2,0)).length() > 0.9) {
vec3 center(a+0.9*random_double(),0.2,b+0.9*random_double());
if ((center-vec3(4,0.2,0)).length() > 0.9) {
if (choose_mat < 0.8) { // diffuse
list[i++] = new moving_sphere(center, center+vec3(0,0.5*random_double(), 0), 0.0, 1.0, 0.2, new lambertian(new constant_texture(vec3(random_double()*random_double(), random_double()*random_double(), random_double()*random_double()))));
}
Expand Down Expand Up @@ -295,9 +295,9 @@ int main() {
}
col /= float(ns);
col = vec3( sqrt(col[0]), sqrt(col[1]), sqrt(col[2]) );
int ir = int(255.99*col[0]);
int ig = int(255.99*col[1]);
int ib = int(255.99*col[2]);
int ir = int(255.99*col[0]);
int ig = int(255.99*col[1]);
int ib = int(255.99*col[2]);
std::cout << ir << " " << ig << " " << ib << "\n";
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/TheNextWeek/ray.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class ray
{
public:
ray() {}
ray(const vec3& a, const vec3& b, double ti = 0.0) { A = a; B = b; _time = ti;}
ray(const vec3& a, const vec3& b, double ti = 0.0) {
A = a;
B = b;
_time = ti;
}
vec3 origin() const { return A; }
vec3 direction() const { return B; }
double time() const { return _time; }
Expand Down
30 changes: 18 additions & 12 deletions src/TheRestOfYourLife/aarect.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
class xy_rect: public hittable {
public:
xy_rect() {}
xy_rect(double _x0, double _x1, double _y0, double _y1, double _k, material *mat) : x0(_x0), x1(_x1), y0(_y0), y1(_y1), k(_k), mp(mat) {};
xy_rect(double _x0, double _x1, double _y0, double _y1, double _k, material *mat)
: x0(_x0), x1(_x1), y0(_y0), y1(_y1), k(_k), mp(mat)
{};
virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
virtual bool bounding_box(double t0, double t1, aabb& box) const {
box = aabb(vec3(x0,y0, k-0.0001), vec3(x1, y1, k+0.0001));
Expand All @@ -30,11 +32,13 @@ class xy_rect: public hittable {
class xz_rect: public hittable {
public:
xz_rect() {}
xz_rect(double _x0, double _x1, double _z0, double _z1, double _k, material *mat) : x0(_x0), x1(_x1), z0(_z0), z1(_z1), k(_k), mp(mat) {};
xz_rect(double _x0, double _x1, double _z0, double _z1, double _k, material *mat)
: x0(_x0), x1(_x1), z0(_z0), z1(_z1), k(_k), mp(mat)
{};
virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
virtual bool bounding_box(double t0, double t1, aabb& box) const {
box = aabb(vec3(x0,k-0.0001,z0), vec3(x1, k+0.0001, z1));
return true;
return true;
}
virtual double pdf_value(const vec3& o, const vec3& v) const {
hit_record rec;
Expand All @@ -47,8 +51,8 @@ class xz_rect: public hittable {
else
return 0;
}
virtual vec3 random(const vec3& o) const {
vec3 random_point = vec3(x0 + random_double()*(x1-x0), k, z0 + random_double()*(z1-z0));
virtual vec3 random(const vec3& o) const {
vec3 random_point = vec3(x0 + random_double()*(x1-x0), k, z0 + random_double()*(z1-z0));
return random_point - o;
}
material *mp;
Expand All @@ -58,7 +62,9 @@ class xz_rect: public hittable {
class yz_rect: public hittable {
public:
yz_rect() {}
yz_rect(double _y0, double _y1, double _z0, double _z1, double _k, material *mat) : y0(_y0), y1(_y1), z0(_z0), z1(_z1), k(_k), mp(mat) {};
yz_rect(double _y0, double _y1, double _z0, double _z1, double _k, material *mat)
: y0(_y0), y1(_y1), z0(_z0), z1(_z1), k(_k), mp(mat)
{};
virtual bool hit(const ray& r, double t0, double t1, hit_record& rec) const;
virtual bool bounding_box(double t0, double t1, aabb& box) const {
box = aabb(vec3(k-0.0001, y0, z0), vec3(k+0.0001, y1, z1));
Expand All @@ -76,10 +82,10 @@ bool xy_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto x = r.origin().x() + t*r.direction().x();
auto y = r.origin().y() + t*r.direction().y();
if (x < x0 || x > x1 || y < y0 || y > y1)
if (x < x0 || x > x1 || y < y0 || y > y1)
return false;
rec.u = (x-x0)/(x1-x0);
rec.v = (y-y0)/(y1-y0);
rec.v = (y-y0)/(y1-y0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand All @@ -94,10 +100,10 @@ bool xz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto x = r.origin().x() + t*r.direction().x();
auto z = r.origin().z() + t*r.direction().z();
if (x < x0 || x > x1 || z < z0 || z > z1)
if (x < x0 || x > x1 || z < z0 || z > z1)
return false;
rec.u = (x-x0)/(x1-x0);
rec.v = (z-z0)/(z1-z0);
rec.v = (z-z0)/(z1-z0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand All @@ -111,10 +117,10 @@ bool yz_rect::hit(const ray& r, double t0, double t1, hit_record& rec) const {
return false;
auto y = r.origin().y() + t*r.direction().y();
auto z = r.origin().z() + t*r.direction().z();
if (y < y0 || y > y1 || z < z0 || z > z1)
if (y < y0 || y > y1 || z < z0 || z > z1)
return false;
rec.u = (y-y0)/(y1-y0);
rec.v = (z-z0)/(z1-z0);
rec.v = (z-z0)/(z1-z0);
rec.t = t;
rec.mat_ptr = mp;
rec.p = r.point_at_parameter(t);
Expand Down

0 comments on commit f2f9d11

Please sign in to comment.