Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(541)

Side by Side Diff: ui/gfx/geometry/quaternion_unittest.cc

Issue 2971903005: Fix matrix interpolation between rotations of 180 degrees (Closed)
Patch Set: forgot to revert a corresponding unit test Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/gfx/geometry/quaternion.cc ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 } 135 }
136 } 136 }
137 137
138 TEST(QuatTest, SlerpOppositeAngles) { 138 TEST(QuatTest, SlerpOppositeAngles) {
139 Vector3dF axis(1, 1, 1); 139 Vector3dF axis(1, 1, 1);
140 double start_radians = -M_PI_2; 140 double start_radians = -M_PI_2;
141 double stop_radians = M_PI_2; 141 double stop_radians = M_PI_2;
142 Quaternion start(axis, start_radians); 142 Quaternion start(axis, start_radians);
143 Quaternion stop(axis, stop_radians); 143 Quaternion stop(axis, stop_radians);
144 144
145 // When quaternions are pointed in the fully opposite direction, we take the 145 // When quaternions are pointed in the fully opposite direction, this is
146 // interpolated quaternion to be the first. This is arbitrary, but if we 146 // ambiguous, so we rotate as per https://www.w3.org/TR/css-transforms-1/
147 // change this policy, this test should fail. 147 Quaternion expected(axis, 0);
148 Quaternion expected = start;
149 148
150 for (size_t i = 0; i < 100; ++i) { 149 Quaternion interpolated = start.Slerp(stop, 0.5f);
151 float t = static_cast<float>(i) / 100.0f; 150 EXPECT_NEAR(expected.x(), interpolated.x(), kEpsilon);
152 Quaternion interpolated = start.Slerp(stop, t); 151 EXPECT_NEAR(expected.y(), interpolated.y(), kEpsilon);
153 CompareQuaternions(expected, interpolated); 152 EXPECT_NEAR(expected.z(), interpolated.z(), kEpsilon);
154 } 153 EXPECT_NEAR(expected.w(), interpolated.w(), kEpsilon);
155 } 154 }
156 155
157 } // namespace gfx 156 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/geometry/quaternion.cc ('k') | ui/gfx/transform_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698