Skia
2D Graphics Library
SkCubicMap.h
Go to the documentation of this file.
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 "include/core/SkPoint.h"
12 #include "include/core/SkScalar.h"
13 #include "include/core/SkTypes.h"
14 
23 class SK_API SkCubicMap {
24 public:
25  SkCubicMap(SkPoint p1, SkPoint p2);
26 
27  static bool IsLinear(SkPoint p1, SkPoint p2) {
28  return SkScalarNearlyEqual(p1.fX, p1.fY) && SkScalarNearlyEqual(p2.fX, p2.fY);
29  }
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 
42  SkPoint fCoeff[3];
43  Type fType;
44 };
45 
46 #endif
47 
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:119
Fast evaluation of a cubic ease-in / ease-out curve.
Definition: SkCubicMap.h:23
float computeYFromX(float x) const
static bool IsLinear(SkPoint p1, SkPoint p2)
Definition: SkCubicMap.h:27
SkPoint computeFromT(float t) const
SkCubicMap(SkPoint p1, SkPoint p2)