293,17 → 293,20 |
|
//------------------------------------------------------------ |
// Rescale xy-vector length if length limit is violated |
void GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
// return vector length after scaling |
u32 GPS_LimitXY(s32 *x, s32 *y, u32 limit) |
{ |
double dist; |
u32 dist; |
|
dist = hypot(*x,*y); // the length of the vector |
if ((u32)dist > limit) |
dist = (u32)hypot(*x,*y); // the length of the vector |
if (dist > limit) |
// if vector length is larger than the given limit |
{ // scale vector compontents so that the length is cut off to limit |
*x = (s32)(((double)(*x) * limit) / dist); |
*y = (s32)(((double)(*y) * limit) / dist); |
*x = (s32)(((double)(*x) * (double)limit) / dist); |
*y = (s32)(((double)(*y) * (double)limit) / dist); |
dist = limit; |
} |
return(dist); |
} |
|
//------------------------------------------------------------ |