Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
SkCubicMap Class Reference

#include <SkCubicMap.h>

Public Member Functions

 SkCubicMap (SkPoint p1, SkPoint p2)
 
float computeYFromX (float x) const
 
SkPoint computeFromT (float t) const
 

Static Public Member Functions

static bool IsLinear (SkPoint p1, SkPoint p2)
 

Detailed Description

Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic curve inside the unit square.

pt[0] is implicitly { 0, 0 } pt[3] is implicitly { 1, 1 } pts[1,2].X are inside the unit [0..1]

Definition at line 23 of file SkCubicMap.h.

Constructor & Destructor Documentation

◆ SkCubicMap()

SkCubicMap::SkCubicMap ( SkPoint  p1,
SkPoint  p2 
)

Definition at line 88 of file SkCubicMap.cpp.

88 {
89 // Clamp X values only (we allow Ys outside [0..1]).
90 p1.fX = std::min(std::max(p1.fX, 0.0f), 1.0f);
91 p2.fX = std::min(std::max(p2.fX, 0.0f), 1.0f);
92
93 auto s1 = skvx::float2::Load(&p1) * 3;
94 auto s2 = skvx::float2::Load(&p2) * 3;
95
96 (1 + s1 - s2).store(&fCoeff[0]);
97 (s2 - s1 - s1).store(&fCoeff[1]);
98 s1.store(&fCoeff[2]);
99
100 fType = kSolver_Type;
101 if (SkScalarNearlyEqual(p1.fX, p1.fY) && SkScalarNearlyEqual(p2.fX, p2.fY)) {
102 fType = kLine_Type;
103 } else if (coeff_nearly_zero(fCoeff[1].fX) && coeff_nearly_zero(fCoeff[2].fX)) {
104 fType = kCubeRoot_Type;
105 }
106}
static bool coeff_nearly_zero(float delta)
Definition: SkCubicMap.cpp:84
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
SI void store(P *ptr, const T &val)
static float max(float r, float g, float b)
Definition: hsl.cpp:49
static float min(float r, float g, float b)
Definition: hsl.cpp:48
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
static SKVX_ALWAYS_INLINE Vec Load(const void *ptr)
Definition: SkVx.h:109

Member Function Documentation

◆ computeFromT()

SkPoint SkCubicMap::computeFromT ( float  t) const

Definition at line 108 of file SkCubicMap.cpp.

108 {
109 auto a = skvx::float2::Load(&fCoeff[0]);
110 auto b = skvx::float2::Load(&fCoeff[1]);
111 auto c = skvx::float2::Load(&fCoeff[2]);
112
114 (((a * t + b) * t + c) * t).store(&result);
115 return result;
116}
static bool b
struct MyStruct a[10]
GAsyncResult * result

◆ computeYFromX()

float SkCubicMap::computeYFromX ( float  x) const

Definition at line 61 of file SkCubicMap.cpp.

61 {
62 x = SkTPin(x, 0.0f, 1.0f);
63
64 if (nearly_zero(x) || nearly_zero(1 - x)) {
65 return x;
66 }
67 if (fType == kLine_Type) {
68 return x;
69 }
70 float t;
71 if (fType == kCubeRoot_Type) {
72 t = std::pow(x / fCoeff[0].fX, 1.0f / 3);
73 } else {
74 t = compute_t_from_x(fCoeff[0].fX, fCoeff[1].fX, fCoeff[2].fX, x);
75 }
76 float a = fCoeff[0].fY;
77 float b = fCoeff[1].fY;
78 float c = fCoeff[2].fY;
79 float y = ((a * t + b) * t + c) * t;
80
81 return y;
82}
static bool nearly_zero(SkScalar x)
Definition: SkCubicMap.cpp:52
static float compute_t_from_x(float A, float B, float C, float x)
Definition: SkCubicMap.cpp:57
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
double y
double x

◆ IsLinear()

static bool SkCubicMap::IsLinear ( SkPoint  p1,
SkPoint  p2 
)
inlinestatic

Definition at line 27 of file SkCubicMap.h.

27 {
28 return SkScalarNearlyEqual(p1.fX, p1.fY) && SkScalarNearlyEqual(p2.fX, p2.fY);
29 }

The documentation for this class was generated from the following files: