<commit_before>#ifndef RT_STRUCT_H
#define RT_STRUCT_H

#include <cmath>
#include "my_rand.h"


struct Vec3 {
	double x, y, z;
	Vec3(const double x = 0, const double y = 0, const double z = 0) : x(x), y(y), z(z) {}
	inline Vec3 operator+(const Vec3 &b) const {return Vec3(x + b.x, y + b.y, z + b.z);}
	inline Vec3 operator-(const Vec3 &b) const {return Vec3(x - b.x, y - b.y, z - b.z);}
	inline Vec3 operator*(const Vec3 &b) const { return Vec3(x * b.x, y * b.y, z * b.z); }
	inline Vec3 operator*(const double b) const {return Vec3(x * b, y * b, z * b);}
	inline Vec3 operator/(const double b) const {return Vec3(x / b, y / b, z / b);}
	inline Vec3 operator-() const { return Vec3(-x, -y, -z); }
	inline const double length_sq() const { return x * x + y * y + z * z; }
	inline const double length() const { return sqrt(length_sq()); }
	inline Vec3 normalize() const { return *this / length(); }
	Vec3 reflect(const Vec3& n) const;
	bool refract(const Vec3& n, double ni_over_nt, Vec3& refracted) const;

	static Vec3 random_in_unit_disc(my_rand &rnd);
	static Vec3 random_in_unit_sphere(my_rand &rnd);
};
inline Vec3 operator*(double f, const Vec3 &v) { return v * f; }
inline Vec3 normalize(const Vec3 &v) {return v * (1.0 / v.length());}
inline const double dot(const Vec3 &v1, const Vec3 &v2) {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;}
inline const Vec3 cross(const Vec3 &v1, const Vec3 &v2) { return Vec3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); }

inline Vec3 Vec3::reflect(const Vec3& n) const { return *this - n * 2 * dot(*this, n); }
inline bool Vec3::refract(const Vec3& n, double ni_over_nt, Vec3& refracted) const {
	Vec3 uv = this->normalize();
	double dt = dot(uv, n);
	double discriminant = 1.0 - ni_over_nt * ni_over_nt * (1 - dt * dt);
	if (discriminant > 0) {
		refracted = (uv - n * dt)*ni_over_nt - n * sqrt(discriminant);
		return true;
	}
	else
		return false;
}

inline Vec3 Vec3::random_in_unit_disc(my_rand &rnd)
{
	do {
		Vec3 p = Vec3(rnd.get(), rnd.get(), 0) * 2.0 - Vec3(1, 1, 0);
		if (dot(p, p) < 1.0) return p;
	} while (true);
}

inline Vec3 Vec3::random_in_unit_sphere(my_rand &rnd)
{
	do {
		Vec3 p = Vec3(rnd.get(), rnd.get(), rnd.get()) * 2.0 - Vec3(1, 1, 1);
		if (dot(p, p) < 1.0) return p;
	} while (true);
}


class Ray
{
private:
	Vec3 o_;
	Vec3 d_;
public:
	Ray() {}
	Ray(const Vec3& o, const Vec3& d) { o_ = o; d_ = d; }
	Vec3 origin() const { return o_; }
	Vec3 direction() const { return d_; }
	Vec3 get(double t) const { return o_ + d_ * t; }
};

class Material;

struct HitRecord
{
	double t;
	Vec3 p;
	Vec3 normal;
	Material *mat_ptr;
};

class Hitable {
public:
	virtual bool hit(const Ray& r, double t_min, double t_max, HitRecord& rec) const = 0;
};

class Sphere : public Hitable {
private:
	Vec3 center_;
	double radius_;
	Material *mat_ptr_;
public:
	Sphere() {}
	Sphere(Vec3 cen, double r, Material *m) : center_(cen), radius_(r), mat_ptr_(m) {};
	bool hit(const Ray& r, double tmin, double tmax, HitRecord& rec) const {
		Vec3 oc = r.origin() - center_;
		double a = dot(r.direction(), r.direction());
		double b = dot(oc, r.direction());<commit_msg>Update RT_struct.h<commit_after>#ifndef RT_STRUCT_H
#define RT_STRUCT_H

#include <cmath>
#include "my_rand.h"


struct Vec3 {
	double x, y, z;
	Vec3(const double x = 0, const double y = 0, const double z = 0) : x(x), y(y), z(z) {}
	inline Vec3 operator+(const Vec3 &b) const {return Vec3(x + b.x, y + b.y, z + b.z);}
	inline Vec3 operator-(const Vec3 &b) const {return Vec3(x - b.x, y - b.y, z - b.z);}
	inline Vec3 operator*(const Vec3 &b) const { return Vec3(x * b.x, y * b.y, z * b.z); }
	inline Vec3 operator*(const double b) const {return Vec3(x * b, y * b, z * b);}
	inline Vec3 operator/(const double b) const {return Vec3(x / b, y / b, z / b);}
	inline Vec3 operator-() const { return Vec3(-x, -y, -z); }
	inline const double length_sq() const { return x * x + y * y + z * z; }
	inline const double length() const { return sqrt(length_sq()); }
	inline Vec3 normalize() const { return *this / length(); }
	Vec3 reflect(const Vec3& n) const;
	bool refract(const Vec3& n, double ni_over_nt, Vec3& refracted) const;

	static Vec3 random_in_unit_disc(my_rand &rnd);
	static Vec3 random_in_unit_sphere(my_rand &rnd);
};
inline Vec3 operator*(double f, const Vec3 &v) { return v * f; }
inline Vec3 normalize(const Vec3 &v) {return v * (1.0 / v.length());}
inline const double dot(const Vec3 &v1, const Vec3 &v2) {return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;}
inline const Vec3 cross(const Vec3 &v1, const Vec3 &v2) { return Vec3(v1.y * v2.z - v1.z * v2.y, v1.z * v2.x - v1.x * v2.z, v1.x * v2.y - v1.y * v2.x); }

inline Vec3 Vec3::reflect(const Vec3& n) const { return *this - n * 2 * dot(*this, n); }
inline bool Vec3::refract(const Vec3& n, double ni_over_nt, Vec3& refracted) const {
	Vec3 uv = this->normalize();
	double dt = dot(uv, n);
	double discriminant = 1.0 - ni_over_nt * ni_over_nt * (1 - dt * dt);
	if (discriminant > 0) {
		refracted = (uv - n * dt)*ni_over_nt - n * sqrt(discriminant);
		return true;
	}
	else
		return false;
}

inline Vec3 Vec3::random_in_unit_disc(my_rand &rnd)
{
	do {
		Vec3 p = Vec3(rnd.get(), rnd.get(), 0) * 2.0 - Vec3(1, 1, 0);
		if (dot(p, p) < 1.0) return p;
	} while (true);
}

inline Vec3 Vec3::random_in_unit_sphere(my_rand &rnd)
{
	do {
		Vec3 p = Vec3(rnd.get(), rnd.get(), rnd.get()) * 2.0 - Vec3(1, 1, 1);
		if (dot(p, p) < 1.0) return p;
	} while (true);
}


class Ray
{
private:
	Vec3 o_;
	Vec3 d_;
public:
	Ray() {}
	Ray(const Vec3& o, const Vec3& d) { o_ = o; d_ = d; }
	Vec3 origin() const { return o_; }
	Vec3 direction() const { return d_; }
	Vec3 get(double t) const { return o_ + d_ * t; }
};

class Material;

struct HitRecord
{
	double t;
	Vec3 p;
	Vec3 normal;
	Material *mat_ptr;
};

class Hitable {
public:
	virtual bool hit(const Ray& r, double t_min, double t_max, HitRecord& rec) const = 0;
};

class Sphere : public Hitable {
private:
	Vec3 center_;
	double radius_;
	Material *mat_ptr_;
public:
	Sphere() {}
	Sphere(Vec3 cen, double r, Material *m) : center_(cen), radius_(r), mat_ptr_(m) {};
	bool hit(const Ray& r, double tmin, double tmax, HitRecord& rec) const {
		return false;
		Vec3 oc = r.origin() - center_;
		double a = dot(r.direction(), r.direction());
		double b = dot(oc, r.direction());
{'fraction_non_alphanumeric': 0.16363923550781867, 'fraction_numerical': 0.035065550465961146, 'mean_word_length': 3.59840232389252, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3573785', 'n_tokens_mistral': 2692, 'n_tokens_neox': 2604, 'n_words': 826}