Moved Fusion Backed from sensor_fusion folder to rotation_vector folder
[platform/core/system/sensord.git] / src / sensor / rotation_vector / test / test_projects / quaternion_test / quaternion_main.cpp
1 /*
2  * sensord
3  *
4  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "../../../quaternion.h"
21
22 int main()
23 {
24         float arr0[4] = {2344.98, 345.24, 456.12, 98.33};
25         float arr1[4] = {0.056, 0.34, -0.0076, 0.001};
26         float axis1[3] = {6.5, 7.5, 8.3};
27         float ang1 = 8.4;
28
29         vect<float, 4> v0(arr0);
30         vect<float, 4> v1(arr1);
31         vect<float, 3> v2(axis1);
32
33         quaternion<float> q0(v0);
34         quaternion<float> q1(v1);
35         quaternion<float> q2((float)2344.98, (float)345.24, (float)456.12, (float)98.33);
36         quaternion<float> q3(q1);
37         quaternion<float> q4;
38
39         cout << "Constructor tests\n";
40         cout << "input\t" << v0 << "\n";
41         cout << "output\t" << q0.m_quat << "\n\n";
42         cout << "input\t" << v1 << "\n";
43         cout << "output\t" << q1.m_quat << "\n\n";
44         cout << "input\t" << v0 << "\n";
45         cout << "output\t" << q2.m_quat << "\n\n";
46         cout << "input\t" << v1 << "\n";
47         cout << "output\t" << q3.m_quat << "\n\n";
48         cout << "default constructor\n";
49         cout << "output\t" << q4.m_quat << "\n\n";
50
51         cout << "Multiplication\n";
52         float val = 0.1;
53         quaternion<float> q5 = q0 * val;
54         cout << "input\t" << q0.m_quat << "\n" << 0.1 << "\n";
55         cout << "output\t" << q5.m_quat << "\n\n";
56         quaternion<float> q6 = q0 * q1;
57         cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n";
58         cout << "output\t" << q6.m_quat << "\n\n";
59
60         cout << "Addition\n";
61         quaternion<float> q7 = q0 + q1;
62         cout << "input\t" << q0.m_quat << "\n" << q1.m_quat << "\n";
63         cout << "output\t" << q7.m_quat << "\n\n";
64
65         cout << "Quaternion Normalization\n";
66         cout << "input\t" << q1.m_quat << "\n";
67         q1.quat_normalize();
68         cout << "output\t" << q1.m_quat << "\n\n";
69
70         cout << "Axis2quat\n";
71         cout << "input\t" << " " << v2 << endl;
72         cout << endl;
73         quaternion<float> q11 = axis2quat(v2, ang1);
74         cout << "output\t" << q11.m_quat << "\n\n";
75         cout << endl;
76 }
77