diff options
author | xidachen <xidachen@chromium.org> | 2016-10-06 05:42:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-10-06 05:42:23 -0700 |
commit | 6069ddabd8385ff838236dc25d7354e71649c9f3 (patch) | |
tree | 422ce8471b0ace1ec0a4dd9cc078446296350cb5 /gm/addarc.cpp | |
parent | d207884bf5d163057529c48342b9d4a8b994b982 (diff) |
Fix SkPath::arcTo when sweepAngle is tiny and radius is big
In this function, it first check whether this arc is a lone point
or not. If not, it converts angles to unit vectors. The problem
here is that when the radius is huge and the sweepAngle is small,
the function angles_to_unit_vectors() could return a startV ==stopV.
When that happens, it will draw a dot at the point that corresponding
to the startAngle. This CL adds a special branch for this case, and
draw a connecting line between the points at startAngle and endAngle.
BUG=640031, skia:5807
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2388833002
Review-Url: https://codereview.chromium.org/2388833002
Diffstat (limited to 'gm/addarc.cpp')
-rw-r--r-- | gm/addarc.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/gm/addarc.cpp b/gm/addarc.cpp index 0a1876b2dc..ff67af22fc 100644 --- a/gm/addarc.cpp +++ b/gm/addarc.cpp @@ -219,10 +219,13 @@ DEF_GM( return new FillCircleGM; ) ////////////////////// static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, SkScalar start, - SkScalar end, bool ccw) { + SkScalar end, bool ccw, bool callArcTo) { SkRect bounds = { x - r, y - r, x + r, y + r }; SkScalar sweep = ccw ? end - start : start - end; - path->arcTo(bounds, start, sweep, false); + if (callArcTo) + path->arcTo(bounds, start, sweep, false); + else + path->addArc(bounds, start, sweep); } // Lifted from canvas-arc-circumference-fill-diffs.html @@ -269,7 +272,7 @@ protected: SkPath path; path.moveTo(0, 2); html_canvas_arc(&path, 18, 15, 10, startAngle, startAngle + (sweepAngles[j] * sign), - anticlockwise); + anticlockwise, true); path.lineTo(0, 28); canvas->drawPath(path, paint); canvas->translate(30, 0); @@ -283,3 +286,37 @@ private: typedef skiagm::GM INHERITED; }; DEF_GM( return new ManyArcsGM; ) + +// Lifted from https://bugs.chromium.org/p/chromium/issues/detail?id=640031 +class TinyAngleBigRadiusArcsGM : public skiagm::GM { +public: + TinyAngleBigRadiusArcsGM() {} + +protected: + SkString onShortName() override { return SkString("tinyanglearcs"); } + + SkISize onISize() override { return SkISize::Make(620, 330); } + + void onDraw(SkCanvas* canvas) override { + SkPaint paint; + paint.setAntiAlias(true); + paint.setStyle(SkPaint::kStroke_Style); + + canvas->translate(50, 50); + + SkPath path; + path.moveTo(50, 20); + path.lineTo(50, 0); + // A combination of tiny sweepAngle + large radius, we should draw a line. + html_canvas_arc(&path, 50, 100000, 100000, 270, 270.0f - 0.00572957795f, + false, true); + path.lineTo(60, 20); + html_canvas_arc(&path, 50, 100000, 99980, 270.0f - 0.00572957795f, 270, + false, false); + canvas->drawPath(path, paint); + } + +private: + typedef skiagm::GM INHERITED; +}; +DEF_GM( return new TinyAngleBigRadiusArcsGM; ) |