summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-30 03:36:29 (GMT)
committerLeonardo Sobral Cunha <leo.cunha@nokia.com>2010-04-30 04:11:02 (GMT)
commit94853c6310bb0f9f3ca08e3c1fa0976ec3d8d285 (patch)
treeeadb1a19695e07885b78154b60b619e62db61365 /src
parent4cd5bcf2aa093fdc3861cd4e91aa7850f38de158 (diff)
downloadQt-94853c6310bb0f9f3ca08e3c1fa0976ec3d8d285.zip
Qt-94853c6310bb0f9f3ca08e3c1fa0976ec3d8d285.tar.gz
Qt-94853c6310bb0f9f3ca08e3c1fa0976ec3d8d285.tar.bz2
Avoid divisions by zero in qdeclarativetimeline
Reviewed-by: Martin Jones
Diffstat (limited to 'src')
-rw-r--r--src/declarative/util/qdeclarativetimeline.cpp13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/declarative/util/qdeclarativetimeline.cpp b/src/declarative/util/qdeclarativetimeline.cpp
index 656c62b..291b2f3 100644
--- a/src/declarative/util/qdeclarativetimeline.cpp
+++ b/src/declarative/util/qdeclarativetimeline.cpp
@@ -387,7 +387,10 @@ void QDeclarativeTimeLine::set(QDeclarativeTimeLineValue &timeLineValue, qreal v
*/
int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal velocity, qreal acceleration)
{
- if ((velocity > 0.0f) == (acceleration > 0.0f))
+ if (acceleration == 0.0f)
+ return -1;
+
+ if ((velocity > 0.0f) == (acceleration > 0.0f))
acceleration = acceleration * -1.0f;
int time = static_cast<int>(-1000 * velocity / acceleration);
@@ -410,13 +413,16 @@ int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal
*/
int QDeclarativeTimeLine::accel(QDeclarativeTimeLineValue &timeLineValue, qreal velocity, qreal acceleration, qreal maxDistance)
{
- Q_ASSERT(acceleration >= 0.0f && maxDistance >= 0.0f);
+ if (maxDistance == 0.0f || acceleration == 0.0f)
+ return -1;
+
+ Q_ASSERT(acceleration > 0.0f && maxDistance > 0.0f);
qreal maxAccel = (velocity * velocity) / (2.0f * maxDistance);
if (maxAccel > acceleration)
acceleration = maxAccel;
- if ((velocity > 0.0f) == (acceleration > 0.0f))
+ if ((velocity > 0.0f) == (acceleration > 0.0f))
acceleration = acceleration * -1.0f;
int time = static_cast<int>(-1000 * velocity / acceleration);
@@ -438,6 +444,7 @@ int QDeclarativeTimeLine::accelDistance(QDeclarativeTimeLineValue &timeLineValue
{
if (distance == 0.0f || velocity == 0.0f)
return -1;
+
Q_ASSERT((distance >= 0.0f) == (velocity >= 0.0f));
int time = static_cast<int>(1000 * (2.0f * distance) / velocity);