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

Public Member Functions

 FwDCubicEvaluator (const SkPoint points[4])
 
void restart (int divisions)
 
bool done () const
 
SkPoint next ()
 
const SkPointgetCtrlPoints () const
 

Detailed Description

Evaluator to sample the values of a cubic bezier using forward differences. Forward differences is a method for evaluating a nth degree polynomial at a uniform step by only adding precalculated values. For a linear example we have the function f(t) = m*t+b, then the value of that function at t+h would be f(t+h) = m*(t+h)+b. If we want to know the uniform step that we must add to the first evaluation f(t) then we need to substract f(t+h) - f(t) = m*t + m*h + b - m*t + b = mh. After obtaining this value (mh) we could just add this constant step to our first sampled point to compute the next one.

For the cubic case the first difference gives as a result a quadratic polynomial to which we can apply again forward differences and get linear function to which we can apply again forward differences to get a constant difference. This is why we keep an array of size 4, the 0th position keeps the sampled value while the next ones keep the quadratic, linear and constant difference values.

Definition at line 84 of file SkPatchUtils.cpp.

Constructor & Destructor Documentation

◆ FwDCubicEvaluator()

FwDCubicEvaluator::FwDCubicEvaluator ( const SkPoint  points[4])
inlineexplicit

Receives the 4 control points of the cubic bezier.

Definition at line 92 of file SkPatchUtils.cpp.

93 : fCoefs(points) {
94 memcpy(fPoints, points, 4 * sizeof(SkPoint));
95
96 this->restart(1);
97 }
static const int points[]
void restart(int divisions)

Member Function Documentation

◆ done()

bool FwDCubicEvaluator::done ( ) const
inline

Check if the evaluator is still within the range of 0<=t<=1

Definition at line 119 of file SkPatchUtils.cpp.

119 {
120 return fCurrent > fMax;
121 }

◆ getCtrlPoints()

const SkPoint * FwDCubicEvaluator::getCtrlPoints ( ) const
inline

Definition at line 135 of file SkPatchUtils.cpp.

135 {
136 return fPoints;
137 }

◆ next()

SkPoint FwDCubicEvaluator::next ( )
inline

Call next to obtain the SkPoint sampled and move to the next one.

Definition at line 126 of file SkPatchUtils.cpp.

126 {
127 SkPoint point = fFwDiff[0];
128 fFwDiff[0] += fFwDiff[1];
129 fFwDiff[1] += fFwDiff[2];
130 fFwDiff[2] += fFwDiff[3];
131 fCurrent++;
132 return point;
133 }

◆ restart()

void FwDCubicEvaluator::restart ( int  divisions)
inline

Restarts the forward differences evaluator to the first value of t = 0.

Definition at line 102 of file SkPatchUtils.cpp.

102 {
103 fDivisions = divisions;
104 fCurrent = 0;
105 fMax = fDivisions + 1;
106 skvx::float2 h = 1.f / fDivisions;
107 skvx::float2 h2 = h * h;
108 skvx::float2 h3 = h2 * h;
109 skvx::float2 fwDiff3 = 6 * fCoefs.fA * h3;
110 fFwDiff[3] = to_point(fwDiff3);
111 fFwDiff[2] = to_point(fwDiff3 + times_2(fCoefs.fB) * h2);
112 fFwDiff[1] = to_point(fCoefs.fA * h3 + fCoefs.fB * h2 + fCoefs.fC * h);
113 fFwDiff[0] = to_point(fCoefs.fD);
114 }
static skvx::float2 times_2(const skvx::float2 &value)
Definition: SkGeometry.h:32
static SkPoint to_point(SkIPoint p)
Definition: editor.cpp:75
SkScalar h
Definition: SkVx.h:83

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