added NORMALIZE #define macro

avoids pointers and the accompanying dereference operations of normalize(...)
pull/8/head
Sara 2023-06-18 16:34:28 +02:00
parent 6f78731d8f
commit fcb9645dbe
1 changed files with 8 additions and 0 deletions

View File

@ -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 static inline
int move_towards(float* out_x, float* out_y, float x, float y, float tx, float ty, float max_delta) { 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, const float diff_x = tx - x,