blob: 86f5762a46668c92ef5237dab32584c4337192ad [file] [log] [blame]
Mike Reed4c79ecf2018-01-04 17:05:11 -05001/*
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 Reedd4322a82018-08-13 16:03:25 -040013/**
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 Reed4c79ecf2018-01-04 17:05:11 -050021class SkCubicMap {
22public:
Mike Reedd4322a82018-08-13 16:03:25 -040023 SkCubicMap() {} // must call setPts() before using
Mike Reed4c79ecf2018-01-04 17:05:11 -050024
Mike Reedd4322a82018-08-13 16:03:25 -040025 SkCubicMap(SkPoint p1, SkPoint p2) {
26 this->setPts(p1, p2);
27 }
Mike Reed0d4a1832018-08-14 17:21:23 -040028
Mike Reedd4322a82018-08-13 16:03:25 -040029 void setPts(SkPoint p1, SkPoint p2);
30
Mike Reed4c79ecf2018-01-04 17:05:11 -050031 float computeYFromX(float x) const;
32
Mike Reedd4322a82018-08-13 16:03:25 -040033 SkPoint computeFromT(float t) const;
Mike Reed4c79ecf2018-01-04 17:05:11 -050034
35private:
Mike Reed0d4a1832018-08-14 17:21:23 -040036 enum Type {
37 kLine_Type, // x == y
38 kCubeRoot_Type, // At^3 == x
39 kSolver_Type, // general monotonic cubic solver
40 };
Mike Reedd4322a82018-08-13 16:03:25 -040041 SkPoint fCoeff[3];
Mike Reed0d4a1832018-08-14 17:21:23 -040042 Type fType;
Mike Reed4c79ecf2018-01-04 17:05:11 -050043};
Mike Reedd4322a82018-08-13 16:03:25 -040044
Mike Reed4c79ecf2018-01-04 17:05:11 -050045#endif
46