1 /* 2 * Copyright (c) 2020-2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /** 17 * @addtogroup UI_Animator 18 * @{ 19 * 20 * @brief Defines UI animation effects and provides matched curves. 21 * 22 * @since 1.0 23 * @version 1.0 24 */ 25 26 /** 27 * @file interpolation.h 28 * 29 * @brief Defines the functions for calculating the interpolation in computer graphics. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef GRAPHIC_LITE_INTERPOLATION_H 36 #define GRAPHIC_LITE_INTERPOLATION_H 37 38 #include "gfx_utils/heap_base.h" 39 40 namespace OHOS { 41 /** 42 * @brief Calculates the Bezier interpolation. 43 * 44 * @since 1.0 45 * @version 1.0 46 */ 47 class Interpolation : public HeapBase { 48 public: 49 /** 50 * @brief Obtains the value calculated by the cubic Bezier equation. 51 * 52 * Use [0, 1024] instead of [0, 1] in the standard Bezier equation. The cubic Bezier equation 53 * is <b>B(t) = P0*(1-t)^3 + 3*P1*t*(1-t)^2 + 3*P2*t^2*(1-t) + P3*t^3</b>. 54 * 55 * @param t Indicates the current change rate of the cubic Bezier curve, within [0, 1024]. 56 * @param u0 Indicates the coordinates for the start point of the cubic Bezier curve, within [0, 1024]. 57 * @param u1 Indicates the coordinates for the first control point of the cubic Bezier curve, within [0, 1024]. 58 * @param u2 Indicates the coordinates for the second control point of the cubic Bezier curve, within [0, 1024]. 59 * @param u3 Indicates the coordinates for the end point of the cubic Bezier curve, within [0, 1024]. 60 * 61 * @return Returns the coordinates for the current change rate. 62 * @since 3 63 */ 64 static int16_t GetBezierInterpolation(int16_t t, int16_t u0, int16_t u1, int16_t u2, int16_t u3); 65 66 /** 67 * @brief Obtains the value calculated by the cubic Bezier equation. 68 * 69 * The standard cubic Bezier equation is <b>B(t) = P0*(1-t)^3 + 3*P1*t*(1-t)^2 + 3*P2*t^2*(1-t) + P3*t^3</b>. 70 * 71 * @param t Indicates the current change rate of the cubic Bezier curve, within [0, 1]. 72 * @param u0 Indicates the coordinates for the start point of the cubic Bezier curve, within [0, 1]. 73 * @param u1 Indicates the coordinates for the first control point of the cubic Bezier curve, within [0, 1]. 74 * @param u2 Indicates the coordinates for the second control point of the cubic Bezier curve, within [0, 1]. 75 * @param u3 Indicates the coordinates for the end point of the cubic Bezier curve, within [0, 1]. 76 * 77 * @return Returns the coordinates for the current change rate. 78 * @since 6 79 */ 80 static float GetBezierInterpolation(float t, float u0, float u1, float u2, float u3); 81 82 /** 83 * @brief Obtains the value calculated by the cubic Bezier equation in standard two-dimensional coordinate system. 84 * 85 * The cubic Bezier equation is <b>B(t) = P0*(1-t)^3 + 3*P1*t*(1-t)^2 + 3*P2*t^2*(1-t) + P3*t^3</b>. 86 * <b>P0=(0,0), P3=(1,1)</b> 87 * 88 * @param x Indicates the abscissa of P, within [0, 1]. 89 * @param x1 Indicates the abscissa of the first control point of the cubic Bezier curve, within [0, 1]. 90 * @param y1 Indicates the ordinate of the first control point of the cubic Bezier curve, within [0, 1]. 91 * @param x2 Indicates the abscissa of the second control point of the cubic Bezier curve, within [0, 1]. 92 * @param y2 Indicates the ordinate of the second control point of the cubic Bezier curve, within [0, 1]. 93 * 94 * @return Returns the ordinate of the P. 95 * @since 6 96 */ 97 static float GetBezierY(float x, float x1, float y1, float x2, float y2); 98 99 private: 100 static float GetBezierDerivative(float t, float u0, float u1, float u2, float u3); 101 static constexpr uint8_t BEZIER_COEFFICIENT = 3; 102 }; 103 } // namespace OHOS 104 #endif // GRAPHIC_LITE_INTERPOLATION_H 105