<commit_before>#include "box.hpp"

Box::Box():
Shape::Shape("untitled_box", Color{0.0}),
_min{glm::vec3{0}},
_max{glm::vec3{0}}
{
	std::cout << "Box construct \n";
}

Box::Box(glm::vec3 const& min, glm::vec3 const& max):
Shape::Shape("untitled_box", Color{0.0}),
_min{min},
_max{max}
{
	std::cout << "Box construct \n";
}

Box::Box(glm::vec3 const& min, glm::vec3 const& max, std::string const& name, Color const& color):
Shape::Shape(name, color),
_min{min},
_max{max}
{
	std::cout << "Box construct \n";
}

std::ostream& Box::print(std::ostream& os) const
{
	os << "[Box ID: " << std::addressof(this) << "]\n" <<
				"Name: " << _name << "\n" <<
 				"Color: " << _color <<
 				"Min: " << glm::to_string(_min) << "\n" <<
 				"Max: " << glm::to_string(_max) << "\n\n"; 
	return os;
}

bool Box::intersect(Ray const& ray, float& distance) const
{
	throw std::runtime_error("not implemented");
}

glm::vec3 Box::min() const
{
	return _min;
}

glm::vec3 Box::max() const
{
	return _max;
}

double Box::area() const
{
	glm::vec3 v = _max - _min;
	return 2 * (v.x * v.y) + 2 * (v.x * v.z) + 2 * (v.z * v.y);
}

double Box::volume() const
{
	glm::vec3 v = _max - _min;
	return v.x * v.y * v.z;
}

Box::~Box()
{
	std::cout << "Box destruct \n";
}<commit_msg>Added method-body to intersect() method of box.cpp<commit_after>#include "box.hpp"

Box::Box():
Shape::Shape("untitled_box", Color{0.0}),
_min{glm::vec3{0}},
_max{glm::vec3{0}}
{
	std::cout << "Box construct \n";
}

Box::Box(glm::vec3 const& min, glm::vec3 const& max):
Shape::Shape("untitled_box", Color{0.0}),
_min{min},
_max{max}
{}

Box::Box(glm::vec3 const& min, glm::vec3 const& max, std::string const& name, Color const& color):
Shape::Shape(name, color),
_min{min},
_max{max}
{
	std::cout << "Box construct \n";
}

std::ostream& Box::print(std::ostream& os) const
{
	os << "[Box ID: " << std::addressof(this) << "]\n" <<
				"Name: " << _name << "\n" <<
 				"Color: " << _color <<
 				"Min: " << glm::to_string(_min) << "\n" <<
 				"Max: " << glm::to_string(_max) << "\n\n"; 
	return os;
}

bool Box::intersect(Ray const& r, float& distance) const
{
	double tx1 = (_min.x - r.origin.x)/glm::normalize(r.direction).x;
	double tx2 = (_max.x - r.origin.x)/glm::normalize(r.direction).x;

	double tnear = std::min(tx1, tx2);
	double tfar = std::max(tx1, tx2);

	double ty1 = (_min.y - r.origin.y)/glm::normalize(r.direction).y;
	double ty2 = (_max.y - r.origin.y)/glm::normalize(r.direction).y;

	tnear = std::max(tnear, std::min(ty1, ty2));
	tfar = std::min(tfar, std::max(ty1, ty2));

	double tz1 = (_min.z - r.origin.z)/glm::normalize(r.direction).z;
	double tz2 = (_max.z - r.origin.z)/glm::normalize(r.direction).z;

	tnear = std::max(tnear, std::min(tz1, tz2));
	tfar = std::min(tfar, std::max(tz1, tz2));

	return tfar >= std::max(0.0, tnear);
}

glm::vec3 Box::min() const
{
	return _min;
}

glm::vec3 Box::max() const
{
	return _max;
}

double Box::area() const
{
	glm::vec3 v = _max - _min;
	return 2 * (v.x * v.y) + 2 * (v.x * v.z) + 2 * (v.z * v.y);
}

double Box::volume() const
{
	glm::vec3 v = _max - _min;
	return v.x * v.y * v.z;
}

Box::~Box()
{
	std::cout << "Box destruct \n";
}
{'fraction_non_alphanumeric': 0.24058246280468504, 'fraction_numerical': 0.018360240582462804, 'mean_word_length': 4.14657980456026, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4378956', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1385, 'n_words': 291}