<commit_before>#pragma once

#include "types.h"

//
// Return min infinity if there is no intersection, otherwise return r s.t. the
// intersection point is P0 + r * (P1 - P0).
//
// If n is normalized, then r is exactly the Euclidean distance from the ray to
// the plane. Note: r may be negative.
//
// Args:
//   v0, n: Plane through v0 with normal n
//
// Cf. http://geomalgorithms.com/a06-_intersect-2.html
//
float ray_plane_intersection(const Ray& ray, const Vec& v0, const Vec& n) {
    auto denom = n * ray.dir;
    if (denom == 0) {
        return std::numeric_limits<float>::min();
    }

    auto nom = n * (v0 - ray.pos);
    return nom / denom;
}

//
// Intersect a ray with an AABB (axis-aligned bounding box).
//
// Cf. http://people.csail.mit.edu/amy/papers/box-jgt.pdf
//
bool ray_box_intersection(const Ray& r, const Box& box) {
    float tx1 = (box.min.x - r.pos.x) * r.invdir.x;
    float tx2 = (box.max.x - r.pos.x) * r.invdir.x;

    float tmin = std::fmin(tx1, tx2);<commit_msg>Fix min float value in plane intersection.<commit_after>#pragma once

#include "types.h"

//
// Return min infinity if there is no intersection, otherwise return r s.t. the
// intersection point is P0 + r * (P1 - P0).
//
// If n is normalized, then r is exactly the Euclidean distance from the ray to
// the plane. Note: r may be negative.
//
// Args:
//   v0, n: Plane through v0 with normal n
//
// Cf. http://geomalgorithms.com/a06-_intersect-2.html
//
float ray_plane_intersection(const Ray& ray, const Vec& v0, const Vec& n) {
    auto denom = n * ray.dir;
    if (denom == 0) {
        return std::numeric_limits<float>::lowest();
    }

    auto nom = n * (v0 - ray.pos);
    return nom / denom;
}

//
// Intersect a ray with an AABB (axis-aligned bounding box).
//
// Cf. http://people.csail.mit.edu/amy/papers/box-jgt.pdf
//
bool ray_box_intersection(const Ray& r, const Box& box) {
    float tx1 = (box.min.x - r.pos.x) * r.invdir.x;
    float tx2 = (box.max.x - r.pos.x) * r.invdir.x;

    float tmin = std::fmin(tx1, tx2);
{'fraction_non_alphanumeric': 0.15471512770137524, 'fraction_numerical': 0.014734774066797643, 'mean_word_length': 2.5736842105263156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5172508', 'n_tokens_mistral': 768, 'n_tokens_neox': 747, 'n_words': 237}