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 /src/core | |
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 'src/core')
-rw-r--r-- | src/core/SkPath.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp index 3cbc76ad8f..4c49e6bc12 100644 --- a/src/core/SkPath.cpp +++ b/src/core/SkPath.cpp @@ -1290,6 +1290,25 @@ void SkPath::arcTo(const SkRect& oval, SkScalar startAngle, SkScalar sweepAngle, angles_to_unit_vectors(startAngle, sweepAngle, &startV, &stopV, &dir); SkPoint singlePt; + + // At this point, we know that the arc is not a lone point, but startV == stopV + // indicates that the sweepAngle is too small such that angles_to_unit_vectors + // cannot handle it. + if (startV == stopV) { + SkScalar endAngle = SkDegreesToRadians(startAngle + sweepAngle); + SkScalar radiusX = oval.width() / 2; + SkScalar radiusY = oval.height() / 2; + // We cannot use SkScalarSinCos function in the next line because + // SkScalarSinCos has a threshold *SkScalarNearlyZero*. When sin(startAngle) + // is 0 and sweepAngle is very small and radius is huge, the expected + // behavior here is to draw a line. But calling SkScalarSinCos will + // make sin(endAngle) to be 0 which will then draw a dot. + singlePt.set(oval.centerX() + radiusX * sk_float_cos(endAngle), + oval.centerY() + radiusY * sk_float_sin(endAngle)); + forceMoveTo ? this->moveTo(singlePt) : this->lineTo(singlePt); + return; + } + SkConic conics[SkConic::kMaxConicsForArc]; int count = build_arc_conics(oval, startV, stopV, dir, conics, &singlePt); if (count) { |