Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkScalar.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2010 The Android Open Source Project
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
9
11 const SkScalar values[], int length) {
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)
SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[], const SkScalar values[], int length)
Definition SkScalar.cpp:10
static SkScalar SkScalarInterp(SkScalar A, SkScalar B, SkScalar t)
Definition SkScalar.h:131
float SkScalar
Definition extension.cpp:12
size_t length