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

Unified Diff: Source/core/rendering/svg/SVGRenderTreeAsText.cpp

Issue 856533002: Fix problems with flakes in SVG LayoutTests. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased to newer master. 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/svg/SVGRenderTreeAsText.cpp
diff --git a/Source/core/rendering/svg/SVGRenderTreeAsText.cpp b/Source/core/rendering/svg/SVGRenderTreeAsText.cpp
index 4de4347697837e04be12955a48a5d7dfc22ba71b..01104f273a4a743399b48c2a18bddf8cf8012925 100644
--- a/Source/core/rendering/svg/SVGRenderTreeAsText.cpp
+++ b/Source/core/rendering/svg/SVGRenderTreeAsText.cpp
@@ -327,9 +327,35 @@ static void writeStyle(TextStream& ts, const RenderObject& object)
writeIfNotEmpty(ts, "end marker", svgStyle.markerEndResource());
}
+static float snapToCloseInteger(float value)
+{
+ // Due to floating point arithmetic uncertainties we may sometimes end up at
+ // something like 4.99999952 when pure arithmetic would have given 5.
+ // To give predictable results in debug ouput, snap numbers very close to
+ // integers to integers. This matters because sometimes numbers are truncated
+ // rather than rounded before being viewed as integers.
+ const double epsilon = 0.00001;
+ if (fabs(value - round(value)) < epsilon)
+ return static_cast<float>(round(value));
+ return value;
+}
+
+static FloatPoint snapToCloseInteger(FloatPoint point)
+{
+ return FloatPoint(snapToCloseInteger(point.x()), snapToCloseInteger(point.y()));
+}
+
+static FloatRect snapToCloseInteger(FloatRect rect)
+{
+ FloatPoint bottomRight = snapToCloseInteger(rect.maxXMaxYCorner());
+ FloatPoint topLeft = snapToCloseInteger(rect.minXMinYCorner());
+ return FloatRect(topLeft, bottomRight - topLeft);
+}
+
static TextStream& writePositionAndStyle(TextStream& ts, const RenderObject& object)
{
- ts << " " << enclosingIntRect(const_cast<RenderObject&>(object).absoluteClippedOverflowRect());
+ FloatRect rect = snapToCloseInteger(object.absoluteClippedOverflowRect());
Daniel Bratell 2015/01/22 09:21:40 This is too late. It's in the conversion from floa
+ ts << " " << enclosingIntRect(rect);
writeStyle(ts, object);
return ts;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698