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