소스 검색

Vector: correctly normalize zero vector

SG 1 년 전
부모
커밋
209bb5af5e
1개의 변경된 파일4개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      vector.c

+ 4 - 0
vector.c

@@ -1,5 +1,6 @@
 #include "vector.h"
 #include <math.h>
+#include <float.h>
 
 #undef vector_add
 #undef vector_sub
@@ -44,6 +45,9 @@ float vector_length(Vector v) {
 
 Vector vector_normalize(Vector v) {
     float length = vector_length(v);
+    if(length < FLT_EPSILON) {
+        return (Vector){0, 0};
+    }
     return (Vector){v.x / length, v.y / length};
 }