Flutter Engine
The Flutter Engine
Functions
Miter_Limit.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (Miter_Limit, 384, 170, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Miter_Limit  ,
384  ,
170  ,
false  ,
 
)

Definition at line 4 of file Miter_Limit.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 SkPoint pts[] = {{ 10, 50 }, { 110, 80 }, { 10, 110 }};
7 SkVector v[] = { pts[0] - pts[1], pts[2] - pts[1] };
8 SkScalar angle1 = SkScalarATan2(v[0].fY, v[0].fX);
9 SkScalar angle2 = SkScalarATan2(v[1].fY, v[1].fX);
10 const SkScalar strokeWidth = 20;
11 SkScalar miterLimit = 1 / SkScalarSin((angle2 - angle1) / 2);
12 SkScalar miterLength = strokeWidth * miterLimit;
14 path.moveTo(pts[0]);
15 path.lineTo(pts[1]);
16 path.lineTo(pts[2]);
17 SkPaint paint; // set to default kMiter_Join
18 paint.setAntiAlias(true);
20 paint.setStrokeMiter(miterLimit);
21 paint.setStrokeWidth(strokeWidth);
22 canvas->drawPath(path, paint);
23 paint.setStrokeWidth(1);
24 canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
25 pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
26 canvas->translate(200, 0);
27 miterLimit *= 0.99f;
28 paint.setStrokeMiter(miterLimit);
29 paint.setStrokeWidth(strokeWidth);
30 canvas->drawPath(path, paint);
31 paint.setStrokeWidth(1);
32 canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
33 pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
34}
35} // END FIDDLE
static const int strokeWidth
Definition: BlurTest.cpp:60
#define SkScalarATan2(y, x)
Definition: SkScalar.h:50
#define SkScalarSin(radians)
Definition: SkScalar.h:45
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
Definition: SkCanvas.cpp:2700
void drawPath(const SkPath &path, const SkPaint &paint)
Definition: SkCanvas.cpp:1747
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
Definition: SkPath.h:59
const Paint & paint
Definition: color_source.cc:38
float SkScalar
Definition: extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57