1 /* 2 * Copyright (c) 2022 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 FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_NG_PROPERTIES_VECTORF_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_NG_PROPERTIES_VECTORF_H 18 19 #include "base/utils/utils.h" 20 21 namespace OHOS::Ace::NG { 22 23 struct VectorF { VectorFVectorF24 VectorF(float xF, float yF) : x(xF), y(yF) {} 25 26 bool operator==(const VectorF& other) const 27 { 28 return NearEqual(x, other.x, 1e-5) && NearEqual(y, other.y, 1e-5); 29 } 30 31 VectorF operator*(float value) const 32 { 33 return VectorF(x * value, y * value); 34 } 35 36 float x = 0.0f; 37 float y = 0.0f; 38 }; 39 40 struct Vector3F { 41 Vector3F() = default; Vector3FVector3F42 Vector3F(float xF, float yF, float zF) : x(xF), y(yF), z(zF) {} 43 44 bool operator==(const Vector3F& other) const 45 { 46 return NearEqual(x, other.x) && NearEqual(y, other.y) && NearEqual(z, other.z); 47 } 48 49 float operator[](int32_t index) const 50 { 51 switch (index) { 52 case 0: 53 return x; 54 case 1: 55 return y; 56 case 2: 57 return z; 58 default: 59 return 0.0f; 60 } 61 } 62 63 float x = 0.0f; 64 float y = 0.0f; 65 float z = 0.0f; 66 }; 67 68 struct Vector4F { Vector4FVector4F69 Vector4F(float xF, float yF, float zF, float wF) : x(xF), y(yF), z(zF), w(wF) {} 70 71 bool operator==(const Vector4F& other) const 72 { 73 return NearEqual(x, other.x) && NearEqual(y, other.y) && NearEqual(z, other.z) && NearEqual(w, other.w); 74 } 75 76 float x = 0.0f; 77 float y = 0.0f; 78 float z = 0.0f; 79 float w = 0.0f; 80 }; 81 82 struct Vector5F { Vector5FVector5F83 Vector5F(float xF, float yF, float zF, float wF, float vF) : x(xF), y(yF), z(zF), w(wF), v(vF) {} 84 85 bool operator==(const Vector5F& other) const 86 { 87 return NearEqual(x, other.x) && NearEqual(y, other.y) && NearEqual(z, other.z) && 88 NearEqual(w, other.w) && NearEqual(v, other.v); 89 } 90 91 float x = 0.0f; 92 float y = 0.0f; 93 float z = 0.0f; 94 float w = 0.0f; 95 float v = 0.0f; 96 }; 97 98 } // namespace OHOS::Ace::NG 99 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_NG_PROPERTIES_VECTORF_H