Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 5 of file Miter_Limit.cpp.

5 {
6void draw(SkCanvas* canvas) {
7 SkPoint pts[] = {{ 10, 50 }, { 110, 80 }, { 10, 110 }};
8 SkVector v[] = { pts[0] - pts[1], pts[2] - pts[1] };
9 SkScalar angle1 = SkScalarATan2(v[0].fY, v[0].fX);
10 SkScalar angle2 = SkScalarATan2(v[1].fY, v[1].fX);
11 const SkScalar strokeWidth = 20;
12 SkScalar miterLimit = 1 / SkScalarSin((angle2 - angle1) / 2);
13 SkScalar miterLength = strokeWidth * miterLimit;
15 path.moveTo(pts[0]);
16 path.lineTo(pts[1]);
17 path.lineTo(pts[2]);
18 SkPaint paint; // set to default kMiter_Join
19 paint.setAntiAlias(true);
21 paint.setStrokeMiter(miterLimit);
22 paint.setStrokeWidth(strokeWidth);
23 canvas->drawPath(path, paint);
24 paint.setStrokeWidth(1);
25 canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
26 pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
27 canvas->translate(200, 0);
28 miterLimit *= 0.99f;
29 paint.setStrokeMiter(miterLimit);
30 paint.setStrokeWidth(strokeWidth);
31 canvas->drawPath(path, paint);
32 paint.setStrokeWidth(1);
33 canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
34 pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
35}
36} // 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)
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
void drawPath(const SkPath &path, const SkPaint &paint)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
const Paint & paint
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