Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(114)

Unified Diff: src/core/SkPath.cpp

Issue 2388833002: Fix SkPath::arcTo when sweepAngle is tiny and radius is big (Closed)
Patch Set: fix compile error on win Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gm/addarc.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkPath.cpp
diff --git a/src/core/SkPath.cpp b/src/core/SkPath.cpp
index 3cbc76ad8f1dac52e61410f5b4a56534d79cd4ca..4c49e6bc126e6871cf102dc64b75120173951368 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) {
« no previous file with comments | « gm/addarc.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698