Rev 98 | Rev 102 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 98 | Rev 99 | ||
---|---|---|---|
Line 291... | Line 291... | ||
291 | } |
291 | } |
Line 292... | Line 292... | ||
292 | 292 | ||
293 | 293 | ||
- | 294 | //------------------------------------------------------------ |
|
294 | //------------------------------------------------------------ |
295 | // Rescale xy-vector length if length limit is violated |
295 | // Rescale xy-vector length if length limit is violated |
296 | // return vector length after scaling |
296 | void GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
297 | u32 GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
Line 297... | Line 298... | ||
297 | { |
298 | { |
298 | double dist; |
299 | u32 dist; |
299 | 300 | ||
300 | dist = hypot(*x,*y); // the length of the vector |
301 | dist = (u32)hypot(*x,*y); // the length of the vector |
301 | if ((u32)dist > limit) |
302 | if (dist > limit) |
302 | // if vector length is larger than the given limit |
303 | // if vector length is larger than the given limit |
- | 304 | { // scale vector compontents so that the length is cut off to limit |
|
303 | { // scale vector compontents so that the length is cut off to limit |
305 | *x = (s32)(((double)(*x) * (double)limit) / dist); |
- | 306 | *y = (s32)(((double)(*y) * (double)limit) / dist); |
|
304 | *x = (s32)(((double)(*x) * limit) / dist); |
307 | dist = limit; |
Line 305... | Line 308... | ||
305 | *y = (s32)(((double)(*y) * limit) / dist); |
308 | } |
306 | } |
309 | return(dist); |
307 | } |
310 | } |