Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(940)

Unified Diff: Source/core/svg/SVGLength.cpp

Issue 861213003: Fix problems with flakes in SVG LayoutTests by reordering arithmetic. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rephrased comment. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/svg/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/svg/SVGLength.cpp
diff --git a/Source/core/svg/SVGLength.cpp b/Source/core/svg/SVGLength.cpp
index 3c928704dc21593d6dd2cd672f1f622760e1dea7..931e3d398293a5ff8f9bc9087ad0b264a9a58ac5 100644
--- a/Source/core/svg/SVGLength.cpp
+++ b/Source/core/svg/SVGLength.cpp
@@ -166,7 +166,7 @@ float SVGLength::value(const SVGLengthContext& context, ExceptionState& es) cons
void SVGLength::setValue(float value, const SVGLengthContext& context, ExceptionState& es)
{
- // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
+ // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed.
if (m_unitType == LengthTypePercentage)
value = value / 100;
@@ -185,13 +185,34 @@ void SVGLength::setUnitType(SVGLengthType type)
float SVGLength::valueAsPercentage() const
{
- // 100% = 100.0 instead of 1.0 for historical reasons, this could eventually be changed
- if (m_unitType == LengthTypePercentage)
+ // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but could eventually be changed.
+ 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
+{
+ // LengthTypePercentage is represented with 100% = 100.0. Good for accuracy but 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;
}
« no previous file with comments | « Source/core/svg/SVGLength.h ('k') | Source/core/svg/SVGLengthContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698