Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 Google Inc. |
| 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 SkCubicMap_DEFINED |
| 9 | #define SkCubicMap_DEFINED |
| 10 | |
| 11 | #include "SkPoint.h" |
| 12 | |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 13 | /** |
| 14 | * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic |
| 15 | * curve inside the unit square. |
| 16 | * |
| 17 | * pt[0] is implicitly { 0, 0 } |
| 18 | * pt[3] is implicitly { 1, 1 } |
| 19 | * pts[1,2] are inside the unit square |
| 20 | */ |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 21 | class SkCubicMap { |
| 22 | public: |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 23 | SkCubicMap() {} // must call setPts() before using |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 24 | |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 25 | SkCubicMap(SkPoint p1, SkPoint p2) { |
| 26 | this->setPts(p1, p2); |
| 27 | } |
Mike Reed | 0d4a183 | 2018-08-14 17:21:23 -0400 | [diff] [blame] | 28 | |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 29 | void setPts(SkPoint p1, SkPoint p2); |
| 30 | |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 31 | float computeYFromX(float x) const; |
| 32 | |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 33 | SkPoint computeFromT(float t) const; |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 34 | |
| 35 | private: |
Mike Reed | 0d4a183 | 2018-08-14 17:21:23 -0400 | [diff] [blame] | 36 | enum Type { |
| 37 | kLine_Type, // x == y |
| 38 | kCubeRoot_Type, // At^3 == x |
| 39 | kSolver_Type, // general monotonic cubic solver |
| 40 | }; |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 41 | SkPoint fCoeff[3]; |
Mike Reed | 0d4a183 | 2018-08-14 17:21:23 -0400 | [diff] [blame] | 42 | Type fType; |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 43 | }; |
Mike Reed | d4322a8 | 2018-08-13 16:03:25 -0400 | [diff] [blame] | 44 | |
Mike Reed | 4c79ecf | 2018-01-04 17:05:11 -0500 | [diff] [blame] | 45 | #endif |
| 46 | |