Normalize a vector. Returns: the magnitude before normalization
| 316 | // Normalize a vector. |
| 317 | // Returns: the magnitude before normalization |
| 318 | float vm_VectorNormalize(vector *a) { |
| 319 | float mag; |
| 320 | |
| 321 | mag = vm_GetMagnitude(a); |
| 322 | |
| 323 | if (mag > 0) |
| 324 | *a /= mag; |
| 325 | else { |
| 326 | *a = Zero_vector; |
| 327 | a->x = 1.0; |
| 328 | mag = 0.0f; |
| 329 | } |
| 330 | |
| 331 | return mag; |
| 332 | } |
| 333 | |
| 334 | float vm_GetMagnitude(vector *a) { |
| 335 | float f; |
no test coverage detected