Chromium Code Reviews| Index: Source/core/html/canvas/CanvasPathMethods.cpp |
| diff --git a/Source/core/html/canvas/CanvasPathMethods.cpp b/Source/core/html/canvas/CanvasPathMethods.cpp |
| index a2d4e75549062dcf5a1c71f63fc3f2b82847c164..e5b8648b00b5d8045dbbed483b73f5b6f52bb289 100644 |
| --- a/Source/core/html/canvas/CanvasPathMethods.cpp |
| +++ b/Source/core/html/canvas/CanvasPathMethods.cpp |
| @@ -130,37 +130,55 @@ void CanvasPathMethods::arcTo(float x1, float y1, float x2, float y2, float r, E |
| m_path.addArcTo(p1, p2, r); |
| } |
| -void CanvasPathMethods::arc(float x, float y, float r, float sa, float ea, bool anticlockwise, ExceptionCode& ec) |
| +static float adjustEndAngle(float startAngle, float endAngle, bool anticlockwise) |
| +{ |
| + float twoPi = 2 * piFloat; |
| + /* http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-arc |
| + * If the anticlockwise argument is false and endAngle-startAngle is equal to or greater than 2π, or, |
| + * if the anticlockwise argument is true and startAngle-endAngle is equal to or greater than 2π, |
| + * then the arc is the whole circumference of this ellipse. |
| + */ |
| + if (!anticlockwise && endAngle - startAngle >= twoPi) |
| + return startAngle + twoPi + fmodf(endAngle - startAngle, twoPi); |
| + if (anticlockwise && startAngle - endAngle >= twoPi) |
| + return startAngle - twoPi - fmodf(startAngle - endAngle, twoPi); |
| + |
| + /* |
| + * Otherwise, the arc is the path along the circumference of this ellipse from the start point to the end point, |
| + * going anti-clockwise if the anticlockwise argument is true, and clockwise otherwise. |
| + * Since the points are on the ellipse, as opposed to being simply angles from zero, |
| + * the arc can never cover an angle greater than 2π radians. |
| + */ |
| + if (!anticlockwise && startAngle > endAngle) |
| + return startAngle + (twoPi - fmodf(startAngle - endAngle, twoPi)); |
|
alph
2013/07/10 13:06:29
I might think of a rare corner case when e.g.
anti
dshwang
2013/07/10 13:36:42
Wow, you have eagle eye. If you want to follow the
|
| + if (anticlockwise && startAngle < endAngle) |
| + return startAngle - (twoPi - fmodf(endAngle - startAngle, twoPi)); |
| + |
| + return endAngle; |
| +} |
| + |
| +void CanvasPathMethods::arc(float x, float y, float radius, float startAngle, float endAngle, bool anticlockwise, ExceptionCode& ec) |
| { |
| ec = 0; |
| - if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(r) || !std::isfinite(sa) || !std::isfinite(ea)) |
| + if (!std::isfinite(x) || !std::isfinite(y) || !std::isfinite(radius) || !std::isfinite(startAngle) || !std::isfinite(endAngle)) |
| return; |
| - if (r < 0) { |
| + if (radius < 0) { |
| ec = IndexSizeError; |
| return; |
| } |
| - if (!r || sa == ea) { |
| - // The arc is empty but we still need to draw the connecting line. |
| - lineTo(x + r * cosf(sa), y + r * sinf(sa)); |
| - return; |
| - } |
| - |
| if (!isTransformInvertible()) |
| return; |
| - // If 'sa' and 'ea' differ by more than 2Pi, just add a circle starting/ending at 'sa'. |
| - if (anticlockwise && sa - ea >= 2 * piFloat) { |
| - m_path.addArc(FloatPoint(x, y), r, sa, sa - 2 * piFloat, anticlockwise); |
| - return; |
| - } |
| - if (!anticlockwise && ea - sa >= 2 * piFloat) { |
| - m_path.addArc(FloatPoint(x, y), r, sa, sa + 2 * piFloat, anticlockwise); |
| + if (!radius || startAngle == endAngle) { |
| + // The arc is empty but we still need to draw the connecting line. |
| + lineTo(x + radius * cosf(startAngle), y + radius * sinf(startAngle)); |
| return; |
| } |
| - m_path.addArc(FloatPoint(x, y), r, sa, ea, anticlockwise); |
| + float adjustedEndAngle = adjustEndAngle(startAngle, endAngle, anticlockwise); |
| + m_path.addArc(FloatPoint(x, y), radius, startAngle, adjustedEndAngle, anticlockwise); |
| } |
| void CanvasPathMethods::rect(float x, float y, float width, float height) |