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 #ifndef UIEFFECT_UTILS_H
16 #define UIEFFECT_UTILS_H
17
18 #include <math.h>
19 #include <utility>
20 #include "common/rs_common_def.h"
21 #include "common/rs_vector2.h"
22 #include "common/rs_vector3.h"
23 #include "common/rs_vector4.h"
24
25 namespace OHOS {
26 namespace Rosen {
27 namespace UIEffect {
IsParaSameSign(Vector4f para)28 inline bool IsParaSameSign(Vector4f para)
29 {
30 return (ROSEN_GE(para.x_, 0.f) && ROSEN_GE(para.y_, 0.f) && ROSEN_GE(para.z_, 0.f) && ROSEN_GE(para.w_, 0.f)) ||
31 (ROSEN_LE(para.x_, 0.f) && ROSEN_LE(para.y_, 0.f) && ROSEN_LE(para.z_, 0.f) && ROSEN_LE(para.w_, 0.f));
32 }
33
34 inline float GetLimitedPara(float para, std::pair<float, float> limits = {-INFINITY, INFINITY})
35 {
36 return std::clamp(para, limits.first, limits.second);
37 }
38
39 inline Vector2f GetLimitedPara(const Vector2f& para, std::pair<float, float> limits = {-INFINITY, INFINITY})
40 {
41 return Vector2f(std::clamp(para.x_, limits.first, limits.second), std::clamp(para.y_, limits.first, limits.second));
42 }
43
44 inline Vector3f GetLimitedPara(const Vector3f& para, std::pair<float, float> limits = {-INFINITY, INFINITY})
45 {
46 return Vector3f(std::clamp(para.x_, limits.first, limits.second), std::clamp(para.y_, limits.first, limits.second),
47 std::clamp(para.z_, limits.first, limits.second));
48 }
49
50 inline Vector4f GetLimitedPara(const Vector4f& para, std::pair<float, float> limits = {-INFINITY, INFINITY})
51 {
52 return Vector4f(std::clamp(para.x_, limits.first, limits.second), std::clamp(para.y_, limits.first, limits.second),
53 std::clamp(para.z_, limits.first, limits.second), std::clamp(para.w_, limits.first, limits.second));
54 }
55 } // namespace UIEffect
56 } // namespace Rosen
57 } // namespace OHOS
58 #endif // UIEFFECT_UTILS_H
59