Bug 1246893 - Fix boundary values of nsSMILKeySpline::GetTForX. r?birtles draft
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Tue, 16 Feb 2016 13:59:36 +0900
changeset 331156 008f24e2c0f61761b9ef726097253d4d56a55e23
parent 330984 ea39d4a6232c278dd8d805608a07cf9f4cc4c76b
child 514313 ee92a2545e2270f07eafc8290bb944396406da6e
push id10911
push userhiikezoe@mozilla-japan.org
push dateTue, 16 Feb 2016 05:00:08 +0000
reviewersbirtles
bugs1246893
milestone47.0a1
Bug 1246893 - Fix boundary values of nsSMILKeySpline::GetTForX. r?birtles MozReview-Commit-ID: 9KX0aLPRP31
dom/smil/nsSMILKeySpline.cpp
--- a/dom/smil/nsSMILKeySpline.cpp
+++ b/dom/smil/nsSMILKeySpline.cpp
@@ -71,16 +71,20 @@ nsSMILKeySpline::GetSlope(double aT,
                           double aA2)
 {
   return 3.0 * A(aA1, aA2)*aT*aT + 2.0 * B(aA1, aA2) * aT + C(aA1);
 }
 
 double
 nsSMILKeySpline::GetTForX(double aX) const
 {
+  // Early return when aX == 1.0 to avoid floating-point inaccuracies.
+  if (aX == 1.0) {
+    return 1.0;
+  }
   // Find interval where t lies
   double intervalStart = 0.0;
   const double* currentSample = &mSampleValues[1];
   const double* const lastSample = &mSampleValues[kSplineTableSize - 1];
   for (; currentSample != lastSample && *currentSample <= aX;
         ++currentSample) {
     intervalStart += kSampleStepSize;
   }