avoid divided by zero error

The old code only checks touch->max_x > touch->min_x but not touch->max_x == touch->min_x. Thus may lead to divided by zero error.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@1782 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
chaos.proton@gmail.com 2011-11-02 08:58:34 +00:00
parent 9de3512c8a
commit e803640027
1 changed files with 2 additions and 2 deletions

View File

@ -158,7 +158,7 @@ static void rtgui_touch_calculate()
{
touch->x = (touch->x - touch->min_x) * X_WIDTH/(touch->max_x - touch->min_x);
}
else
else if (touch->max_x < touch->min_x)
{
touch->x = (touch->min_x - touch->x) * X_WIDTH/(touch->min_x - touch->max_x);
}
@ -167,7 +167,7 @@ static void rtgui_touch_calculate()
{
touch->y = (touch->y - touch->min_y) * Y_WIDTH /(touch->max_y - touch->min_y);
}
else
else if (touch->max_y < touch->min_y)
{
touch->y = (touch->min_y - touch->y) * Y_WIDTH /(touch->min_y - touch->max_y);
}