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" |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame^] | 12 | #include "SkTArray.h" |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 13 | |
| 14 | class SkFieldVisitor; |
| 15 | class SkRandom; |
| 16 | |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame^] | 17 | struct SkCurveSegment { |
| 18 | SkScalar eval(SkScalar x, SkRandom& random) const; |
| 19 | void visitFields(SkFieldVisitor* v); |
| 20 | |
| 21 | void setConstant(SkScalar c) { |
| 22 | fConstant = true; |
| 23 | fRanged = false; |
| 24 | fMin[0] = c; |
| 25 | } |
| 26 | |
| 27 | SkScalar fMin[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 28 | SkScalar fMax[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; |
| 29 | |
| 30 | bool fConstant = true; |
| 31 | bool fRanged = false; |
| 32 | bool fBidirectional = false; |
| 33 | }; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 34 | |
| 35 | struct SkCurve { |
| 36 | SkCurve(SkScalar c = 0.0f) { |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame^] | 37 | fSegments.push_back().setConstant(c); |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 38 | } |
| 39 | |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame^] | 40 | SkScalar eval(SkScalar x, SkRandom& random) const; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 41 | void visitFields(SkFieldVisitor* v); |
| 42 | |
Brian Osman | 8b6283f | 2019-02-14 16:55:21 -0500 | [diff] [blame^] | 43 | SkTArray<SkScalar, true> fXValues; |
| 44 | SkTArray<SkCurveSegment, true> fSegments; |
Brian Osman | 7c979f5 | 2019-02-12 13:27:51 -0500 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | #endif // SkCurve_DEFINED |