Chromium Code Reviews| Index: Source/core/svg/SVGLength.cpp |
| diff --git a/Source/core/svg/SVGLength.cpp b/Source/core/svg/SVGLength.cpp |
| index 3c928704dc21593d6dd2cd672f1f622760e1dea7..10db3a15c50f7b27e3198469354636cfb07e5e0e 100644 |
| --- a/Source/core/svg/SVGLength.cpp |
| +++ b/Source/core/svg/SVGLength.cpp |
| @@ -186,12 +186,33 @@ void SVGLength::setUnitType(SVGLengthType type) |
| float SVGLength::valueAsPercentage() const |
| { |
| // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed |
|
Stephen Chennney
2015/01/22 21:57:25
This comment seems wrong now.
Daniel Bratell
2015/01/23 08:49:40
It is still correct since it refers to the interna
|
| - if (m_unitType == LengthTypePercentage) |
| + if (m_unitType == LengthTypePercentage) { |
| + // Note: This division is a source of floating point inaccuracy. |
| return m_valueInSpecifiedUnits / 100; |
| + } |
| return m_valueInSpecifiedUnits; |
| } |
| +float SVGLength::valueAsPercentage100() const |
| +{ |
| + // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed |
| + if (m_unitType == LengthTypePercentage) |
| + return m_valueInSpecifiedUnits; |
| + |
| + return m_valueInSpecifiedUnits * 100; |
| +} |
| + |
| +float SVGLength::scaleByPercentage(float input) const |
| +{ |
| + float result = input * m_valueInSpecifiedUnits; |
| + if (m_unitType == LengthTypePercentage) { |
| + // Delaying division by 100 as long as possible since it introduces floating point errors. |
| + result = result / 100; |
| + } |
| + return result; |
| +} |
| + |
| template<typename CharType> |
| static bool parseValueInternal(const String& string, float& convertedNumber, SVGLengthType& type) |
| { |
| @@ -403,8 +424,8 @@ PassRefPtrWillBeRawPtr<SVGLength> SVGLength::blend(PassRefPtrWillBeRawPtr<SVGLen |
| RefPtrWillBeRawPtr<SVGLength> length = create(); |
| if (fromType == LengthTypePercentage || toType == LengthTypePercentage) { |
| - float fromPercent = from->valueAsPercentage() * 100; |
| - float toPercent = valueAsPercentage() * 100; |
| + float fromPercent = from->valueAsPercentage100(); |
| + float toPercent = valueAsPercentage100(); |
| length->newValueSpecifiedUnits(LengthTypePercentage, blink::blend(fromPercent, toPercent, progress)); |
| return length; |
| } |