123b3eb3cSopenharmony_ci/* 223b3eb3cSopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 323b3eb3cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 423b3eb3cSopenharmony_ci * you may not use this file except in compliance with the License. 523b3eb3cSopenharmony_ci * You may obtain a copy of the License at 623b3eb3cSopenharmony_ci * 723b3eb3cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 823b3eb3cSopenharmony_ci * 923b3eb3cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1023b3eb3cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1123b3eb3cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1223b3eb3cSopenharmony_ci * See the License for the specific language governing permissions and 1323b3eb3cSopenharmony_ci * limitations under the License. 1423b3eb3cSopenharmony_ci */ 1523b3eb3cSopenharmony_ci 1623b3eb3cSopenharmony_ci#include <cmath> 1723b3eb3cSopenharmony_ci 1823b3eb3cSopenharmony_ci#include "gtest/gtest.h" 1923b3eb3cSopenharmony_ci 2023b3eb3cSopenharmony_ci#include "base/geometry/quaternion.h" 2123b3eb3cSopenharmony_ci 2223b3eb3cSopenharmony_ciusing namespace testing; 2323b3eb3cSopenharmony_ciusing namespace testing::ext; 2423b3eb3cSopenharmony_ci 2523b3eb3cSopenharmony_cinamespace OHOS::Ace { 2623b3eb3cSopenharmony_cinamespace { 2723b3eb3cSopenharmony_ciconst double NUM_D1 = 1.0; 2823b3eb3cSopenharmony_ciconst double NUM_D2 = 0.2; 2923b3eb3cSopenharmony_ciconst double NUM_D3 = std::sin(std::acos(0.8)) / 3; 3023b3eb3cSopenharmony_ci} // namespace 3123b3eb3cSopenharmony_ci 3223b3eb3cSopenharmony_ciclass QuaternionTest : public testing::Test {}; 3323b3eb3cSopenharmony_ci 3423b3eb3cSopenharmony_ci/** 3523b3eb3cSopenharmony_ci * @tc.name: QuaternionTest001 3623b3eb3cSopenharmony_ci * @tc.desc: Test all functions of the class Quaternion. 3723b3eb3cSopenharmony_ci * @tc.type: FUNC 3823b3eb3cSopenharmony_ci */ 3923b3eb3cSopenharmony_ciHWTEST_F(QuaternionTest, QuaternionTest001, TestSize.Level1) 4023b3eb3cSopenharmony_ci{ 4123b3eb3cSopenharmony_ci Quaternion quaternion1; 4223b3eb3cSopenharmony_ci quaternion1.SetX(NUM_D1); 4323b3eb3cSopenharmony_ci quaternion1.SetY(NUM_D1); 4423b3eb3cSopenharmony_ci quaternion1.SetZ(NUM_D1); 4523b3eb3cSopenharmony_ci quaternion1.SetW(NUM_D1); 4623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion1.GetX(), NUM_D1); 4723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion1.GetY(), NUM_D1); 4823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion1.GetZ(), NUM_D1); 4923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion1.GetW(), NUM_D1); 5023b3eb3cSopenharmony_ci 5123b3eb3cSopenharmony_ci Quaternion quaternion2 = quaternion1.inverse(); 5223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion2.GetX(), -NUM_D1); 5323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion2.GetY(), -NUM_D1); 5423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion2.GetZ(), -NUM_D1); 5523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion2.GetW(), NUM_D1); 5623b3eb3cSopenharmony_ci 5723b3eb3cSopenharmony_ci Quaternion quaternion3 = quaternion1.Slerp(quaternion2, -1.0); 5823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion3.GetX(), NUM_D1); 5923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion3.GetY(), NUM_D1); 6023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion3.GetZ(), NUM_D1); 6123b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion3.GetW(), NUM_D1); 6223b3eb3cSopenharmony_ci 6323b3eb3cSopenharmony_ci Quaternion quaternion4 = quaternion1.Slerp(quaternion2, 2.0); 6423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion4.GetX(), NUM_D1); 6523b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion4.GetY(), NUM_D1); 6623b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion4.GetZ(), NUM_D1); 6723b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion4.GetW(), NUM_D1); 6823b3eb3cSopenharmony_ci 6923b3eb3cSopenharmony_ci quaternion2.SetW(-NUM_D1); 7023b3eb3cSopenharmony_ci Quaternion quaternion5 = quaternion1.Slerp(quaternion2, 1.0); 7123b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion5.GetX(), NUM_D1); 7223b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion5.GetY(), NUM_D1); 7323b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion5.GetZ(), NUM_D1); 7423b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion5.GetW(), NUM_D1); 7523b3eb3cSopenharmony_ci 7623b3eb3cSopenharmony_ci Quaternion quaternion6(NUM_D2, NUM_D2, NUM_D2, NUM_D2); 7723b3eb3cSopenharmony_ci Quaternion quaternion7 = quaternion1.Slerp(quaternion6, 1.0); 7823b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion7.GetX(), NUM_D3); 7923b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion7.GetY(), NUM_D3); 8023b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion7.GetZ(), NUM_D3); 8123b3eb3cSopenharmony_ci EXPECT_DOUBLE_EQ(quaternion7.GetW(), NUM_D3); 8223b3eb3cSopenharmony_ci} 8323b3eb3cSopenharmony_ci} // namespace OHOS::Ace 84