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_vector3.h"
22 #include "common/rs_vector4.h"
23 
24 namespace OHOS {
25 namespace Rosen {
26 namespace UIEffect {
IsParaSameSign(Vector4f para)27 inline bool IsParaSameSign(Vector4f para)
28 {
29     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)) ||
30         (ROSEN_LE(para.x_, 0.f) && ROSEN_LE(para.y_, 0.f) && ROSEN_LE(para.z_, 0.f) && ROSEN_LE(para.w_, 0.f));
31 }
32 
33 inline float GetLimitedPara(float para, std::pair<float, float> limits = {-INFINITY, INFINITY})
34 {
35     return std::clamp(para, limits.first, limits.second);
36 }
37 
38 inline Vector3f GetLimitedPara(const Vector3f& para, std::pair<float, float> limits = {-INFINITY, INFINITY})
39 {
40     return Vector3f(std::clamp(para.x_, limits.first, limits.second), std::clamp(para.y_, limits.first, limits.second),
41         std::clamp(para.z_, limits.first, limits.second));
42 }
43 
44 inline Vector4f GetLimitedPara(const Vector4f& para, std::pair<float, float> limits = {-INFINITY, INFINITY})
45 {
46     return Vector4f(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), std::clamp(para.w_, limits.first, limits.second));
48 }
49 } // namespace UIEffect
50 } // namespace Rosen
51 } // namespace OHOS
52 #endif // UIEFFECT_UTILS_H
53