T3 Add interval.h

Add the following source code

Create interval.h under the src folder

#ifndef INTERVAL_H
#define INTERVAL_H

class interval {
  public:
    double min, max;

    interval() : min(+infinity), max(-infinity) {} // Default interval is empty

    interval(double min, double max) : min(min), max(max) {}

    double size() const {
        return max - min;
    }

    bool contains(double x) const {
        return min <= x && x <= max;
    }

    bool surrounds(double x) const {
        return min < x && x < max;
    }

    static const interval empty, universe;
};

const interval interval::empty    = interval(+infinity, -infinity);
const interval interval::universe = interval(-infinity, +infinity);

#endif

Revise rtweekend.h

Revise hittable, hittable_list, sphere to use intervals

hittable

hittable_list

sphere

main.cpp

in function ray_color, make following changes

Build Your Program

to make sure everything is correct

Last updated