SkCubicMap.h 1002 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef SkCubicMap_DEFINED
  8. #define SkCubicMap_DEFINED
  9. #include "include/core/SkPoint.h"
  10. /**
  11. * Fast evaluation of a cubic ease-in / ease-out curve. This is defined as a parametric cubic
  12. * curve inside the unit square.
  13. *
  14. * pt[0] is implicitly { 0, 0 }
  15. * pt[3] is implicitly { 1, 1 }
  16. * pts[1,2].X are inside the unit [0..1]
  17. */
  18. class SK_API SkCubicMap {
  19. public:
  20. SkCubicMap(SkPoint p1, SkPoint p2);
  21. static bool IsLinear(SkPoint p1, SkPoint p2) {
  22. return SkScalarNearlyEqual(p1.fX, p1.fY) && SkScalarNearlyEqual(p2.fX, p2.fY);
  23. }
  24. float computeYFromX(float x) const;
  25. SkPoint computeFromT(float t) const;
  26. private:
  27. enum Type {
  28. kLine_Type, // x == y
  29. kCubeRoot_Type, // At^3 == x
  30. kSolver_Type, // general monotonic cubic solver
  31. };
  32. SkPoint fCoeff[3];
  33. Type fType;
  34. };
  35. #endif