Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 | |
| 8 | #ifndef SkCurve_DEFINED |
| 9 | #define SkCurve_DEFINED |
| 10 | |
| 11 | #include "SkScalar.h" |
| 12 | |
| 13 | class SkFieldVisitor; |
| 14 | class SkRandom; |
| 15 | |
| 16 | // TODO: Generalize this to a keyframed list of cubics |
| 17 | |
| 18 | struct SkCurve { |
| 19 | SkCurve(SkScalar c = 0.0f) { |
| 20 | fRanged = false; |
| 21 | fMin[0] = fMin[1] = fMin[2] = fMin[3] = c; |
| 22 | fMax[0] = fMax[1] = fMax[2] = fMax[3] = c; |
| 23 | } |
| 24 | |
| 25 | SkScalar eval(float x, SkRandom& random) const; |
| 26 | void visitFields(SkFieldVisitor* v); |
| 27 | |
| 28 | bool fRanged; |
| 29 | SkScalar fMin[4]; |
| 30 | SkScalar fMax[4]; // used if ranged |
| 31 | }; |
| 32 | |
| 33 | // Ranged constant. Keeping this here temporarily. Phase this out in favor of SkCurve everywhere. |
| 34 | struct SkRangedFloat { |
| 35 | float eval(SkRandom& random) const; |
| 36 | float* vec() { return &fMin; } |
| 37 | |
| 38 | float fMin = 0.0f; |
| 39 | float fMax = 0.0f; |
| 40 | |
| 41 | void visitFields(SkFieldVisitor* v); |
| 42 | }; |
| 43 | |
| 44 | #endif // SkCurve_DEFINED |