<NME> hmm_test.c
<BEF> #include "hmm_test.h"

int main()
{
    int tests_failed = hmt_run_all_tests();
    int coverage_failed = hmt_check_all_coverage();

    return tests_failed || coverage_failed;
}
        }
        TEST_END()

        TEST_BEGIN(Cross)
        {
            hmm_vec3 v1 = HMM_Vec3(1.0f, 2.0f, 3.0f);

<MSG> Handle zero-vector normalization. (#63)

* Handle zero-vector normalization.

When normalizing a vectors, we have to check whether vector length is
not zero, to avoid dividing by zero when normalizing zero-vectors.

* Test for normalization of zero vectors

<DFF> @@ -310,6 +310,54 @@ int run_tests()
         }
         TEST_END()
 
+        TEST_BEGIN(NormalizeZero)
+        {
+            hmm_vec2 v2 = HMM_Vec2(0.0f, 0.0f);
+            hmm_vec3 v3 = HMM_Vec3(0.0f, 0.0f, 0.0f);
+            hmm_vec4 v4 = HMM_Vec4(0.0f, 0.0f, 0.0f, 0.0f);
+
+            {
+                hmm_vec2 result = HMM_NormalizeVec2(v2);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+            }
+            {
+                hmm_vec3 result = HMM_NormalizeVec3(v3);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+                EXPECT_FLOAT_EQ(result.Z, 0.0f);
+            }
+            {
+                hmm_vec4 result = HMM_NormalizeVec4(v4);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+                EXPECT_FLOAT_EQ(result.Z, 0.0f);
+                EXPECT_FLOAT_EQ(result.W, 0.0f);
+            }
+
+#ifdef HANDMADE_MATH_CPP_MODE
+            {
+                hmm_vec2 result = HMM_Normalize(v2);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+            }
+            {
+                hmm_vec3 result = HMM_Normalize(v3);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+                EXPECT_FLOAT_EQ(result.Z, 0.0f);
+            }
+            {
+                hmm_vec4 result = HMM_Normalize(v4);
+                EXPECT_FLOAT_EQ(result.X, 0.0f);
+                EXPECT_FLOAT_EQ(result.Y, 0.0f);
+                EXPECT_FLOAT_EQ(result.Z, 0.0f);
+                EXPECT_FLOAT_EQ(result.W, 0.0f);
+            }
+#endif
+        }
+        TEST_END()
+
         TEST_BEGIN(Cross)
         {
             hmm_vec3 v1 = HMM_Vec3(1.0f, 2.0f, 3.0f);

{'addition_count': 48, 'commit_subject': 'Handle zero-vector normalization. (#63)', 'deletion_count': 0, 'file_extension': '.c', 'lang': 'c', 'license': 'cc0-1.0', 'repo_name': 'HandmadeMath/Handmade-Math'}