Flutter Engine
The Flutter Engine
Functions
SkScalar.cpp File Reference
#include "include/core/SkScalar.h"
#include "include/private/base/SkDebug.h"

Go to the source code of this file.

Functions

SkScalar SkScalarInterpFunc (SkScalar searchKey, const SkScalar keys[], const SkScalar values[], int length)
 

Function Documentation

◆ SkScalarInterpFunc()

SkScalar SkScalarInterpFunc ( SkScalar  searchKey,
const SkScalar  keys[],
const SkScalar  values[],
int  length 
)

Interpolate along the function described by (keys[length], values[length]) for the passed searchKey. SearchKeys outside the range keys[0]-keys[Length] clamp to the min or max value. This function assumes the number of pairs (length) will be small and a linear search is used.

Repeated keys are allowed for discontinuous functions (so long as keys is monotonically increasing). If key is the value of a repeated scalar in keys the first one will be used.

Definition at line 11 of file SkScalar.cpp.

12 {
13 SkASSERT(length > 0);
14 SkASSERT(keys != nullptr);
15 SkASSERT(values != nullptr);
16#ifdef SK_DEBUG
17 for (int i = 1; i < length; i++) {
18 SkASSERT(keys[i-1] <= keys[i]);
19 }
20#endif
21 int right = 0;
22 while (right < length && keys[right] < searchKey) {
23 ++right;
24 }
25 // Could use sentinel values to eliminate conditionals, but since the
26 // tables are taken as input, a simpler format is better.
27 if (right == length) {
28 return values[length-1];
29 }
30 if (right == 0) {
31 return values[0];
32 }
33 // Otherwise, interpolate between right - 1 and right.
34 SkScalar leftKey = keys[right-1];
35 SkScalar rightKey = keys[right];
36 SkScalar fract = (searchKey - leftKey) / (rightKey - leftKey);
38}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool right(const SkPoint &p0, const SkPoint &p1)
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
Definition: SkScalar.h:131
float SkScalar
Definition: extension.cpp:12
size_t length
SIN Vec< N, float > fract(const Vec< N, float > &x)
Definition: SkVx.h:744