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

Side by Side Diff: gm/addarc.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 unified diff | Download patch
« no previous file with comments | « no previous file | src/core/SkPath.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "gm.h" 8 #include "gm.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 private: 212 private:
213 SkScalar fRotate; 213 SkScalar fRotate;
214 214
215 typedef skiagm::GM INHERITED; 215 typedef skiagm::GM INHERITED;
216 }; 216 };
217 DEF_GM( return new FillCircleGM; ) 217 DEF_GM( return new FillCircleGM; )
218 218
219 ////////////////////// 219 //////////////////////
220 220
221 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk Scalar start, 221 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk Scalar start,
222 SkScalar end, bool ccw) { 222 SkScalar end, bool ccw, bool callArcTo) {
223 SkRect bounds = { x - r, y - r, x + r, y + r }; 223 SkRect bounds = { x - r, y - r, x + r, y + r };
224 SkScalar sweep = ccw ? end - start : start - end; 224 SkScalar sweep = ccw ? end - start : start - end;
225 path->arcTo(bounds, start, sweep, false); 225 if (callArcTo)
226 path->arcTo(bounds, start, sweep, false);
227 else
228 path->addArc(bounds, start, sweep);
226 } 229 }
227 230
228 // Lifted from canvas-arc-circumference-fill-diffs.html 231 // Lifted from canvas-arc-circumference-fill-diffs.html
229 class ManyArcsGM : public skiagm::GM { 232 class ManyArcsGM : public skiagm::GM {
230 public: 233 public:
231 ManyArcsGM() {} 234 ManyArcsGM() {}
232 235
233 protected: 236 protected:
234 SkString onShortName() override { return SkString("manyarcs"); } 237 SkString onShortName() override { return SkString("manyarcs"); }
235 238
(...skipping 26 matching lines...) Expand all
262 if (i == SK_ARRAY_COUNT(startAngles)) { 265 if (i == SK_ARRAY_COUNT(startAngles)) {
263 anticlockwise = true; 266 anticlockwise = true;
264 sign = -1; 267 sign = -1;
265 } 268 }
266 SkScalar startAngle = startAngles[i % SK_ARRAY_COUNT(startAngles)] * sign; 269 SkScalar startAngle = startAngles[i % SK_ARRAY_COUNT(startAngles)] * sign;
267 canvas->save(); 270 canvas->save();
268 for (size_t j = 0; j < SK_ARRAY_COUNT(sweepAngles); ++j) { 271 for (size_t j = 0; j < SK_ARRAY_COUNT(sweepAngles); ++j) {
269 SkPath path; 272 SkPath path;
270 path.moveTo(0, 2); 273 path.moveTo(0, 2);
271 html_canvas_arc(&path, 18, 15, 10, startAngle, startAngle + (swe epAngles[j] * sign), 274 html_canvas_arc(&path, 18, 15, 10, startAngle, startAngle + (swe epAngles[j] * sign),
272 anticlockwise); 275 anticlockwise, true);
273 path.lineTo(0, 28); 276 path.lineTo(0, 28);
274 canvas->drawPath(path, paint); 277 canvas->drawPath(path, paint);
275 canvas->translate(30, 0); 278 canvas->translate(30, 0);
276 } 279 }
277 canvas->restore(); 280 canvas->restore();
278 canvas->translate(0, 40); 281 canvas->translate(0, 40);
279 } 282 }
280 } 283 }
281 284
282 private: 285 private:
283 typedef skiagm::GM INHERITED; 286 typedef skiagm::GM INHERITED;
284 }; 287 };
285 DEF_GM( return new ManyArcsGM; ) 288 DEF_GM( return new ManyArcsGM; )
289
290 // Lifted from https://bugs.chromium.org/p/chromium/issues/detail?id=640031
291 class TinyAngleBigRadiusArcsGM : public skiagm::GM {
292 public:
293 TinyAngleBigRadiusArcsGM() {}
294
295 protected:
296 SkString onShortName() override { return SkString("tinyanglearcs"); }
297
298 SkISize onISize() override { return SkISize::Make(620, 330); }
299
300 void onDraw(SkCanvas* canvas) override {
301 SkPaint paint;
302 paint.setAntiAlias(true);
303 paint.setStyle(SkPaint::kStroke_Style);
304
305 canvas->translate(50, 50);
306
307 SkPath path;
308 path.moveTo(50, 20);
309 path.lineTo(50, 0);
310 // A combination of tiny sweepAngle + large radius, we should draw a lin e.
311 html_canvas_arc(&path, 50, 100000, 100000, 270, 270.0f - 0.00572957795f,
312 false, true);
313 path.lineTo(60, 20);
314 html_canvas_arc(&path, 50, 100000, 99980, 270.0f - 0.00572957795f, 270,
315 false, false);
316 canvas->drawPath(path, paint);
317 }
318
319 private:
320 typedef skiagm::GM INHERITED;
321 };
322 DEF_GM( return new TinyAngleBigRadiusArcsGM; )
OLDNEW
« no previous file with comments | « no previous file | src/core/SkPath.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698