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 "media/QuaternionUtil.h"
20 #include "TestUtil.h"
21
22 using Eigen::Quaternionf;
23 using Eigen::Vector3f;
24
25 namespace android {
26 namespace media {
27 namespace {
28
TEST(Twist,DefaultCtor)29 TEST(Twist, DefaultCtor) {
30 Twist3f twist;
31 EXPECT_EQ(twist.translationalVelocity(), Vector3f::Zero());
32 EXPECT_EQ(twist.rotationalVelocity(), Vector3f::Zero());
33 EXPECT_FLOAT_EQ(twist.scalarRotationalVelocity(), 0);
34 EXPECT_FLOAT_EQ(twist.scalarTranslationalVelocity(), 0);
35 }
36
TEST(Twist,FullCtor)37 TEST(Twist, FullCtor) {
38 Vector3f rot{1, 2, 3};
39 Vector3f trans{4, 5, 6};
40 Twist3f twist(trans, rot);
41 EXPECT_EQ(twist.translationalVelocity(), trans);
42 EXPECT_EQ(twist.rotationalVelocity(), rot);
43 EXPECT_FLOAT_EQ(twist.scalarRotationalVelocity(), std::sqrt(14.f));
44 EXPECT_FLOAT_EQ(twist.scalarTranslationalVelocity(), std::sqrt(77.f));
45 }
46
TEST(Twist,Integrate)47 TEST(Twist, Integrate) {
48 Vector3f trans{1, 2, 3};
49 // 45 deg/sec around Z.
50 Vector3f rot{0, 0, M_PI_4};
51 Twist3f twist(trans, rot);
52 Pose3f pose = integrate(twist, 2.f);
53
54 EXPECT_EQ(pose, Pose3f(Vector3f{2, 4, 6}, rotateZ(M_PI_2)));
55 }
56
TEST(Twist,Differentiate)57 TEST(Twist, Differentiate) {
58 Pose3f pose(Vector3f{2, 4, 6}, rotateZ(M_PI_2));
59 Twist3f twist = differentiate(pose, 2.f);
60 EXPECT_EQ(twist, Twist3f(Vector3f(1, 2, 3), Vector3f(0, 0, M_PI_4)));
61 }
62
63 } // namespace
64 } // namespace media
65 } // namespace android
66