Flutter Engine
The Flutter Engine
Functions
SkCubicMap.cpp File Reference
#include "include/core/SkCubicMap.h"
#include "include/private/base/SkTPin.h"
#include "src/base/SkVx.h"
#include <algorithm>
#include <cmath>

Go to the source code of this file.

Functions

static float eval_poly (float t, float b)
 
template<typename... Rest>
static float eval_poly (float t, float m, float b, Rest... rest)
 
static float cubic_solver (float A, float B, float C, float D)
 
static bool nearly_zero (SkScalar x)
 
static float compute_t_from_x (float A, float B, float C, float x)
 
static bool coeff_nearly_zero (float delta)
 

Function Documentation

◆ coeff_nearly_zero()

static bool coeff_nearly_zero ( float  delta)
inlinestatic

Definition at line 84 of file SkCubicMap.cpp.

84 {
85 return std::fabs(delta) <= 0.0000001f;
86}

◆ compute_t_from_x()

static float compute_t_from_x ( float  A,
float  B,
float  C,
float  x 
)
static

Definition at line 57 of file SkCubicMap.cpp.

57 {
58 return cubic_solver(A, B, C, -x);
59}
static float cubic_solver(float A, float B, float C, float D)
Definition: SkCubicMap.cpp:23
double x

◆ cubic_solver()

static float cubic_solver ( float  A,
float  B,
float  C,
float  D 
)
static

Definition at line 23 of file SkCubicMap.cpp.

23 {
24#ifdef SK_DEBUG
25 auto valid = [](float t) { return t >= 0 && t <= 1; };
26#endif
27
28 auto guess_nice_cubic_root = [](float a, float b, float c, float d) { return -d; };
29 float t = guess_nice_cubic_root(A, B, C, D);
30
31 int iters = 0;
32 const int MAX_ITERS = 8;
33 for (; iters < MAX_ITERS; ++iters) {
34 SkASSERT(valid(t));
35 float f = eval_poly(t, A, B, C, D); // f = At^3 + Bt^2 + Ct + D
36 if (std::fabs(f) <= 0.00005f) {
37 break;
38 }
39 float fp = eval_poly(t, 3*A, 2*B, C); // f' = 3At^2 + 2Bt + C
40 float fpp = eval_poly(t, 3*A + 3*A, 2*B); // f'' = 6At + 2B
41
42 float numer = 2 * fp * f;
43 float denom = std::fma(2 * fp, fp, -(f * fpp));
44
45 t -= numer / denom;
46 }
47
48 SkASSERT(valid(t));
49 return t;
50}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static float eval_poly(float t, float b)
Definition: SkCubicMap.cpp:16
static skvx::float4 fma(const skvx::float4 &f, float m, const skvx::float4 &a)
Definition: SkGeometry.cpp:597
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
static bool b
struct MyStruct a[10]
const uint32_t fp

◆ eval_poly() [1/2]

static float eval_poly ( float  t,
float  b 
)
static

Definition at line 16 of file SkCubicMap.cpp.

16{ return b; }

◆ eval_poly() [2/2]

template<typename... Rest>
static float eval_poly ( float  t,
float  m,
float  b,
Rest...  rest 
)
static

Definition at line 19 of file SkCubicMap.cpp.

19 {
20 return eval_poly(t, std::fma(m, t, b), rest...);
21}

◆ nearly_zero()

static bool nearly_zero ( SkScalar  x)
inlinestatic

Definition at line 52 of file SkCubicMap.cpp.

52 {
53 SkASSERT(x >= 0);
54 return x <= 0.0000000001f;
55}