normalize will now normalize if either x or y is non-zero
previously 100,0 would return 100,0 instead of 1,0pull/8/head
parent
494dbfedb3
commit
6f78731d8f
|
@ -18,7 +18,7 @@ void clamp_magnitude(float* xx, float* yy, float max_magnitude) {
|
||||||
static inline
|
static inline
|
||||||
void normalize(float* xx, float* yy) {
|
void normalize(float* xx, float* yy) {
|
||||||
float x = *xx, y = *yy;
|
float x = *xx, y = *yy;
|
||||||
if(x != 0 && y != 0) {
|
if(x != 0 || y != 0) {
|
||||||
const float m = sqrtf(x*x + y*y);
|
const float m = sqrtf(x*x + y*y);
|
||||||
x /= m; y /= m;
|
x /= m; y /= m;
|
||||||
*xx = x; *yy = y;
|
*xx = x; *yy = y;
|
||||||
|
|
Loading…
Reference in New Issue