From fcb9645dbe17e8c5cf08769b73be56107541c95c Mon Sep 17 00:00:00 2001 From: Sara Date: Sun, 18 Jun 2023 16:34:28 +0200 Subject: [PATCH] added NORMALIZE #define macro avoids pointers and the accompanying dereference operations of normalize(...) --- src/corelib/math/vec.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/corelib/math/vec.h b/src/corelib/math/vec.h index 9a62b93..1129da3 100644 --- a/src/corelib/math/vec.h +++ b/src/corelib/math/vec.h @@ -25,6 +25,14 @@ void normalize(float* xx, float* yy) { } } +#define NORMALIZE(_xx, _yy) \ +if(_xx != 0 || _yy != 0) { \ + const float m = sqrtf(_xx*_xx + _yy*_yy); \ + _xx /= m; _yy /= m; \ +} else { \ + _xx = 0; _yy = 0; \ +} + static inline int move_towards(float* out_x, float* out_y, float x, float y, float tx, float ty, float max_delta) { const float diff_x = tx - x,