OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 empiricalBounds.unionBounds(transformed); | 68 empiricalBounds.unionBounds(transformed); |
69 firstTime = false; | 69 firstTime = false; |
70 } | 70 } |
71 | 71 |
72 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertContains, bounds, empiricalBounds); | 72 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertContains, bounds, empiricalBounds); |
73 } | 73 } |
74 | 74 |
75 TEST(TransformOperationsTest, AbsoluteAnimatedTranslatedBoundsTest) { | 75 TEST(TransformOperationsTest, AbsoluteAnimatedTranslatedBoundsTest) { |
76 TransformOperations fromOps; | 76 TransformOperations fromOps; |
77 TransformOperations toOps; | 77 TransformOperations toOps; |
78 fromOps.operations().append(TranslateTransformOperation::create( | 78 fromOps.operations().push_back(TranslateTransformOperation::create( |
79 Length(-30, blink::Fixed), Length(20, blink::Fixed), 15, | 79 Length(-30, blink::Fixed), Length(20, blink::Fixed), 15, |
80 TransformOperation::Translate3D)); | 80 TransformOperation::Translate3D)); |
81 toOps.operations().append(TranslateTransformOperation::create( | 81 toOps.operations().push_back(TranslateTransformOperation::create( |
82 Length(10, blink::Fixed), Length(10, blink::Fixed), 200, | 82 Length(10, blink::Fixed), Length(10, blink::Fixed), 200, |
83 TransformOperation::Translate3D)); | 83 TransformOperation::Translate3D)); |
84 FloatBox box(0, 0, 0, 10, 10, 10); | 84 FloatBox box(0, 0, 0, 10, 10, 10); |
85 FloatBox bounds; | 85 FloatBox bounds; |
86 | 86 |
87 EXPECT_TRUE( | 87 EXPECT_TRUE( |
88 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds)); | 88 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds)); |
89 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 89 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
90 FloatBox(0, 0, 0, 20, 20, 210), bounds); | 90 FloatBox(0, 0, 0, 20, 20, 210), bounds); |
91 | 91 |
(...skipping 23 matching lines...) Expand all Loading... |
115 | 115 |
116 // All progressions for animations start and end at 0, 1 respectively, | 116 // All progressions for animations start and end at 0, 1 respectively, |
117 // we can go outside of these bounds, but will always at least contain | 117 // we can go outside of these bounds, but will always at least contain |
118 // [0,1]. | 118 // [0,1]. |
119 float progress[][2] = {{0, 1}, {-.25, 1.25}}; | 119 float progress[][2] = {{0, 1}, {-.25, 1.25}}; |
120 | 120 |
121 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { | 121 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { |
122 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | 122 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { |
123 TransformOperations fromOps; | 123 TransformOperations fromOps; |
124 TransformOperations toOps; | 124 TransformOperations toOps; |
125 fromOps.operations().append(TranslateTransformOperation::create( | 125 fromOps.operations().push_back(TranslateTransformOperation::create( |
126 Length(testTransforms[i][0][0], blink::Fixed), | 126 Length(testTransforms[i][0][0], blink::Fixed), |
127 Length(testTransforms[i][0][1], blink::Fixed), | 127 Length(testTransforms[i][0][1], blink::Fixed), |
128 testTransforms[i][0][2], TransformOperation::Translate3D)); | 128 testTransforms[i][0][2], TransformOperation::Translate3D)); |
129 toOps.operations().append(TranslateTransformOperation::create( | 129 toOps.operations().push_back(TranslateTransformOperation::create( |
130 Length(testTransforms[i][1][0], blink::Fixed), | 130 Length(testTransforms[i][1][0], blink::Fixed), |
131 Length(testTransforms[i][1][1], blink::Fixed), | 131 Length(testTransforms[i][1][1], blink::Fixed), |
132 testTransforms[i][1][2], TransformOperation::Translate3D)); | 132 testTransforms[i][1][2], TransformOperation::Translate3D)); |
133 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); | 133 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); |
134 } | 134 } |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 TEST(TransformOperationsTest, AbsoluteAnimatedScaleBoundsTest) { | 138 TEST(TransformOperationsTest, AbsoluteAnimatedScaleBoundsTest) { |
139 TransformOperations fromOps; | 139 TransformOperations fromOps; |
140 TransformOperations toOps; | 140 TransformOperations toOps; |
141 fromOps.operations().append( | 141 fromOps.operations().push_back( |
142 ScaleTransformOperation::create(4, -3, TransformOperation::Scale)); | 142 ScaleTransformOperation::create(4, -3, TransformOperation::Scale)); |
143 toOps.operations().append( | 143 toOps.operations().push_back( |
144 ScaleTransformOperation::create(5, 2, TransformOperation::Scale)); | 144 ScaleTransformOperation::create(5, 2, TransformOperation::Scale)); |
145 | 145 |
146 FloatBox box(0, 0, 0, 10, 10, 10); | 146 FloatBox box(0, 0, 0, 10, 10, 10); |
147 FloatBox bounds; | 147 FloatBox bounds; |
148 | 148 |
149 EXPECT_TRUE( | 149 EXPECT_TRUE( |
150 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds)); | 150 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds)); |
151 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 151 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
152 FloatBox(0, 0, 0, 50, 20, 10), bounds); | 152 FloatBox(0, 0, 0, 50, 20, 10), bounds); |
153 | 153 |
(...skipping 24 matching lines...) Expand all Loading... |
178 | 178 |
179 // All progressions for animations start and end at 0, 1 respectively, | 179 // All progressions for animations start and end at 0, 1 respectively, |
180 // we can go outside of these bounds, but will always at least contain | 180 // we can go outside of these bounds, but will always at least contain |
181 // [0,1]. | 181 // [0,1]. |
182 float progress[][2] = {{0, 1}, {-.25f, 1.25f}}; | 182 float progress[][2] = {{0, 1}, {-.25f, 1.25f}}; |
183 | 183 |
184 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { | 184 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { |
185 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | 185 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { |
186 TransformOperations fromOps; | 186 TransformOperations fromOps; |
187 TransformOperations toOps; | 187 TransformOperations toOps; |
188 fromOps.operations().append(TranslateTransformOperation::create( | 188 fromOps.operations().push_back(TranslateTransformOperation::create( |
189 Length(testTransforms[i][0][0], blink::Fixed), | 189 Length(testTransforms[i][0][0], blink::Fixed), |
190 Length(testTransforms[i][0][1], blink::Fixed), | 190 Length(testTransforms[i][0][1], blink::Fixed), |
191 testTransforms[i][0][2], TransformOperation::Translate3D)); | 191 testTransforms[i][0][2], TransformOperation::Translate3D)); |
192 toOps.operations().append(TranslateTransformOperation::create( | 192 toOps.operations().push_back(TranslateTransformOperation::create( |
193 Length(testTransforms[i][1][0], blink::Fixed), | 193 Length(testTransforms[i][1][0], blink::Fixed), |
194 Length(testTransforms[i][1][1], blink::Fixed), | 194 Length(testTransforms[i][1][1], blink::Fixed), |
195 testTransforms[i][1][2], TransformOperation::Translate3D)); | 195 testTransforms[i][1][2], TransformOperation::Translate3D)); |
196 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); | 196 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); |
197 } | 197 } |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 TEST(TransformOperationsTest, AbsoluteAnimatedRotationBounds) { | 201 TEST(TransformOperationsTest, AbsoluteAnimatedRotationBounds) { |
202 TransformOperations fromOps; | 202 TransformOperations fromOps; |
203 TransformOperations toOps; | 203 TransformOperations toOps; |
204 fromOps.operations().append( | 204 fromOps.operations().push_back( |
205 RotateTransformOperation::create(0, TransformOperation::Rotate)); | 205 RotateTransformOperation::create(0, TransformOperation::Rotate)); |
206 toOps.operations().append( | 206 toOps.operations().push_back( |
207 RotateTransformOperation::create(360, TransformOperation::Rotate)); | 207 RotateTransformOperation::create(360, TransformOperation::Rotate)); |
208 float sqrt2 = sqrt(2.0f); | 208 float sqrt2 = sqrt(2.0f); |
209 FloatBox box(-sqrt2, -sqrt2, 0, sqrt2, sqrt2, 0); | 209 FloatBox box(-sqrt2, -sqrt2, 0, sqrt2, sqrt2, 0); |
210 FloatBox bounds; | 210 FloatBox bounds; |
211 | 211 |
212 // Since we're rotating 360 degrees, any box with dimensions between 0 and | 212 // Since we're rotating 360 degrees, any box with dimensions between 0 and |
213 // 2 * sqrt(2) should give the same result. | 213 // 2 * sqrt(2) should give the same result. |
214 float sizes[] = {0, 0.1f, sqrt2, 2 * sqrt2}; | 214 float sizes[] = {0, 0.1f, sqrt2, 2 * sqrt2}; |
215 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | 215 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); |
216 for (size_t i = 0; i < WTF_ARRAY_LENGTH(sizes); ++i) { | 216 for (size_t i = 0; i < WTF_ARRAY_LENGTH(sizes); ++i) { |
217 box.setSize(FloatPoint3D(sizes[i], sizes[i], 0)); | 217 box.setSize(FloatPoint3D(sizes[i], sizes[i], 0)); |
218 | 218 |
219 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 219 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
220 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 220 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
221 FloatBox(-2, -2, 0, 4, 4, 0), bounds); | 221 FloatBox(-2, -2, 0, 4, 4, 0), bounds); |
222 } | 222 } |
223 } | 223 } |
224 | 224 |
225 TEST(TransformOperationsTest, AbsoluteAnimatedExtremeRotationBounds) { | 225 TEST(TransformOperationsTest, AbsoluteAnimatedExtremeRotationBounds) { |
226 // If the normal is off-plane, we can have up to 6 exrema (min/max in each | 226 // If the normal is off-plane, we can have up to 6 exrema (min/max in each |
227 // dimension between) the endpoints of the arg. This makes sure we are | 227 // dimension between) the endpoints of the arg. This makes sure we are |
228 // catching all 6. | 228 // catching all 6. |
229 TransformOperations fromOps; | 229 TransformOperations fromOps; |
230 TransformOperations toOps; | 230 TransformOperations toOps; |
231 fromOps.operations().append(RotateTransformOperation::create( | 231 fromOps.operations().push_back(RotateTransformOperation::create( |
232 1, 1, 1, 30, TransformOperation::Rotate3D)); | 232 1, 1, 1, 30, TransformOperation::Rotate3D)); |
233 toOps.operations().append(RotateTransformOperation::create( | 233 toOps.operations().push_back(RotateTransformOperation::create( |
234 1, 1, 1, 390, TransformOperation::Rotate3D)); | 234 1, 1, 1, 390, TransformOperation::Rotate3D)); |
235 | 235 |
236 FloatBox box(1, 0, 0, 0, 0, 0); | 236 FloatBox box(1, 0, 0, 0, 0, 0); |
237 FloatBox bounds; | 237 FloatBox bounds; |
238 float min = -1 / 3.0f; | 238 float min = -1 / 3.0f; |
239 float max = 1; | 239 float max = 1; |
240 float size = max - min; | 240 float size = max - min; |
241 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 241 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
242 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 242 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
243 FloatBox(min, min, min, size, size, size), bounds); | 243 FloatBox(min, min, min, size, size, size), bounds); |
244 } | 244 } |
245 | 245 |
246 TEST(TransformOperationsTest, AbsoluteAnimatedAxisRotationBounds) { | 246 TEST(TransformOperationsTest, AbsoluteAnimatedAxisRotationBounds) { |
247 // We can handle rotations about a single axis. If the axes are different, | 247 // We can handle rotations about a single axis. If the axes are different, |
248 // we revert to matrix interpolation for which inflated bounds cannot be | 248 // we revert to matrix interpolation for which inflated bounds cannot be |
249 // computed. | 249 // computed. |
250 TransformOperations fromOps; | 250 TransformOperations fromOps; |
251 TransformOperations toSame; | 251 TransformOperations toSame; |
252 TransformOperations toOpposite; | 252 TransformOperations toOpposite; |
253 TransformOperations toDifferent; | 253 TransformOperations toDifferent; |
254 fromOps.operations().append(RotateTransformOperation::create( | 254 fromOps.operations().push_back(RotateTransformOperation::create( |
255 1, 1, 1, 30, TransformOperation::Rotate3D)); | 255 1, 1, 1, 30, TransformOperation::Rotate3D)); |
256 toSame.operations().append(RotateTransformOperation::create( | 256 toSame.operations().push_back(RotateTransformOperation::create( |
257 1, 1, 1, 390, TransformOperation::Rotate3D)); | 257 1, 1, 1, 390, TransformOperation::Rotate3D)); |
258 toOpposite.operations().append(RotateTransformOperation::create( | 258 toOpposite.operations().push_back(RotateTransformOperation::create( |
259 -1, -1, -1, 390, TransformOperation::Rotate3D)); | 259 -1, -1, -1, 390, TransformOperation::Rotate3D)); |
260 toDifferent.operations().append(RotateTransformOperation::create( | 260 toDifferent.operations().push_back(RotateTransformOperation::create( |
261 1, 3, 1, 390, TransformOperation::Rotate3D)); | 261 1, 3, 1, 390, TransformOperation::Rotate3D)); |
262 | 262 |
263 FloatBox box(1, 0, 0, 0, 0, 0); | 263 FloatBox box(1, 0, 0, 0, 0, 0); |
264 FloatBox bounds; | 264 FloatBox bounds; |
265 EXPECT_TRUE(toSame.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 265 EXPECT_TRUE(toSame.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
266 EXPECT_FALSE(toOpposite.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 266 EXPECT_FALSE(toOpposite.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
267 EXPECT_FALSE(toDifferent.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 267 EXPECT_FALSE(toDifferent.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
268 } | 268 } |
269 | 269 |
270 TEST(TransformOperationsTest, AbsoluteAnimatedOnAxisRotationBounds) { | 270 TEST(TransformOperationsTest, AbsoluteAnimatedOnAxisRotationBounds) { |
271 // If we rotate a point that is on the axis of rotation, the box should not | 271 // If we rotate a point that is on the axis of rotation, the box should not |
272 // change at all. | 272 // change at all. |
273 TransformOperations fromOps; | 273 TransformOperations fromOps; |
274 TransformOperations toOps; | 274 TransformOperations toOps; |
275 fromOps.operations().append(RotateTransformOperation::create( | 275 fromOps.operations().push_back(RotateTransformOperation::create( |
276 1, 1, 1, 30, TransformOperation::Rotate3D)); | 276 1, 1, 1, 30, TransformOperation::Rotate3D)); |
277 toOps.operations().append(RotateTransformOperation::create( | 277 toOps.operations().push_back(RotateTransformOperation::create( |
278 1, 1, 1, 390, TransformOperation::Rotate3D)); | 278 1, 1, 1, 390, TransformOperation::Rotate3D)); |
279 | 279 |
280 FloatBox box(1, 1, 1, 0, 0, 0); | 280 FloatBox box(1, 1, 1, 0, 0, 0); |
281 FloatBox bounds; | 281 FloatBox bounds; |
282 | 282 |
283 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 283 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
284 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, box, bounds); | 284 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, box, bounds); |
285 } | 285 } |
286 | 286 |
287 // This would have been best as anonymous structs, but |WTF_ARRAY_LENGTH| | 287 // This would have been best as anonymous structs, but |WTF_ARRAY_LENGTH| |
(...skipping 24 matching lines...) Expand all Loading... |
312 {0, 0, 1, FloatBox(-dim2, -dim2, 1, dim3, dim3, 0)}, | 312 {0, 0, 1, FloatBox(-dim2, -dim2, 1, dim3, dim3, 0)}, |
313 {1, 1, 0, FloatBox(dim1, dim1, -1, dim2, dim2, 2)}, | 313 {1, 1, 0, FloatBox(dim1, dim1, -1, dim2, dim2, 2)}, |
314 {0, 1, 1, FloatBox(-1, dim1, dim1, 2, dim2, dim2)}, | 314 {0, 1, 1, FloatBox(-1, dim1, dim1, 2, dim2, dim2)}, |
315 {1, 0, 1, FloatBox(dim1, -1, dim1, dim2, 2, dim2)}}; | 315 {1, 0, 1, FloatBox(dim1, -1, dim1, dim2, 2, dim2)}}; |
316 | 316 |
317 for (size_t i = 0; i < WTF_ARRAY_LENGTH(tests); ++i) { | 317 for (size_t i = 0; i < WTF_ARRAY_LENGTH(tests); ++i) { |
318 float x = tests[i].x; | 318 float x = tests[i].x; |
319 float y = tests[i].y; | 319 float y = tests[i].y; |
320 float z = tests[i].z; | 320 float z = tests[i].z; |
321 TransformOperations fromOps; | 321 TransformOperations fromOps; |
322 fromOps.operations().append(RotateTransformOperation::create( | 322 fromOps.operations().push_back(RotateTransformOperation::create( |
323 x, y, z, 0, TransformOperation::Rotate3D)); | 323 x, y, z, 0, TransformOperation::Rotate3D)); |
324 TransformOperations toOps; | 324 TransformOperations toOps; |
325 toOps.operations().append(RotateTransformOperation::create( | 325 toOps.operations().push_back(RotateTransformOperation::create( |
326 x, y, z, 360, TransformOperation::Rotate3D)); | 326 x, y, z, 360, TransformOperation::Rotate3D)); |
327 FloatBox box(1, 1, 1, 0, 0, 0); | 327 FloatBox box(1, 1, 1, 0, 0, 0); |
328 FloatBox bounds; | 328 FloatBox bounds; |
329 | 329 |
330 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 330 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
331 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, tests[i].expected, | 331 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, tests[i].expected, |
332 bounds); | 332 bounds); |
333 } | 333 } |
334 } | 334 } |
335 | 335 |
(...skipping 13 matching lines...) Expand all Loading... |
349 for (size_t i = 0; i < WTF_ARRAY_LENGTH(axes); ++i) { | 349 for (size_t i = 0; i < WTF_ARRAY_LENGTH(axes); ++i) { |
350 for (size_t j = 0; j < WTF_ARRAY_LENGTH(angles); ++j) { | 350 for (size_t j = 0; j < WTF_ARRAY_LENGTH(angles); ++j) { |
351 for (size_t k = 0; k < WTF_ARRAY_LENGTH(progress); ++k) { | 351 for (size_t k = 0; k < WTF_ARRAY_LENGTH(progress); ++k) { |
352 float x = axes[i][0]; | 352 float x = axes[i][0]; |
353 float y = axes[i][1]; | 353 float y = axes[i][1]; |
354 float z = axes[i][2]; | 354 float z = axes[i][2]; |
355 | 355 |
356 TransformOperations fromOps; | 356 TransformOperations fromOps; |
357 TransformOperations toOps; | 357 TransformOperations toOps; |
358 | 358 |
359 fromOps.operations().append(RotateTransformOperation::create( | 359 fromOps.operations().push_back(RotateTransformOperation::create( |
360 x, y, z, angles[j][0], TransformOperation::Rotate3D)); | 360 x, y, z, angles[j][0], TransformOperation::Rotate3D)); |
361 toOps.operations().append(RotateTransformOperation::create( | 361 toOps.operations().push_back(RotateTransformOperation::create( |
362 x, y, z, angles[j][1], TransformOperation::Rotate3D)); | 362 x, y, z, angles[j][1], TransformOperation::Rotate3D)); |
363 EmpiricallyTestBounds(fromOps, toOps, progress[k][0], progress[k][1]); | 363 EmpiricallyTestBounds(fromOps, toOps, progress[k][0], progress[k][1]); |
364 } | 364 } |
365 } | 365 } |
366 } | 366 } |
367 } | 367 } |
368 | 368 |
369 TEST(TransformOperationsTest, AbsoluteAnimatedPerspectiveBoundsTest) { | 369 TEST(TransformOperationsTest, AbsoluteAnimatedPerspectiveBoundsTest) { |
370 TransformOperations fromOps; | 370 TransformOperations fromOps; |
371 TransformOperations toOps; | 371 TransformOperations toOps; |
372 fromOps.operations().append(PerspectiveTransformOperation::create(20)); | 372 fromOps.operations().push_back(PerspectiveTransformOperation::create(20)); |
373 toOps.operations().append(PerspectiveTransformOperation::create(40)); | 373 toOps.operations().push_back(PerspectiveTransformOperation::create(40)); |
374 FloatBox box(0, 0, 0, 10, 10, 10); | 374 FloatBox box(0, 0, 0, 10, 10, 10); |
375 FloatBox bounds; | 375 FloatBox bounds; |
376 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | 376 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); |
377 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 377 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
378 FloatBox(0, 0, 0, 20, 20, 20), bounds); | 378 FloatBox(0, 0, 0, 20, 20, 20), bounds); |
379 | 379 |
380 fromOps.blendedBoundsForBox(box, toOps, -0.25, 1.25, &bounds); | 380 fromOps.blendedBoundsForBox(box, toOps, -0.25, 1.25, &bounds); |
381 // The perspective range was [20, 40] and blending will extrapolate that to | 381 // The perspective range was [20, 40] and blending will extrapolate that to |
382 // [17, 53]. The cube has w/h/d of 10 and the observer is at 17, so the face | 382 // [17, 53]. The cube has w/h/d of 10 and the observer is at 17, so the face |
383 // closest the observer is 17-10=7. | 383 // closest the observer is 17-10=7. |
384 double projectedSize = 10.0 / 7.0 * 17.0; | 384 double projectedSize = 10.0 / 7.0 * 17.0; |
385 EXPECT_PRED_FORMAT2( | 385 EXPECT_PRED_FORMAT2( |
386 FloatBoxTest::AssertAlmostEqual, | 386 FloatBoxTest::AssertAlmostEqual, |
387 FloatBox(0, 0, 0, projectedSize, projectedSize, projectedSize), bounds); | 387 FloatBox(0, 0, 0, projectedSize, projectedSize, projectedSize), bounds); |
388 } | 388 } |
389 | 389 |
390 TEST(TransformOperationsTest, EmpiricalAnimatedPerspectiveBoundsTest) { | 390 TEST(TransformOperationsTest, EmpiricalAnimatedPerspectiveBoundsTest) { |
391 float depths[][2] = { | 391 float depths[][2] = { |
392 {600, 400}, {800, 1000}, {800, std::numeric_limits<float>::infinity()}}; | 392 {600, 400}, {800, 1000}, {800, std::numeric_limits<float>::infinity()}}; |
393 | 393 |
394 float progress[][2] = {{0, 1}, {-0.1f, 1.1f}}; | 394 float progress[][2] = {{0, 1}, {-0.1f, 1.1f}}; |
395 | 395 |
396 for (size_t i = 0; i < WTF_ARRAY_LENGTH(depths); ++i) { | 396 for (size_t i = 0; i < WTF_ARRAY_LENGTH(depths); ++i) { |
397 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | 397 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { |
398 TransformOperations fromOps; | 398 TransformOperations fromOps; |
399 TransformOperations toOps; | 399 TransformOperations toOps; |
400 | 400 |
401 fromOps.operations().append( | 401 fromOps.operations().push_back( |
402 PerspectiveTransformOperation::create(depths[i][0])); | 402 PerspectiveTransformOperation::create(depths[i][0])); |
403 toOps.operations().append( | 403 toOps.operations().push_back( |
404 PerspectiveTransformOperation::create(depths[i][1])); | 404 PerspectiveTransformOperation::create(depths[i][1])); |
405 | 405 |
406 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); | 406 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1]); |
407 } | 407 } |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 TEST(TransformOperationsTest, AnimatedSkewBoundsTest) { | 411 TEST(TransformOperationsTest, AnimatedSkewBoundsTest) { |
412 TransformOperations fromOps; | 412 TransformOperations fromOps; |
413 TransformOperations toOps; | 413 TransformOperations toOps; |
414 fromOps.operations().append( | 414 fromOps.operations().push_back( |
415 SkewTransformOperation::create(-45, 0, TransformOperation::Skew)); | 415 SkewTransformOperation::create(-45, 0, TransformOperation::Skew)); |
416 toOps.operations().append( | 416 toOps.operations().push_back( |
417 SkewTransformOperation::create(0, 45, TransformOperation::Skew)); | 417 SkewTransformOperation::create(0, 45, TransformOperation::Skew)); |
418 FloatBox box(0, 0, 0, 10, 10, 10); | 418 FloatBox box(0, 0, 0, 10, 10, 10); |
419 FloatBox bounds; | 419 FloatBox bounds; |
420 | 420 |
421 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds); | 421 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds); |
422 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 422 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
423 FloatBox(0, 0, 0, 10, 20, 10), bounds); | 423 FloatBox(0, 0, 0, 10, 20, 10), bounds); |
424 | 424 |
425 identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | 425 identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); |
426 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 426 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
427 FloatBox(-10, 0, 0, 20, 10, 10), bounds); | 427 FloatBox(-10, 0, 0, 20, 10, 10), bounds); |
428 | 428 |
429 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | 429 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); |
430 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 430 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
431 FloatBox(-10, 0, 0, 20, 20, 10), bounds); | 431 FloatBox(-10, 0, 0, 20, 20, 10), bounds); |
432 | 432 |
433 fromOps.blendedBoundsForBox(box, toOps, 0, 1, &bounds); | 433 fromOps.blendedBoundsForBox(box, toOps, 0, 1, &bounds); |
434 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 434 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
435 FloatBox(-10, 0, 0, 20, 20, 10), bounds); | 435 FloatBox(-10, 0, 0, 20, 20, 10), bounds); |
436 } | 436 } |
437 | 437 |
438 TEST(TransformOperationsTest, NonCommutativeRotations) { | 438 TEST(TransformOperationsTest, NonCommutativeRotations) { |
439 TransformOperations fromOps; | 439 TransformOperations fromOps; |
440 fromOps.operations().append(RotateTransformOperation::create( | 440 fromOps.operations().push_back(RotateTransformOperation::create( |
441 1, 0, 0, 0, TransformOperation::Rotate3D)); | 441 1, 0, 0, 0, TransformOperation::Rotate3D)); |
442 fromOps.operations().append(RotateTransformOperation::create( | 442 fromOps.operations().push_back(RotateTransformOperation::create( |
443 0, 1, 0, 0, TransformOperation::Rotate3D)); | 443 0, 1, 0, 0, TransformOperation::Rotate3D)); |
444 TransformOperations toOps; | 444 TransformOperations toOps; |
445 toOps.operations().append(RotateTransformOperation::create( | 445 toOps.operations().push_back(RotateTransformOperation::create( |
446 1, 0, 0, 45, TransformOperation::Rotate3D)); | 446 1, 0, 0, 45, TransformOperation::Rotate3D)); |
447 toOps.operations().append(RotateTransformOperation::create( | 447 toOps.operations().push_back(RotateTransformOperation::create( |
448 0, 1, 0, 135, TransformOperation::Rotate3D)); | 448 0, 1, 0, 135, TransformOperation::Rotate3D)); |
449 | 449 |
450 FloatBox box(0, 0, 0, 1, 1, 1); | 450 FloatBox box(0, 0, 0, 1, 1, 1); |
451 FloatBox bounds; | 451 FloatBox bounds; |
452 | 452 |
453 double minProgress = 0; | 453 double minProgress = 0; |
454 double maxProgress = 1; | 454 double maxProgress = 1; |
455 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, minProgress, maxProgress, | 455 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, minProgress, maxProgress, |
456 &bounds)); | 456 &bounds)); |
457 | 457 |
458 TransformOperations operations = toOps.blend(fromOps, maxProgress); | 458 TransformOperations operations = toOps.blend(fromOps, maxProgress); |
459 TransformationMatrix blendedTransform; | 459 TransformationMatrix blendedTransform; |
460 operations.apply(FloatSize(0, 0), blendedTransform); | 460 operations.apply(FloatSize(0, 0), blendedTransform); |
461 | 461 |
462 FloatPoint3D blendedPoint(0.9f, 0.9f, 0); | 462 FloatPoint3D blendedPoint(0.9f, 0.9f, 0); |
463 blendedPoint = blendedTransform.mapPoint(blendedPoint); | 463 blendedPoint = blendedTransform.mapPoint(blendedPoint); |
464 FloatBox expandedBounds = bounds; | 464 FloatBox expandedBounds = bounds; |
465 expandedBounds.expandTo(blendedPoint); | 465 expandedBounds.expandTo(blendedPoint); |
466 | 466 |
467 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, bounds, expandedBounds); | 467 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, bounds, expandedBounds); |
468 } | 468 } |
469 | 469 |
470 TEST(TransformOperationsTest, AbsoluteSequenceBoundsTest) { | 470 TEST(TransformOperationsTest, AbsoluteSequenceBoundsTest) { |
471 TransformOperations fromOps; | 471 TransformOperations fromOps; |
472 TransformOperations toOps; | 472 TransformOperations toOps; |
473 | 473 |
474 fromOps.operations().append(TranslateTransformOperation::create( | 474 fromOps.operations().push_back(TranslateTransformOperation::create( |
475 Length(1, Fixed), Length(-5, Fixed), 1, TransformOperation::Translate3D)); | 475 Length(1, Fixed), Length(-5, Fixed), 1, TransformOperation::Translate3D)); |
476 fromOps.operations().append( | 476 fromOps.operations().push_back( |
477 ScaleTransformOperation::create(-1, 2, 3, TransformOperation::Scale3D)); | 477 ScaleTransformOperation::create(-1, 2, 3, TransformOperation::Scale3D)); |
478 fromOps.operations().append(TranslateTransformOperation::create( | 478 fromOps.operations().push_back(TranslateTransformOperation::create( |
479 Length(2, Fixed), Length(4, Fixed), -1, TransformOperation::Translate3D)); | 479 Length(2, Fixed), Length(4, Fixed), -1, TransformOperation::Translate3D)); |
480 | 480 |
481 toOps.operations().append( | 481 toOps.operations().push_back( |
482 TranslateTransformOperation::create(Length(13, Fixed), Length(-1, Fixed), | 482 TranslateTransformOperation::create(Length(13, Fixed), Length(-1, Fixed), |
483 5, TransformOperation::Translate3D)); | 483 5, TransformOperation::Translate3D)); |
484 toOps.operations().append( | 484 toOps.operations().push_back( |
485 ScaleTransformOperation::create(-3, -2, 5, TransformOperation::Scale3D)); | 485 ScaleTransformOperation::create(-3, -2, 5, TransformOperation::Scale3D)); |
486 toOps.operations().append(TranslateTransformOperation::create( | 486 toOps.operations().push_back(TranslateTransformOperation::create( |
487 Length(6, Fixed), Length(-2, Fixed), 3, TransformOperation::Translate3D)); | 487 Length(6, Fixed), Length(-2, Fixed), 3, TransformOperation::Translate3D)); |
488 | 488 |
489 FloatBox box(1, 2, 3, 4, 4, 4); | 489 FloatBox box(1, 2, 3, 4, 4, 4); |
490 FloatBox bounds; | 490 FloatBox bounds; |
491 | 491 |
492 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, -0.5, 1.5, &bounds)); | 492 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, -0.5, 1.5, &bounds)); |
493 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 493 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
494 FloatBox(-57, -59, -1, 76, 112, 80), bounds); | 494 FloatBox(-57, -59, -1, 76, 112, 80), bounds); |
495 | 495 |
496 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | 496 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); |
(...skipping 10 matching lines...) Expand all Loading... |
507 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, | 507 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, |
508 FloatBox(-7, -3, 2, 15, 23, 20), bounds); | 508 FloatBox(-7, -3, 2, 15, 23, 20), bounds); |
509 } | 509 } |
510 | 510 |
511 TEST(TransformOperationsTest, ZoomTest) { | 511 TEST(TransformOperationsTest, ZoomTest) { |
512 double zoomFactor = 1.25; | 512 double zoomFactor = 1.25; |
513 | 513 |
514 FloatPoint3D originalPoint(2, 3, 4); | 514 FloatPoint3D originalPoint(2, 3, 4); |
515 | 515 |
516 TransformOperations ops; | 516 TransformOperations ops; |
517 ops.operations().append(TranslateTransformOperation::create( | 517 ops.operations().push_back(TranslateTransformOperation::create( |
518 Length(1, Fixed), Length(2, Fixed), 3, TransformOperation::Translate3D)); | 518 Length(1, Fixed), Length(2, Fixed), 3, TransformOperation::Translate3D)); |
519 ops.operations().append(PerspectiveTransformOperation::create(1234)); | 519 ops.operations().push_back(PerspectiveTransformOperation::create(1234)); |
520 ops.operations().append( | 520 ops.operations().push_back( |
521 Matrix3DTransformOperation::create(TransformationMatrix( | 521 Matrix3DTransformOperation::create(TransformationMatrix( |
522 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))); | 522 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16))); |
523 | 523 |
524 // Apply unzoomed ops to unzoomed units, then zoom in | 524 // Apply unzoomed ops to unzoomed units, then zoom in |
525 FloatPoint3D unzoomedPoint = originalPoint; | 525 FloatPoint3D unzoomedPoint = originalPoint; |
526 TransformOperations unzoomedOps = ops; | 526 TransformOperations unzoomedOps = ops; |
527 TransformationMatrix unzoomedMatrix; | 527 TransformationMatrix unzoomedMatrix; |
528 ops.apply(FloatSize(0, 0), unzoomedMatrix); | 528 ops.apply(FloatSize(0, 0), unzoomedMatrix); |
529 FloatPoint3D result1 = unzoomedMatrix.mapPoint(unzoomedPoint); | 529 FloatPoint3D result1 = unzoomedMatrix.mapPoint(unzoomedPoint); |
530 result1.scale(zoomFactor, zoomFactor, zoomFactor); | 530 result1.scale(zoomFactor, zoomFactor, zoomFactor); |
531 | 531 |
532 // Apply zoomed ops to zoomed units | 532 // Apply zoomed ops to zoomed units |
533 FloatPoint3D zoomedPoint = originalPoint; | 533 FloatPoint3D zoomedPoint = originalPoint; |
534 zoomedPoint.scale(zoomFactor, zoomFactor, zoomFactor); | 534 zoomedPoint.scale(zoomFactor, zoomFactor, zoomFactor); |
535 TransformOperations zoomedOps = ops.zoom(zoomFactor); | 535 TransformOperations zoomedOps = ops.zoom(zoomFactor); |
536 TransformationMatrix zoomedMatrix; | 536 TransformationMatrix zoomedMatrix; |
537 zoomedOps.apply(FloatSize(0, 0), zoomedMatrix); | 537 zoomedOps.apply(FloatSize(0, 0), zoomedMatrix); |
538 FloatPoint3D result2 = zoomedMatrix.mapPoint(zoomedPoint); | 538 FloatPoint3D result2 = zoomedMatrix.mapPoint(zoomedPoint); |
539 | 539 |
540 EXPECT_EQ(result1, result2); | 540 EXPECT_EQ(result1, result2); |
541 } | 541 } |
542 | 542 |
543 } // namespace blink | 543 } // namespace blink |
OLD | NEW |