Chromium Code Reviews| 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; |
| } |