Flutter Engine
The Flutter Engine
Classes | Macros | Functions | Variables
FitCubicToCircleSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/private/base/SkTArray.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/viewer/ClickHandlerSlide.h"
#include <tuple>

Go to the source code of this file.

Classes

class  SampleFitCubicToCircle
 
class  SampleFitCubicToCircle::Click
 

Macros

#define M_PI   3.14159265358979323846264338327950288
 
#define M_SQRT2   1.41421356237309504880168872420969808
 

Functions

static float fit_cubic_to_unit_circle (double x0, double y0, double x1, double y1, std::array< double, 4 > *X, std::array< double, 4 > *Y)
 
static double lerp (double x, double y, double T)
 
static std::tuple< double, double, double > eval_cubic (double x[], double T)
 
double find_max_error_T (double cubicX[4], double cubicY[4])
 

Variables

static constexpr int kCenterX = 300
 
static constexpr int kCenterY = 325
 
static constexpr int kRadius = 250
 

Macro Definition Documentation

◆ M_PI

#define M_PI   3.14159265358979323846264338327950288

Definition at line 22 of file FitCubicToCircleSlide.cpp.

◆ M_SQRT2

#define M_SQRT2   1.41421356237309504880168872420969808

Definition at line 26 of file FitCubicToCircleSlide.cpp.

Function Documentation

◆ eval_cubic()

static std::tuple< double, double, double > eval_cubic ( double  x[],
double  T 
)
static

Definition at line 92 of file FitCubicToCircleSlide.cpp.

92 {
93 // Use De Casteljau's algorithm for better accuracy and stability.
94 double ab = lerp(x[0], x[1], T);
95 double bc = lerp(x[1], x[2], T);
96 double cd = lerp(x[2], x[3], T);
97 double abc = lerp(ab, bc, T);
98 double bcd = lerp(bc, cd, T);
99 double abcd = lerp(abc, bcd, T);
100 return {abcd, 3 * (bcd - abc) /*1st derivative.*/, 6 * (cd - 2*bc + ab) /*2nd derivative.*/};
101}
static double lerp(double x, double y, double T)
double x
Definition: ab.py:1
#define T
Definition: precompiler.cc:65

◆ find_max_error_T()

double find_max_error_T ( double  cubicX[4],
double  cubicY[4] 
)

Definition at line 110 of file FitCubicToCircleSlide.cpp.

110 {
111 constexpr static double kInitialT = .25;
112 double T = kInitialT;
113 for (int i = 0; i < 64; ++i) {
114 auto [x, dx, ddx] = eval_cubic(cubicX, T);
115 auto [y, dy, ddy] = eval_cubic(cubicY, T);
116 double dError = 2*(x*dx + y*dy);
117 double ddError = 2*(x*ddx + y*ddy + dx*dx + dy*dy);
118 T -= dError / ddError;
119 }
120 return T;
121}
static std::tuple< double, double, double > eval_cubic(double x[], double T)
double y
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208

◆ fit_cubic_to_unit_circle()

static float fit_cubic_to_unit_circle ( double  x0,
double  y0,
double  x1,
double  y1,
std::array< double, 4 > *  X,
std::array< double, 4 > *  Y 
)
static

Definition at line 76 of file FitCubicToCircleSlide.cpp.

77 {
78 constexpr static double kM = -4.0/3;
79 constexpr static double kA = 4*M_SQRT2/3;
80 double d = x0*x1 + y0*y1;
81 double c = (std::sqrt(1 + d) * kM + kA) / std::sqrt(1 - d);
82 *X = {x0, x0 - y0*c, x1 + y1*c, x1};
83 *Y = {y0, y0 + x0*c, y1 - x1*c, y1};
84 return c;
85}
#define M_SQRT2
static const SkScalar Y
Definition: StrokeBench.cpp:55
static const SkScalar X
Definition: StrokeBench.cpp:54
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
const auto kA
SIN Vec< N, float > sqrt(const Vec< N, float > &x)
Definition: SkVx.h:706

◆ lerp()

static double lerp ( double  x,
double  y,
double  T 
)
static

Definition at line 87 of file FitCubicToCircleSlide.cpp.

87 {
88 return x + T*(y - x);
89}

Variable Documentation

◆ kCenterX

constexpr int kCenterX = 300
staticconstexpr

Definition at line 29 of file FitCubicToCircleSlide.cpp.

◆ kCenterY

constexpr int kCenterY = 325
staticconstexpr

Definition at line 30 of file FitCubicToCircleSlide.cpp.

◆ kRadius

constexpr int kRadius = 250
staticconstexpr

Definition at line 31 of file FitCubicToCircleSlide.cpp.