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 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 */ 21 class SkCubicMap { 22 public: SkCubicMap()23 SkCubicMap() {} // must call setPts() before using 24 SkCubicMap(SkPoint p1,SkPoint p2)25 SkCubicMap(SkPoint p1, SkPoint p2) { 26 this->setPts(p1, p2); 27 } 28 29 void setPts(SkPoint p1, SkPoint p2); 30 31 float computeYFromX(float x) const; 32 33 SkPoint computeFromT(float t) const; 34 35 private: 36 enum Type { 37 kLine_Type, // x == y 38 kCubeRoot_Type, // At^3 == x 39 kSolver_Type, // general monotonic cubic solver 40 }; 41 SkPoint fCoeff[3]; 42 Type fType; 43 }; 44 45 #endif 46 47