|
2 | 2 | * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
|
3 | 3 | * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
|
4 | 4 | * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
|
5 |
| - * Copyright (C) 2008-2021 Apple Inc. All rights reserved. |
| 5 | + * Copyright (C) 2008-2023 Apple Inc. All rights reserved. |
6 | 6 | * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au>
|
7 | 7 | * Copyright (C) Research In Motion Limited 2010. All rights reserved.
|
8 | 8 | * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
|
| 9 | + * Copyright (C) 2013 Google Inc. All rights reserved. |
9 | 10 | *
|
10 | 11 | * This library is free software; you can redistribute it and/or
|
11 | 12 | * modify it under the terms of the GNU Library General Public
|
@@ -403,10 +404,12 @@ unsigned SVGAnimationElement::calculateKeyTimesIndex(float percent) const
|
403 | 404 | const auto& keyTimes = this->keyTimes();
|
404 | 405 | unsigned index;
|
405 | 406 | unsigned keyTimesCount = keyTimes.size();
|
406 |
| - // Compare index + 1 to keyTimesCount because the last keyTimes entry is |
407 |
| - // required to be 1, and percent can never exceed 1; i.e., the second last |
408 |
| - // keyTimes entry defines the beginning of the final interval |
409 |
| - for (index = 1; index + 1 < keyTimesCount; ++index) { |
| 407 | + // For linear and spline animations, the last value must be '1'. In those |
| 408 | + // cases we don't need to consider the last value, since |percent| is never |
| 409 | + // greater than one. |
| 410 | + if (keyTimesCount && calcMode() != CalcMode::Discrete) |
| 411 | + --keyTimesCount; |
| 412 | + for (index = 1; index < keyTimesCount; ++index) { |
410 | 413 | if (keyTimes[index] > percent)
|
411 | 414 | break;
|
412 | 415 | }
|
@@ -437,14 +440,15 @@ float SVGAnimationElement::calculatePercentFromKeyPoints(float percent) const
|
437 | 440 | return m_keyPoints[m_keyPoints.size() - 1];
|
438 | 441 |
|
439 | 442 | unsigned index = calculateKeyTimesIndex(percent);
|
440 |
| - float fromPercent = keyTimes[index]; |
441 |
| - float toPercent = keyTimes[index + 1]; |
442 | 443 | float fromKeyPoint = m_keyPoints[index];
|
443 |
| - float toKeyPoint = m_keyPoints[index + 1]; |
444 | 444 |
|
445 | 445 | if (calcMode() == CalcMode::Discrete)
|
446 | 446 | return fromKeyPoint;
|
447 | 447 |
|
| 448 | + ASSERT(index + 1 < keyTimes.size()); |
| 449 | + float fromPercent = keyTimes[index]; |
| 450 | + float toPercent = keyTimes[index + 1]; |
| 451 | + float toKeyPoint = m_keyPoints[index + 1]; |
448 | 452 | float keyPointPercent = (percent - fromPercent) / (toPercent - fromPercent);
|
449 | 453 |
|
450 | 454 | if (calcMode() == CalcMode::Spline) {
|
|
0 commit comments