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

Unified Diff: gm/addarc.cpp

Issue 869843006: more gms for conics (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | samplecode/SampleArc.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gm/addarc.cpp
diff --git a/gm/addarc.cpp b/gm/addarc.cpp
index e6fad25772db27b6a8ca642b3885ca2c14a12981..aef7916da5318001e759e1159d518925c63153f9 100644
--- a/gm/addarc.cpp
+++ b/gm/addarc.cpp
@@ -8,6 +8,7 @@
#include "gm.h"
#include "SkAnimTimer.h"
#include "SkCanvas.h"
+#include "SkPathMeasure.h"
#include "SkRandom.h"
class AddArcGM : public skiagm::GM {
@@ -60,3 +61,53 @@ private:
typedef skiagm::GM INHERITED;
};
DEF_GM( return new AddArcGM; )
+
+///////////////////////////////////////////////////
+
+#define R 400
+
+class AddArcMeasGM : public skiagm::GM {
+public:
+ AddArcMeasGM() {}
+
+protected:
+ SkString onShortName() SK_OVERRIDE { return SkString("addarc_meas"); }
+
+ SkISize onISize() SK_OVERRIDE { return SkISize::Make(2*R + 40, 2*R + 40); }
+
+ void onDraw(SkCanvas* canvas) SK_OVERRIDE {
+ canvas->translate(R + 20, R + 20);
+
+ SkPaint paint;
+ paint.setAntiAlias(true);
+ paint.setStyle(SkPaint::kStroke_Style);
+
+ SkPaint measPaint;
+ measPaint.setAntiAlias(true);
+ measPaint.setColor(SK_ColorRED);
+
+ const SkRect oval = SkRect::MakeLTRB(-R, -R, R, R);
+ canvas->drawOval(oval, paint);
+
+ for (SkScalar deg = 0; deg < 360; deg += 10) {
+ const SkScalar rad = SkDegreesToRadians(deg);
+ SkScalar rx = SkScalarCos(rad) * R;
+ SkScalar ry = SkScalarSin(rad) * R;
+
+ canvas->drawLine(0, 0, rx, ry, paint);
+
+ SkPath path;
+ path.addArc(oval, 0, deg);
+ SkPathMeasure meas(path, false);
+ SkScalar arcLen = rad * R;
+ SkPoint pos;
+ if (meas.getPosTan(arcLen, &pos, NULL)) {
+ canvas->drawLine(0, 0, pos.x(), pos.y(), measPaint);
+ }
+ }
+ }
+
+private:
+ typedef skiagm::GM INHERITED;
+};
+DEF_GM( return new AddArcMeasGM; )
« no previous file with comments | « no previous file | samplecode/SampleArc.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698