Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkScalar.cpp File Reference
#include "include/core/SkScalar.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 10 of file SkScalar.cpp.

11 {
12 SkASSERT(length > 0);
13 SkASSERT(keys != nullptr);
14 SkASSERT(values != nullptr);
15#ifdef SK_DEBUG
16 for (int i = 1; i < length; i++) {
17 SkASSERT(keys[i-1] <= keys[i]);
18 }
19#endif
20 int right = 0;
21 while (right < length && keys[right] < searchKey) {
22 ++right;
23 }
24 // Could use sentinel values to eliminate conditionals, but since the
25 // tables are taken as input, a simpler format is better.
26 if (right == length) {
27 return values[length-1];
28 }
29 if (right == 0) {
30 return values[0];
31 }
32 // Otherwise, interpolate between right - 1 and right.
33 SkScalar leftKey = keys[right-1];
34 SkScalar rightKey = keys[right];
35 SkScalar fract = (searchKey - leftKey) / (rightKey - leftKey);
36 return SkScalarInterp(values[right-1], values[right], fract);
37}
#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