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

Side by Side Diff: gm/addarc.cpp

Issue 931183002: add gm for path-arcs, and catch degenerate arc in conic-case (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: The C parser and warnings as just AWESOME Created 5 years, 10 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 | include/core/SkPath.h » ('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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 fRotate = timer.scaled(60, 360); 155 fRotate = timer.scaled(60, 360);
156 return true; 156 return true;
157 } 157 }
158 158
159 private: 159 private:
160 SkScalar fRotate; 160 SkScalar fRotate;
161 161
162 typedef skiagm::GM INHERITED; 162 typedef skiagm::GM INHERITED;
163 }; 163 };
164 DEF_GM( return new StrokeCircleGM; ) 164 DEF_GM( return new StrokeCircleGM; )
165
166 //////////////////////
167
168 static void html_canvas_arc(SkPath* path, SkScalar x, SkScalar y, SkScalar r, Sk Scalar start,
169 SkScalar end, bool ccw) {
170 SkRect bounds = { x - r, y - r, x + r, y + r };
171 SkScalar sweep = ccw ? end - start : start - end;
172 path->arcTo(bounds, start, sweep, false);
173 }
174
175 // Lifted from canvas-arc-circumference-fill-diffs.html
176 class ManyArcsGM : public skiagm::GM {
177 public:
178 ManyArcsGM() {}
179
180 protected:
181 SkString onShortName() SK_OVERRIDE { return SkString("manyarcs"); }
182
183 SkISize onISize() SK_OVERRIDE { return SkISize::Make(620, 330); }
184
185 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
186 SkPaint paint;
187 paint.setAntiAlias(true);
188 paint.setStyle(SkPaint::kStroke_Style);
189
190 canvas->translate(10, 10);
191
192 // 20 angles.
193 SkScalar sweepAngles[] = {
194 -123.7f, -2.3f, -2, -1, -0.3f, -0.000001f, 0, 0.00000 1f, 0.3f, 0.7f,
195 1, 1.3f, 1.5f, 1.7f, 1.99999f, 2, 2.00001f, 2.3f, 4.3 f, 3934723942837.3f
196 };
197 for (size_t i = 0; i < SK_ARRAY_COUNT(sweepAngles); ++i) {
198 sweepAngles[i] *= 180;
199 }
200
201 SkScalar startAngles[] = { -1, -0.5f, 0, 0.5f };
202 for (size_t i = 0; i < SK_ARRAY_COUNT(startAngles); ++i) {
203 startAngles[i] *= 180;
204 }
205
206 bool anticlockwise = false;
207 SkScalar sign = 1;
208 for (size_t i = 0; i < SK_ARRAY_COUNT(startAngles) * 2; ++i) {
209 if (i == SK_ARRAY_COUNT(startAngles)) {
210 anticlockwise = true;
211 sign = -1;
212 }
213 SkScalar startAngle = startAngles[i % SK_ARRAY_COUNT(startAngles)] * sign;
214 canvas->save();
215 for (size_t j = 0; j < SK_ARRAY_COUNT(sweepAngles); ++j) {
216 SkPath path;
217 path.moveTo(0, 2);
218 html_canvas_arc(&path, 18, 15, 10, startAngle, startAngle + (swe epAngles[j] * sign),
219 anticlockwise);
220 path.lineTo(0, 28);
221 canvas->drawPath(path, paint);
222 canvas->translate(30, 0);
223 }
224 canvas->restore();
225 canvas->translate(0, 40);
226 }
227 }
228
229 private:
230 typedef skiagm::GM INHERITED;
231 };
232 DEF_GM( return new ManyArcsGM; )
233
OLDNEW
« no previous file with comments | « no previous file | include/core/SkPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698