1 /*
2 * Copyright (c) 2024 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 #ifndef API_BASE_MATH_SPLINE_H
17 #define API_BASE_MATH_SPLINE_H
18
19 #include <base/namespace.h>
20
21 BASE_BEGIN_NAMESPACE()
22 namespace Math {
23 /** @ingroup group_math_spline */
24 /** For hermite interpolation */
25 template<typename T>
Hermite(T const& v1, T const& t1, T const& v2, T const& t2, float s)26 inline constexpr T Hermite(T const& v1, T const& t1, T const& v2, T const& t2, float s)
27 {
28 const float s2 = s * s;
29 const float s3 = s2 * s;
30 const float s23 = 2.f * s3;
31 const float s32 = 3.f * s2;
32
33 const float f1 = s23 - s32 + 1.f;
34 const float f2 = -s23 + s32;
35 const float f3 = s3 - 2.f * s2 + s;
36 const float f4 = s3 - s2;
37
38 return v1 * f1 + v2 * f2 + t1 * f3 + t2 * f4;
39 }
40 } // namespace Math
41 BASE_END_NAMESPACE()
42
43 #endif // API_BASE_MATH_SPLINE_H
44