Index: Source/core/rendering/svg/SVGRenderTreeAsText.cpp |
diff --git a/Source/core/rendering/svg/SVGRenderTreeAsText.cpp b/Source/core/rendering/svg/SVGRenderTreeAsText.cpp |
index d73c4e88b57da044cbccd42178bf4afec8cdde71..7d2d1f51a6f1cced344dbc0789f2f5af20a7c8a1 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()); |
+ ts << " " << enclosingIntRect(rect); |
writeStyle(ts, object); |
return ts; |
} |