1 /*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "media/Twist.h"
18
19 #include <gtest/gtest.h>
20
21 #include "QuaternionUtil.h"
22 #include "TestUtil.h"
23
24 using Eigen::Quaternionf;
25 using Eigen::Vector3f;
26
27 namespace android {
28 namespace media {
29 namespace {
30
TEST(Twist,DefaultCtor)31 TEST(Twist, DefaultCtor) {
32 Twist3f twist;
33 EXPECT_EQ(twist.translationalVelocity(), Vector3f::Zero());
34 EXPECT_EQ(twist.rotationalVelocity(), Vector3f::Zero());
35 EXPECT_FLOAT_EQ(twist.scalarRotationalVelocity(), 0);
36 EXPECT_FLOAT_EQ(twist.scalarTranslationalVelocity(), 0);
37 }
38
TEST(Twist,FullCtor)39 TEST(Twist, FullCtor) {
40 Vector3f rot{1, 2, 3};
41 Vector3f trans{4, 5, 6};
42 Twist3f twist(trans, rot);
43 EXPECT_EQ(twist.translationalVelocity(), trans);
44 EXPECT_EQ(twist.rotationalVelocity(), rot);
45 EXPECT_FLOAT_EQ(twist.scalarRotationalVelocity(), std::sqrt(14.f));
46 EXPECT_FLOAT_EQ(twist.scalarTranslationalVelocity(), std::sqrt(77.f));
47 }
48
TEST(Twist,Integrate)49 TEST(Twist, Integrate) {
50 Vector3f trans{1, 2, 3};
51 // 45 deg/sec around Z.
52 Vector3f rot{0, 0, M_PI_4};
53 Twist3f twist(trans, rot);
54 Pose3f pose = integrate(twist, 2.f);
55
56 EXPECT_EQ(pose, Pose3f(Vector3f{2, 4, 6}, rotateZ(M_PI_2)));
57 }
58
TEST(Twist,Differentiate)59 TEST(Twist, Differentiate) {
60 Pose3f pose(Vector3f{2, 4, 6}, rotateZ(M_PI_2));
61 Twist3f twist = differentiate(pose, 2.f);
62 EXPECT_EQ(twist, Twist3f(Vector3f(1, 2, 3), Vector3f(0, 0, M_PI_4)));
63 }
64
65 } // namespace
66 } // namespace media
67 } // namespace android
68