LCOV - code coverage report
Current view: top level - rbc/analytic - SphereSphere.hpp (source / functions) Coverage Total Hit
Test: coverage_clean.info Lines: 100.0 % 12 12
Test Date: 2026-03-30 03:13:12 Functions: 100.0 % 1 1

            Line data    Source code
       1              : #pragma once
       2              : #include "rbc/shapes/ShapeTypes.hpp"
       3              : #include "rbc/Contact.hpp"
       4              : #include <math3d/math3d.hpp>
       5              : namespace rbc
       6              : {
       7              : 
       8              :     // ── Sphere vs Sphere ─────────────────────────────────────────────────────────
       9              :     // Pure distance check — no SAT, no GJK needed.
      10              :     // The only axis that matters is the vector between the two centres.
      11              : 
      12              :     template <>
      13              :     struct CollisionAlgorithm<Sphere, Sphere>
      14              :     {
      15          434 :         static bool test(const Sphere &a, const m3d::tf &tf_a,
      16              :                          const Sphere &b, const m3d::tf &tf_b,
      17              :                          ContactManifold &manifold)
      18              :         {
      19          434 :             const m3d::vec3 delta = tf_b.pos - tf_a.pos;
      20          434 :             const m3d::scalar dist = m3d::length(delta);
      21          434 :             const m3d::scalar rsum = a.radius + b.radius;
      22              : 
      23          434 :             if (dist >= rsum)
      24          422 :                 return false; // separated
      25              : 
      26              : 
      27              :             // Normal points from A to B (the direction A needs to move to separate)
      28           12 :             manifold.normal = (dist > m3d::EPSILON)
      29           12 :                              ? delta / dist
      30              :                              : m3d::vec3(1.0, 0.0, 0.0); // coincident centres — pick arbitrary axis
      31              : 
      32           12 :             manifold.num_points = 1;
      33           12 :             manifold.points[0].penetration_depth = rsum - dist;
      34           12 :             manifold.points[0].position = tf_a.pos + manifold.normal * a.radius;
      35              : 
      36           12 :             return true;
      37              :         }
      38              :     };
      39              : 
      40              : } // namespace rbc
        

Generated by: LCOV version 2.0-1