LCOV - code coverage report
Current view: top level - test - plane.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 64 64
Test Date: 2026-04-03 02:26:39 Functions: 100.0 % 2 2

            Line data    Source code
       1              : #include "catch.hpp"
       2              : #include "Plane.h"
       3              : #include "Vector.h"
       4              : 
       5            8 : SCENARIO( "Plane operations", "[Plane]" ) {
       6            8 :   GIVEN( "Default plane" ) {
       7            1 :     Plane p;
       8              :     float a, b, c, d;
       9            1 :     p.getDefinition(a, b, c, d);
      10              : 
      11            2 :     THEN( "default is X-normal through origin" ) {
      12            1 :       REQUIRE(a == Approx(1.0f));
      13            1 :       REQUIRE(b == Approx(0.0f));
      14            1 :       REQUIRE(c == Approx(0.0f));
      15            1 :       REQUIRE(d == Approx(0.0f));
      16            1 :     }
      17            1 :   }
      18              : 
      19            8 :   GIVEN( "setPlane and getDefinition round-trip" ) {
      20            1 :     Plane p;
      21            1 :     p.setPlane(2.0f, -3.0f, 4.0f, -5.0f);
      22              :     float a, b, c, d;
      23            1 :     p.getDefinition(a, b, c, d);
      24              : 
      25            2 :     THEN( "coefficients match" ) {
      26            1 :       REQUIRE(a == Approx(2.0f));
      27            1 :       REQUIRE(b == Approx(-3.0f));
      28            1 :       REQUIRE(c == Approx(4.0f));
      29            1 :       REQUIRE(d == Approx(-5.0f));
      30            1 :     }
      31            1 :   }
      32              : 
      33           11 :   GIVEN( "Normalized plane through origin" ) {
      34            4 :     Plane p;
      35            4 :     p.setPlane(3.0f, 4.0f, 0.0f, 0.0f);
      36            4 :     p.normalize();
      37              :     float a, b, c, d;
      38            4 :     p.getDefinition(a, b, c, d);
      39            4 :     const float invLen = 0.2f;
      40              : 
      41            5 :     THEN( "normal is unit length" ) {
      42            1 :       REQUIRE(a == Approx(3.0f * invLen));
      43            1 :       REQUIRE(b == Approx(4.0f * invLen));
      44            1 :       REQUIRE(c == Approx(0.0f));
      45            1 :       REQUIRE(d == Approx(0.0f));
      46            1 :     }
      47              : 
      48            5 :     THEN( "distanceToPoint is signed distance" ) {
      49            1 :       REQUIRE(p.distanceToPoint(5.0f, 0.0f, 0.0f) == Approx(3.0f * invLen * 5.0f));
      50            1 :       REQUIRE(p.distanceToPoint(0.0f, 0.0f, 0.0f) == Approx(0.0f));
      51            1 :     }
      52              : 
      53            5 :     THEN( "classifyPoint distinguishes sides" ) {
      54            1 :       REQUIRE(p.classifyPoint(10.0f, 0.0f, 0.0f) == 1);
      55            1 :       REQUIRE(p.classifyPoint(-10.0f, 0.0f, 0.0f) == -1);
      56            1 :       REQUIRE(p.classifyPoint(0.0f, 0.0f, 0.0f) == 0);
      57            1 :     }
      58              : 
      59            5 :     THEN( "getNormalVector matches abc" ) {
      60            1 :       Vector n;
      61            1 :       p.getNormalVector(n);
      62            1 :       REQUIRE(n.x == Approx(a));
      63            1 :       REQUIRE(n.y == Approx(b));
      64            1 :       REQUIRE(n.z == Approx(c));
      65            1 :     }
      66            4 :   }
      67              : 
      68            8 :   GIVEN( "Normalizing a degenerate normal" ) {
      69            1 :     Plane p;
      70            1 :     p.setPlane(0.0f, 0.0f, 0.0f, 5.0f);
      71            1 :     p.normalize();
      72              :     float a, b, c, d;
      73            1 :     p.getDefinition(a, b, c, d);
      74              : 
      75            2 :     THEN( "coefficients are unchanged when length is zero" ) {
      76            1 :       REQUIRE(a == Approx(0.0f));
      77            1 :       REQUIRE(b == Approx(0.0f));
      78            1 :       REQUIRE(c == Approx(0.0f));
      79            1 :       REQUIRE(d == Approx(5.0f));
      80            1 :     }
      81            1 :   }
      82            7 : }
        

Generated by: LCOV version 2.4-0