Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions
PathSlide.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkFont.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkRegion.h"
#include "include/core/SkShader.h"
#include "include/core/SkTypeface.h"
#include "include/effects/SkGradientShader.h"
#include "include/utils/SkParsePath.h"
#include "src/base/SkTime.h"
#include "src/base/SkUTF.h"
#include "src/core/SkGeometry.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/timer/TimeUtils.h"
#include "tools/viewer/ClickHandlerSlide.h"
#include <stdlib.h>
#include "include/effects/SkCornerPathEffect.h"
#include "src/base/SkRandom.h"

Go to the source code of this file.

Classes

class  PathSlide
 
class  ArcToSlide
 
class  FatStrokeSlide
 
class  CubicCurveSlide
 
class  CubicCurve2Slide
 

Functions

static void test_cubic ()
 
static void test_cubic2 ()
 
static int compute_parallel_to_base (const SkPoint pts[4], SkScalar t[2])
 
static SkPoint lerp (SkPoint a, SkPoint b, float t)
 
static int find_max_deviation_cubic (const SkPoint src[4], SkScalar ts[2])
 

Function Documentation

◆ compute_parallel_to_base()

static int compute_parallel_to_base ( const SkPoint  pts[4],
SkScalar  t[2] 
)
static

Definition at line 421 of file PathSlide.cpp.

421 {
422 // F = At^3 + Bt^2 + Ct + D
423 SkVector A = pts[3] - pts[0] + (pts[1] - pts[2]) * 3.0f;
424 SkVector B = (pts[0] - pts[1] - pts[1] + pts[2]) * 3.0f;
425 SkVector C = (pts[1] - pts[0]) * 3.0f;
426 SkVector DA = pts[3] - pts[0];
427
428 // F' = 3At^2 + 2Bt + C
429 SkScalar a = 3 * A.cross(DA);
430 SkScalar b = 2 * B.cross(DA);
431 SkScalar c = C.cross(DA);
432
433 int n = SkFindUnitQuadRoots(a, b, c, t);
434 SkString str;
435 for (int i = 0; i < n; ++i) {
436 str.appendf(" %g", t[i]);
437 }
438 SkDebugf("roots %s\n", str.c_str());
439 return n;
440}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
int SkFindUnitQuadRoots(SkScalar A, SkScalar B, SkScalar C, SkScalar roots[2])
const char * c_str() const
Definition SkString.h:133
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]

◆ find_max_deviation_cubic()

static int find_max_deviation_cubic ( const SkPoint  src[4],
SkScalar  ts[2] 
)
static

Definition at line 531 of file PathSlide.cpp.

531 {
532 // deviation = F' x (d - a) == 0, solve for t(s)
533 // F = At^3 + Bt^2 + Ct + D
534 // F' = 3At^2 + 2Bt + C
535 // Z = d - a
536 // F' x Z = 3(A x Z)t^2 + 2(B x Z)t + (C x Z)
537 //
538 SkVector A = src[3] + (src[1] - src[2]) * 3 - src[0];
539 SkVector B = (src[2] - src[1] - src[1] + src[0]) * 3;
540 SkVector C = (src[1] - src[0]) * 3;
541 SkVector Z = src[3] - src[0];
542 // now forumlate the quadratic coefficients we need to solve for t : F' x Z
543 return SkFindUnitQuadRoots(3 * A.cross(Z), 2 * B.cross(Z), C.cross(Z), ts);
544}
#define Z

◆ lerp()

static SkPoint lerp ( SkPoint  a,
SkPoint  b,
float  t 
)
static

Definition at line 527 of file PathSlide.cpp.

527 {
528 return a * (1 - t) + b * t;
529}

◆ test_cubic()

static void test_cubic ( )
static

Definition at line 32 of file PathSlide.cpp.

32 {
33 SkPoint src[4] = {
34 { 556.25000f, 523.03003f },
35 { 556.23999f, 522.96002f },
36 { 556.21997f, 522.89001f },
37 { 556.21997f, 522.82001f }
38 };
39 SkPoint dst[11];
40 dst[10].set(42, -42); // one past the end, that we don't clobber these
41 SkScalar tval[] = { 0.33333334f, 0.99999994f };
42
43 SkChopCubicAt(src, dst, tval, 2);
44
45#if 0
46 for (int i = 0; i < 11; i++) {
47 SkDebugf("--- %d [%g %g]\n", i, dst[i].fX, dst[i].fY);
48 }
49#endif
50}
void SkChopCubicAt(const SkPoint src[4], SkPoint dst[7], SkScalar t)
dst
Definition cp.py:12

◆ test_cubic2()

static void test_cubic2 ( )
static

Definition at line 52 of file PathSlide.cpp.

52 {
53 const char* str = "M2242 -590088L-377758 9.94099e+07L-377758 9.94099e+07L2242 -590088Z";
56
57 {
58 SkRect r = path.getBounds();
59 SkIRect ir;
60 r.round(&ir);
61 SkDebugf("[%g %g %g %g] [%x %x %x %x]\n",
64 (uint32_t)ir.fLeft, (uint32_t)ir.fTop, (uint32_t)ir.fRight, (uint32_t)ir.fBottom);
65 }
66
68 bitmap.allocN32Pixels(300, 200);
69
70 SkCanvas canvas(bitmap);
72 paint.setAntiAlias(true);
73 canvas.drawPath(path, paint);
74}
#define SkScalarToDouble(x)
Definition SkScalar.h:63
static bool FromSVGString(const char str[], SkPath *)
const Paint & paint
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
int32_t fBottom
larger y-axis bounds
Definition SkRect.h:36
int32_t fTop
smaller y-axis bounds
Definition SkRect.h:34
int32_t fLeft
smaller x-axis bounds
Definition SkRect.h:33
int32_t fRight
larger x-axis bounds
Definition SkRect.h:35
SkScalar fBottom
larger y-axis bounds
Definition extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition extension.cpp:16
void round(SkIRect *dst) const
Definition SkRect.h:1228
SkScalar fTop
smaller y-axis bounds
Definition extension.cpp:15