Subversion Repositories NaviCtrl

Rev

Rev 97 | Rev 99 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 97 Rev 98
Line 293... Line 293...
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
void GPS_LimitXY(s32 *x, s32 *y, u32 limit)
296
void GPS_LimitXY(s32 *x, s32 *y, u32 limit)
297
{
297
{
-
 
298
        double dist;
298
        u32 dist;
299
 
299
        dist = (u32)hypot(*x,*y);       // the length of the vector
-
 
300
        if (dist == 0)
-
 
301
        {
-
 
302
                *x = 0;
-
 
303
                *y = 0;
-
 
304
        }
300
        dist = hypot(*x,*y);    // the length of the vector
305
        else if (dist > limit)
301
        if ((u32)dist > limit)
306
        // if vector length is larger than the given limit
302
        // if vector length is larger than the given limit
307
        {       // 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
308
                *x = (*x * limit) / dist;
304
                *x = (s32)(((double)(*x) * limit) / dist);
309
                *y = (*y * limit) / dist;
305
                *y = (s32)(((double)(*y) * limit) / dist);
310
        }
306
        }
Line 311... Line 307...
311
}
307
}
312
 
308