-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathRotationSpline_TEST.cc
More file actions
105 lines (87 loc) · 3.21 KB
/
Copy pathRotationSpline_TEST.cc
File metadata and controls
105 lines (87 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <gtest/gtest.h>
#include "gz/math/Helpers.hh"
#include "gz/math/Vector3.hh"
#include "gz/math/Quaternion.hh"
#include "gz/math/RotationSpline.hh"
using namespace gz;
/////////////////////////////////////////////////
TEST(RotationSplineTest, RotationSpline)
{
math::RotationSpline s;
s.AddPoint(math::Quaterniond(0, 0, 0));
EXPECT_EQ(static_cast<unsigned int>(1), s.PointCount());
s.Clear();
EXPECT_EQ(static_cast<unsigned int>(0), s.PointCount());
s.AddPoint(math::Quaterniond(0, 0, 0));
EXPECT_TRUE(s.Point(0) == math::Quaterniond(0, 0, 0));
s.AddPoint(math::Quaterniond(.1, .1, .1));
EXPECT_TRUE(s.Point(1) == math::Quaterniond(.1, .1, .1));
// ::UpdatePoint
EXPECT_NO_THROW(s.UpdatePoint(2, math::Quaterniond(.2, .2, .2)));
EXPECT_FALSE(s.UpdatePoint(2, math::Quaterniond(.2, .2, .2)));
EXPECT_TRUE(s.UpdatePoint(1, math::Quaterniond(.2, .2, .2)));
s.AutoCalculate(false);
EXPECT_TRUE(s.UpdatePoint(0, math::Quaterniond(
math::Vector3d(-.1, -.1, -.1))));
s.AutoCalculate(true);
// ::Interpolate
EXPECT_TRUE(s.Interpolate(0.5) ==
math::Quaterniond(0.998089, 0.0315333, 0.0427683, 0.0315333));
// ::Interpolate
s.AddPoint(math::Quaterniond(.4, .4, .4));
EXPECT_NO_THROW(s.Interpolate(4, 0.2));
EXPECT_FALSE(s.Interpolate(4, 0.2).IsFinite());
EXPECT_EQ(s.Interpolate(s.PointCount()-1, 0.2),
s.Point(s.PointCount()-1));
EXPECT_TRUE(s.Interpolate(1, 0.2) ==
math::Quaterniond(0.978787, 0.107618, 0.137159, 0.107618));
EXPECT_EQ(s.Interpolate(1, 0.0), s.Point(1));
EXPECT_EQ(s.Interpolate(1, 1.0), s.Point(2));
// ::Interpolate
s.Clear();
s.AddPoint(math::Quaterniond(0.1, 0, 0));
s.AddPoint(math::Quaterniond(0.2, 0, 0));
EXPECT_EQ(s.Interpolate(0.5), math::Quaterniond(0.15, 0, 0));
}
/////////////////////////////////////////////////
TEST(RotationSplineTest, GetPoint)
{
math::RotationSpline s;
EXPECT_NO_THROW(s.Point(0));
EXPECT_FALSE(s.Point(0).IsFinite());
EXPECT_NO_THROW(s.Point(1));
EXPECT_FALSE(s.Point(1).IsFinite());
s.AddPoint(math::Quaterniond(0, 0, 0));
EXPECT_NO_THROW(s.Point(0));
EXPECT_NO_THROW(s.Point(1));
EXPECT_TRUE(s.Point(1).IsFinite());
}
/////////////////////////////////////////////////
TEST(RotationSplineTest, RecalcTangents)
{
math::RotationSpline s;
s.AddPoint(math::Quaterniond(0, 0, 0));
s.AddPoint(math::Quaterniond(.4, .4, .4));
s.AddPoint(math::Quaterniond(0, 0, 0));
s.RecalcTangents();
EXPECT_EQ(s.Interpolate(0, 0.5),
math::Quaterniond(0.987225, 0.077057, 0.11624, 0.077057));
EXPECT_EQ(s.Interpolate(1, 0.5),
math::Quaterniond(0.987225, 0.077057, 0.11624, 0.077057));
}