1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=5de2de0f00354e59074a9bb1a42d5a63
5cb93a386Sopenharmony_ciREG_FIDDLE(Miter_Limit, 384, 170, false, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    SkPoint pts[] = {{ 10, 50 }, { 110, 80 }, { 10, 110 }};
8cb93a386Sopenharmony_ci    SkVector v[] = { pts[0] - pts[1], pts[2] - pts[1] };
9cb93a386Sopenharmony_ci    SkScalar angle1 = SkScalarATan2(v[0].fY, v[0].fX);
10cb93a386Sopenharmony_ci    SkScalar angle2 = SkScalarATan2(v[1].fY, v[1].fX);
11cb93a386Sopenharmony_ci    const SkScalar strokeWidth = 20;
12cb93a386Sopenharmony_ci    SkScalar miterLimit = 1 / SkScalarSin((angle2 - angle1) / 2);
13cb93a386Sopenharmony_ci    SkScalar miterLength = strokeWidth * miterLimit;
14cb93a386Sopenharmony_ci    SkPath path;
15cb93a386Sopenharmony_ci    path.moveTo(pts[0]);
16cb93a386Sopenharmony_ci    path.lineTo(pts[1]);
17cb93a386Sopenharmony_ci    path.lineTo(pts[2]);
18cb93a386Sopenharmony_ci    SkPaint paint;  // set to default kMiter_Join
19cb93a386Sopenharmony_ci    paint.setAntiAlias(true);
20cb93a386Sopenharmony_ci    paint.setStyle(SkPaint::kStroke_Style);
21cb93a386Sopenharmony_ci    paint.setStrokeMiter(miterLimit);
22cb93a386Sopenharmony_ci    paint.setStrokeWidth(strokeWidth);
23cb93a386Sopenharmony_ci    canvas->drawPath(path, paint);
24cb93a386Sopenharmony_ci    paint.setStrokeWidth(1);
25cb93a386Sopenharmony_ci    canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
26cb93a386Sopenharmony_ci                     pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
27cb93a386Sopenharmony_ci    canvas->translate(200, 0);
28cb93a386Sopenharmony_ci    miterLimit *= 0.99f;
29cb93a386Sopenharmony_ci    paint.setStrokeMiter(miterLimit);
30cb93a386Sopenharmony_ci    paint.setStrokeWidth(strokeWidth);
31cb93a386Sopenharmony_ci    canvas->drawPath(path, paint);
32cb93a386Sopenharmony_ci    paint.setStrokeWidth(1);
33cb93a386Sopenharmony_ci    canvas->drawLine(pts[1].fX - miterLength / 2, pts[1].fY + 50,
34cb93a386Sopenharmony_ci                     pts[1].fX + miterLength / 2, pts[1].fY + 50, paint);
35cb93a386Sopenharmony_ci}
36cb93a386Sopenharmony_ci}  // END FIDDLE
37