Subversion Repositories NaviCtrl

Compare Revisions

Ignore whitespace Rev 97 → Rev 98

/trunk/GPS.c
295,18 → 295,14
// Rescale xy-vector length if length limit is violated
void GPS_LimitXY(s32 *x, s32 *y, u32 limit)
{
u32 dist;
dist = (u32)hypot(*x,*y); // the length of the vector
if (dist == 0)
{
*x = 0;
*y = 0;
}
else if (dist > limit)
double dist;
 
dist = hypot(*x,*y); // the length of the vector
if ((u32)dist > limit)
// if vector length is larger than the given limit
{ // scale vector compontents so that the length is cut off to limit
*x = (*x * limit) / dist;
*y = (*y * limit) / dist;
*x = (s32)(((double)(*x) * limit) / dist);
*y = (s32)(((double)(*y) * limit) / dist);
}
}