<commit_before>#include <cmath>
#include "sphere.h"

namespace pt {

Sphere::Sphere(const glm::vec3 &center, const float radius) : center(center), radius(radius) {}
bool Sphere::intersect(Ray &ray, DifferentialGeometry &dg) const {
	const float a = glm::dot(ray.dir, ray.dir);
	const float b = 2.0 * glm::dot(ray.dir, ray.origin);
	const float c = glm::dot(ray.origin, ray.origin) - radius * radius;
	const float discrim = b * b - 4.0 * a * c;
	if (discrim > 0.f){
		float t = (-b - std::sqrt(discrim)) / (2.0 * a);
		if (t > ray.t_min && t < ray.t_max){
			ray.t_max = t;
			dg.point = ray.origin + ray.dir * t;
			dg.normal = glm::normalize(dg.point - center);
			return true;
		} else {
			t = (-b + std::sqrt(discrim)) / (2.0 * a);
			if (t > ray.t_min && t < ray.t_max){
				ray.t_max = t;
				dg.point = ray.origin + ray.dir * t;
				dg.normal = glm::normalize(dg.point - center);
				return true;
			}
		}
	}
	return false;
}

}
<commit_msg>Actually account for sphere center pos<commit_after>#include <cmath>
#include <glm/ext.hpp>
#include "sphere.h"

namespace pt {

Sphere::Sphere(const glm::vec3 &center, const float radius) : center(center), radius(radius) {}
bool Sphere::intersect(Ray &ray, DifferentialGeometry &dg) const {
	const float a = glm::length2(ray.dir);
	const glm::vec3 oc = ray.origin - center;
	const float b = 2.0 * glm::dot(ray.dir, oc);
	const float c = glm::length2(oc) - radius * radius;
	const float discrim = b * b - 4.0 * a * c;
	if (discrim > 0.f){
		float t = (-b - std::sqrt(discrim)) / (2.0 * a);
		if (t > ray.t_min && t < ray.t_max){
			ray.t_max = t;
			dg.point = ray.origin + ray.dir * t;
			dg.normal = glm::normalize(dg.point - center);
			return true;
		} else {
			t = (-b + std::sqrt(discrim)) / (2.0 * a);
			if (t > ray.t_min && t < ray.t_max){
				ray.t_max = t;
				dg.point = ray.origin + ray.dir * t;
				dg.normal = glm::normalize(dg.point - center);
				return true;
			}
		}
	}
	return false;
}

}

{'fraction_non_alphanumeric': 0.18028600612870277, 'fraction_numerical': 0.01174668028600613, 'mean_word_length': 3.0308641975308643, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, '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': '1427138', 'n_tokens_mistral': 870, 'n_tokens_neox': 782, 'n_words': 200}