From 590d48b6c6b19bae136c2743cbd5753f1bb8d260 Mon Sep 17 00:00:00 2001 From: K Tyl Date: Sat, 6 Jun 2020 04:09:13 +0100 Subject: [PATCH] use snake_case --- src/colour.h | 8 ++++---- src/main.cpp | 40 ++++++++++++++++++++-------------------- src/vec3.h | 6 +++--- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/colour.h b/src/colour.h index 8f19595..2d42906 100755 --- a/src/colour.h +++ b/src/colour.h @@ -4,10 +4,10 @@ #include -void writeColour(std::ostream &out, colour pixelColour) +void write_colour(std::ostream &out, colour pixel_colour) { // write the translated [0,255] value of each colour component. - out << static_cast(255.999 * pixelColour.x()) << ' ' - << static_cast(255.999 * pixelColour.y()) << ' ' - << static_cast(255.999 * pixelColour.z()) << '\n'; + out << static_cast(255.999 * pixel_colour.x()) << ' ' + << static_cast(255.999 * pixel_colour.y()) << ' ' + << static_cast(255.999 * pixel_colour.z()) << '\n'; } diff --git a/src/main.cpp b/src/main.cpp index 660c732..a329384 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,15 +8,15 @@ const double ASPECT_RATIO = 16.0 / 9.0; const int WIDTH = 384; const int HEIGHT = static_cast(WIDTH / ASPECT_RATIO); -double hitSphere(const point3& centre, double radius, const ray& r) +double hit_sphere(const point3& centre, double radius, const ray& r) { vec3 oc = r.origin() - centre; - auto a = r.direction().lengthSquared(); - auto halfB = dot(oc, r.direction()); - auto c = oc.lengthSquared() - radius*radius; + auto a = r.direction().length_squared(); + auto half_b = dot(oc, r.direction()); + auto c = oc.length_squared() - radius*radius; - auto discriminant = halfB*halfB - a*c; + auto discriminant = half_b*half_b - a*c; if (discriminant < 0) { @@ -24,21 +24,21 @@ double hitSphere(const point3& centre, double radius, const ray& r) } else { - return (-halfB - sqrt(discriminant)) / a; + return (-half_b - sqrt(discriminant)) / a; } } -colour rayColour(const ray& r) +colour ray_colour(const ray& r) { - auto t = hitSphere(point3(0,0,-1), 0.5, r); + auto t = hit_sphere(point3(0,0,-1), 0.5, r); if (t > 0.0) { - vec3 N = unitVector(r.at(t) - vec3(0,0,-1)); + vec3 N = unit_vector(r.at(t) - vec3(0,0,-1)); return 0.5*colour(N.x()+1, N.y()+1, N.z()+1); } - vec3 unitDirection = unitVector(r.direction()); - t = 0.5 * (unitDirection.y() + 1.0); + vec3 unit_direction = unit_vector(r.direction()); + t = 0.5 * (unit_direction.y() + 1.0); auto a = colour(1.0, 0.5, 0.6); auto b = colour(0.0, 0.0, 0.0); @@ -48,14 +48,14 @@ colour rayColour(const ray& r) int main() { - auto viewportHeight = 2.0; - auto viewportWidth = ASPECT_RATIO * viewportHeight; - auto focalLength = 1.0; + auto viewport_height = 2.0; + auto viewport_width = ASPECT_RATIO * viewport_height; + auto focal_length = 1.0; auto origin = point3(0, 0, 0); - auto horizontal = vec3(viewportWidth, 0, 0); - auto vertical = vec3(0, viewportHeight, 0); - auto lowerLeftCorner = origin - horizontal/2 - vertical/2 - vec3(0,0,focalLength); + auto horizontal = vec3(viewport_width, 0, 0); + auto vertical = vec3(0, viewport_height, 0); + auto lower_left_corner = origin - horizontal/2 - vertical/2 - vec3(0,0,focal_length); std::cout << "P3\n" << WIDTH << ' ' << HEIGHT << "\n255\n"; @@ -66,10 +66,10 @@ int main() { auto u = double(x) / (WIDTH-1); auto v = double(y) / (HEIGHT-1); - ray r(origin, lowerLeftCorner + u*horizontal + v*vertical - origin); + ray r(origin, lower_left_corner + u*horizontal + v*vertical - origin); - colour pixelColour = rayColour(r); - writeColour(std::cout, pixelColour); + colour pixel_colour = ray_colour(r); + write_colour(std::cout, pixel_colour); } } diff --git a/src/vec3.h b/src/vec3.h index 08d3f46..c0084a7 100755 --- a/src/vec3.h +++ b/src/vec3.h @@ -40,10 +40,10 @@ public: double length() const { - return std::sqrt(lengthSquared()); + return std::sqrt(length_squared()); } - double lengthSquared() const + double length_squared() const { return e[0]*e[0] + e[1]*e[1] + e[2]*e[2]; } @@ -112,7 +112,7 @@ inline vec3 lerp(const vec3 &a, const vec3 &b, double t) return (1.0 - t) * a + t * b; } -inline vec3 unitVector(vec3 v) +inline vec3 unit_vector(vec3 v) { return v / v.length(); }