<commit_before>#include "physics.hpp"
#include <glm/glm.hpp>

namespace Physics
{
    // Compute the cross product AB x AC
    f32 CrossProduct(const glm::vec2& pointA, const glm::vec2& pointB, const glm::vec2& pointC)
    {
        glm::vec2 AB = pointB - pointA;
        glm::vec2 AC = pointC - pointA;
        f32 cross = AB.x * AC.y - AB.y * AC.x;
        return cross;
    }

    bool IsLineSegmentsIntersecting(const glm::vec2& line1p1, const glm::vec2& line1p2, const glm::vec2& line2p1, const glm::vec2& line2p2, raycast_collision* const collision)
    {
        // Get the segments' parameters.
        const float dx12 = line1p2.x - line1p1.x;
        const float dy12 = line1p2.y - line1p1.y;
        const float dx34 = line2p2.x - line2p1.x;
        const float dy34 = line2p2.y - line2p1.y;

        // Solve for t1 and t2
        const float denominator = (dy12 * dx34 - dx12 * dy34);
        if (denominator == 0.0f) // Collinear
        {
            // collision is undefined when there isn't a collision
            return false;
        }

        const float t1 = ((line1p1.x - line2p1.x) * dy34 + (line2p1.y - line1p1.y) * dx34) / denominator;
        const float t2 = ((line2p1.x - line1p1.x) * dy12 + (line1p1.y - line2p1.y) * dx12) / -denominator;

        // The segments intersect if t1 and t2 are between 0 and 1.
        const bool intersecting = (t1 >= 0.0f) && (t1 <= 1.0f) && (t2 >= 0.0f) && (t2 <= 1.0f);

        // Find the point of intersection.
        if (collision && intersecting)
        {
            collision->intersection = glm::vec2(line1p1.x + dx12 * t1, line1p1.y + dy12 * t1);
        }

        return intersecting;
    }

    // Compute the dot product AB . BC
    f32 DotProduct(const glm::vec2& pointA, const glm::vec2& pointB, const glm::vec2& pointC)<commit_msg>put clamping back, might be required to handle floating point drift, seemed to be in the wrong place previously ?<commit_after>#include "physics.hpp"
#include <glm/glm.hpp>

namespace Physics
{
    // Compute the cross product AB x AC
    f32 CrossProduct(const glm::vec2& pointA, const glm::vec2& pointB, const glm::vec2& pointC)
    {
        glm::vec2 AB = pointB - pointA;
        glm::vec2 AC = pointC - pointA;
        f32 cross = AB.x * AC.y - AB.y * AC.x;
        return cross;
    }

    bool IsLineSegmentsIntersecting(const glm::vec2& line1p1, const glm::vec2& line1p2, const glm::vec2& line2p1, const glm::vec2& line2p2, raycast_collision* const collision)
    {
        // Get the segments' parameters.
        const float dx12 = line1p2.x - line1p1.x;
        const float dy12 = line1p2.y - line1p1.y;
        const float dx34 = line2p2.x - line2p1.x;
        const float dy34 = line2p2.y - line2p1.y;

        // Solve for t1 and t2
        const float denominator = (dy12 * dx34 - dx12 * dy34);
        if (denominator == 0.0f) // Collinear
        {
            // collision is undefined when there isn't a collision
            return false;
        }

        float t1 = ((line1p1.x - line2p1.x) * dy34 + (line2p1.y - line1p1.y) * dx34) / denominator;
        float t2 = ((line2p1.x - line1p1.x) * dy12 + (line1p1.y - line2p1.y) * dx12) / -denominator;

        // Find the closest points on the segments.
        if (t1 < 0)
        {
            t1 = 0;
        }
        else if (t1 > 1)
        {
            t1 = 1;
        }

        if (t2 < 0)
        {
            t2 = 0;
        }
        else if (t2 > 1)
        {
            t2 = 1;
        }

        // The segments intersect if t1 and t2 are between 0 and 1.
        const bool intersecting = (t1 >= 0.0f) && (t1 <= 1.0f) && (t2 >= 0.0f) && (t2 <= 1.0f);

        // Find the point of intersection.
        if (collision && intersecting)
        {
            collision->intersection = glm::vec2(line1p1.x + dx12 * t1, line1p1.y + dy12 * t1);
        }

        return intersecting;
    }

    // Compute the dot product AB . BC
    f32 DotProduct(const glm::vec2& pointA, const glm::vec2& pointB, const glm::vec2& pointC)
{'fraction_non_alphanumeric': 0.12077534791252485, 'fraction_numerical': 0.06113320079522863, 'mean_word_length': 1.9272727272727272, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '6091271', 'n_tokens_mistral': 1539, 'n_tokens_neox': 1439, 'n_words': 407}