#ifndef RAYTRACER_BOX_HPP
#define RAYTRACER_BOX_HPP

#include "./vec3.hpp"
#include "./color.hpp"
#include "./object.hpp"
#include "./material.hpp"

namespace raytracer
{
class box: public object
{
 public:
  box(const vec3& vMin, const vec3& vMax, const material& mat): object(mat)
  {      
    vmin_= vMin;
    vmax_= vMax;
    this->pos_= vMin.add(vMax).scale(0.5);
    halflen_.x= fabs(vMax.x-vMin.x)/2;
    halflen_.y= fabs(vMax.y-vMin.y)/2;
    halflen_.z= fabs(vMax.z-vMin.z)/2;
  }
  box(const vec3& pos, const double edgelen, const material& mat): object(mat)
  {
    halflen_.x= halflen_.y= halflen_.z= edgelen/2.0f;
    this->pos_= pos;
    vmin_= pos.add(halflen_.negative());
    vmax_= pos.add(halflen_);
  }

  inline const vec3& vmin(){ return this->vmin_; }
  inline const vec3& vmax(){ return this->vmax_; }

  virtual bool intersects(const ray& ray, double& length, vec3& normal, material& material) const;
    
 private:
  vec3 vmin_, vmax_, halflen_;
};
}
#endif
