Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions | |
| 6 * are met: | |
| 7 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN Y | |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| 16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN Y | |
| 17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
| 18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
| 19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O N | |
| 20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 23 */ | |
| 24 | |
| 25 #include "config.h" | |
| 26 #include "platform/transforms/TransformOperations.h" | |
| 27 | |
| 28 #include "platform/geometry/FloatBox.h" | |
| 29 #include "platform/geometry/FloatBoxTestHelpers.h" | |
| 30 #include "platform/transforms/IdentityTransformOperation.h" | |
| 31 #include "platform/transforms/Matrix3DTransformOperation.h" | |
| 32 #include "platform/transforms/MatrixTransformOperation.h" | |
| 33 #include "platform/transforms/PerspectiveTransformOperation.h" | |
| 34 #include "platform/transforms/RotateTransformOperation.h" | |
| 35 #include "platform/transforms/ScaleTransformOperation.h" | |
| 36 #include "platform/transforms/SkewTransformOperation.h" | |
| 37 #include "platform/transforms/TranslateTransformOperation.h" | |
| 38 | |
| 39 #include <gtest/gtest.h> | |
| 40 | |
| 41 using namespace WebCore; | |
| 42 namespace { | |
| 43 | |
| 44 static const TransformOperations identityOperations; | |
| 45 | |
| 46 static void EmpiricallyTestBounds(const TransformOperations& from, | |
| 47 const TransformOperations& to, | |
| 48 const double& minProgress, | |
| 49 const double& maxProgress) | |
| 50 { | |
| 51 FloatBox box(200, 500, 100, 100, 300, 200); | |
| 52 FloatBox bounds; | |
| 53 | |
| 54 EXPECT_TRUE(to.blendedBoundsForBox(box, from, minProgress, maxProgress, &bou nds)); | |
| 55 bool firstTime= true; | |
|
Ian Vollick
2014/06/17 15:54:56
nit: ws
awoloszyn
2014/06/17 20:06:03
Done.
| |
| 56 | |
| 57 FloatBox empiricalBounds; | |
| 58 static const size_t numSteps = 10; | |
| 59 for (size_t step = 0; step < numSteps; ++step) { | |
| 60 float t = step / (numSteps - 1); | |
| 61 t = minProgress + (maxProgress - minProgress) * t; | |
| 62 TransformOperations operations = from.blend(to, t); | |
| 63 TransformationMatrix matrix; | |
| 64 operations.apply(FloatSize(0, 0), matrix); | |
| 65 FloatBox transformed = box; | |
| 66 matrix.transformBox(transformed); | |
| 67 | |
| 68 if (firstTime) | |
| 69 empiricalBounds = transformed; | |
| 70 else | |
| 71 empiricalBounds.unionBounds(transformed); | |
| 72 firstTime = false; | |
| 73 } | |
| 74 | |
| 75 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertContains, bounds, empiricalBounds); | |
| 76 } | |
| 77 | |
| 78 TEST(TransformOperationsTest, AbsoluteAnimatedTranslatedBoundsTest) | |
| 79 { | |
| 80 TransformOperations fromOps; | |
| 81 TransformOperations toOps; | |
| 82 fromOps.operations().append(TranslateTransformOperation::create(Length(-30, WebCore::Fixed), Length(20, WebCore::Fixed), 15, TransformOperation::Translate3D )); | |
| 83 toOps.operations().append(TranslateTransformOperation::create(Length(10, Web Core::Fixed), Length(10, WebCore::Fixed), 200, TransformOperation::Translate3D)) ; | |
| 84 FloatBox box(0, 0, 0, 10, 10, 10); | |
| 85 FloatBox bounds; | |
| 86 | |
| 87 EXPECT_TRUE(toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds )); | |
| 88 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 20, 2 0, 210), bounds); | |
| 89 | |
| 90 EXPECT_TRUE(identityOperations.blendedBoundsForBox(box, toOps, 0, 1, &bounds )); | |
| 91 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 20, 2 0, 210), bounds); | |
| 92 | |
| 93 EXPECT_TRUE(identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &boun ds)); | |
| 94 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-30, 0, 0, 40, 30, 25), bounds); | |
| 95 | |
| 96 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 97 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-30, 10, 15, 5 0, 20, 195), bounds); | |
| 98 | |
| 99 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, -0.5, 1.25, &bounds)); | |
| 100 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-50, 7.5, -77. 5, 80, 27.5, 333.75), bounds); | |
| 101 | |
|
Ian Vollick
2014/06/17 15:54:56
nit: extra ws.
awoloszyn
2014/06/17 20:06:03
Done.
| |
| 102 } | |
| 103 | |
| 104 TEST(TransformOperationsTest, EmpiricalAnimatedTranslatedBoundsTest) | |
| 105 { | |
| 106 float testTransforms[][2][3] = { | |
| 107 { { 0, 0, 0 }, { 10, 10, 0 } } , | |
| 108 { { -100, 202.5, -32.6 }, { 43.2, 56.1, 89.75 } }, | |
| 109 { { 43.2, 56.1, 89.75 }, { -100, 202.5, -32.6 } } | |
| 110 }; | |
| 111 | |
| 112 // All progressions for animations start and end at 0, 1 respectively, | |
| 113 // we can go outside of these bounds, but will always at least contain | |
| 114 // [0,1]. | |
| 115 float progress[][2] = { | |
| 116 { 0, 1 }, | |
| 117 { -.25, 1.25 } | |
| 118 }; | |
| 119 | |
| 120 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { | |
| 121 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | |
| 122 TransformOperations fromOps; | |
| 123 TransformOperations toOps; | |
| 124 fromOps.operations().append(TranslateTransformOperation::create(Leng th(testTransforms[i][0][0], WebCore::Fixed), Length(testTransforms[i][0][1], Web Core::Fixed), testTransforms[i][0][2], TransformOperation::Translate3D)); | |
| 125 toOps.operations().append(TranslateTransformOperation::create(Length (testTransforms[i][1][0], WebCore::Fixed), Length(testTransforms[i][1][1], WebCo re::Fixed), testTransforms[i][1][2], TransformOperation::Translate3D)); | |
| 126 EmpiricallyTestBounds(fromOps, toOps, 0, 1); | |
| 127 } | |
| 128 } | |
| 129 } | |
| 130 | |
| 131 TEST(TransformOperationsTest, AbsoluteAnimatedScaleBoundsTest) | |
| 132 { | |
| 133 TransformOperations fromOps; | |
| 134 TransformOperations toOps; | |
| 135 fromOps.operations().append(ScaleTransformOperation::create(4, -3, Transform Operation::Scale)); | |
| 136 toOps.operations().append(ScaleTransformOperation::create(5, 2, TransformOpe ration::Scale)); | |
| 137 | |
| 138 FloatBox box(0, 0, 0, 10, 10, 10); | |
| 139 FloatBox bounds; | |
| 140 | |
|
Ian Vollick
2014/06/17 15:54:56
nit: extra ws.
awoloszyn
2014/06/17 20:06:03
Done.
| |
| 141 | |
| 142 EXPECT_TRUE(toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds )); | |
| 143 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 50, 2 0, 10), bounds); | |
| 144 | |
| 145 EXPECT_TRUE(identityOperations.blendedBoundsForBox(box, toOps, 0, 1, &bounds )); | |
| 146 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 50, 2 0, 10), bounds); | |
| 147 | |
| 148 EXPECT_TRUE(identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &boun ds)); | |
| 149 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, -30, 0, 40, 40, 10), bounds); | |
| 150 | |
| 151 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 152 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, -30, 0, 50, 50, 10), bounds); | |
| 153 | |
| 154 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, -0.5, 1.25, &bounds)); | |
| 155 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, -55, 0, 52. 5, 87.5, 10), bounds); | |
| 156 } | |
| 157 | |
| 158 TEST(TransformOperationsTest, EmpiricalAnimatedScaleBoundsTest) | |
| 159 { | |
| 160 | |
| 161 float testTransforms[][2][3] = { | |
| 162 { { 1, 1, 1 }, { 10, 10, -32}}, | |
| 163 { { 1, 2, 5 }, { -1, -2, -4}}, | |
| 164 { { 0, 0, 0 }, { 1, 2, 3}}, | |
| 165 { { 0, 0, 0 }, { 0, 0, 0}} | |
| 166 }; | |
| 167 | |
| 168 // All progressions for animations start and end at 0, 1 respectively, | |
| 169 // we can go outside of these bounds, but will always at least contain | |
| 170 // [0,1]. | |
| 171 float progress[][2] = { | |
| 172 { 0, 1 }, | |
| 173 { -.25f, 1.25f } | |
| 174 }; | |
| 175 | |
| 176 for (size_t i = 0; i < WTF_ARRAY_LENGTH(testTransforms); ++i) { | |
| 177 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | |
| 178 TransformOperations fromOps; | |
| 179 TransformOperations toOps; | |
| 180 fromOps.operations().append(TranslateTransformOperation::create(Leng th(testTransforms[i][0][0], WebCore::Fixed), Length(testTransforms[i][0][1], Web Core::Fixed), testTransforms[i][0][2], TransformOperation::Translate3D)); | |
| 181 toOps.operations().append(TranslateTransformOperation::create(Length (testTransforms[i][1][0], WebCore::Fixed), Length(testTransforms[i][1][1], WebCo re::Fixed), testTransforms[i][1][2], TransformOperation::Translate3D)); | |
| 182 EmpiricallyTestBounds(fromOps, toOps, 0, 1); | |
| 183 } | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 TEST(TransformOperationsTest, AbsoluteAnimatedRotationBounds) | |
| 188 { | |
| 189 TransformOperations fromOps; | |
| 190 TransformOperations toOps; | |
| 191 fromOps.operations().append(RotateTransformOperation::create(0, TransformOpe ration::Rotate)); | |
| 192 toOps.operations().append(RotateTransformOperation::create(360, TransformOpe ration::Rotate)); | |
| 193 float sqrt2 = sqrt(2); | |
| 194 FloatBox box(-sqrt2, -sqrt2, 0, sqrt2, sqrt2, 0); | |
| 195 FloatBox bounds; | |
| 196 | |
| 197 // Since we're rotating 360 degrees, any box with dimensions between 0 and | |
| 198 // 2 * sqrt(2) should give the same result; | |
|
Ian Vollick
2014/06/17 15:54:56
nit s/;/./
awoloszyn
2014/06/17 20:06:03
Done.
| |
| 199 float sizes[] = { 0, 0.1f, sqrt2, 2*sqrt2 }; | |
| 200 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | |
| 201 for (size_t i = 0; i < WTF_ARRAY_LENGTH(sizes); ++i) { | |
| 202 box.setSize(FloatPoint3D(sizes[i], sizes[i], 0)); | |
| 203 | |
| 204 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 205 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-2, -2, 0, 4, 4, 0), bounds); | |
| 206 } | |
| 207 } | |
| 208 | |
| 209 TEST(TransformOperationsTest, AbsoluteAnimatedExtremeRotationBounds) | |
| 210 { | |
| 211 // If the normal is off-plane, we can have up to 6 exrema (min/max in each | |
| 212 // dimension between) the endpoints of the arg. This makes sure we are | |
| 213 // catching all 6. | |
| 214 TransformOperations fromOps; | |
| 215 TransformOperations toOps; | |
| 216 fromOps.operations().append(RotateTransformOperation::create(1, 1, 1, 30, Tr ansformOperation::Rotate3D)); | |
| 217 toOps.operations().append(RotateTransformOperation::create(1, 1, 1, 390, Tr ansformOperation::Rotate3D)); | |
| 218 | |
| 219 FloatBox box(1, 0, 0, 0, 0, 0); | |
| 220 FloatBox bounds; | |
| 221 float min = -1 / 3.0f; | |
| 222 float max = 1; | |
| 223 float size = max - min; | |
| 224 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 225 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(min, min, min, size, size, size), bounds); | |
| 226 } | |
| 227 | |
| 228 TEST(TransformOperationsTest, AbsoluteAnimatedAxisRotationBounds) | |
| 229 { | |
| 230 // We can handle rotations about a single axis. If the axes are different, | |
| 231 // we revert to matrix interpolation for which inflated bounds cannot be | |
| 232 // computed. | |
| 233 TransformOperations fromOps; | |
| 234 TransformOperations toSame; | |
| 235 TransformOperations toOpposite; | |
| 236 TransformOperations toDifferent; | |
| 237 fromOps.operations().append(RotateTransformOperation::create(1, 1, 1, 30, Tr ansformOperation::Rotate3D)); | |
| 238 toSame.operations().append(RotateTransformOperation::create(1, 1, 1, 390, T ransformOperation::Rotate3D)); | |
| 239 toOpposite.operations().append(RotateTransformOperation::create(-1, -1, -1, 390, TransformOperation::Rotate3D)); | |
| 240 toDifferent.operations().append(RotateTransformOperation::create(1, 3, 1, 39 0, TransformOperation::Rotate3D)); | |
| 241 | |
| 242 FloatBox box(1, 0, 0, 0, 0, 0); | |
| 243 FloatBox bounds; | |
| 244 EXPECT_TRUE(toSame.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 245 EXPECT_TRUE(toOpposite.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 246 EXPECT_FALSE(toDifferent.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 247 } | |
| 248 | |
| 249 TEST(TransformOperationsTest, AbsoluteAnimatedOnAxisRotationBounds) | |
| 250 { | |
| 251 // If we rotate a point that is on the axis of rotation, the box should not | |
| 252 // change at all. | |
| 253 TransformOperations fromOps; | |
| 254 TransformOperations toOps; | |
| 255 fromOps.operations().append(RotateTransformOperation::create(1, 1, 1, 30, Tr ansformOperation::Rotate3D)); | |
| 256 toOps.operations().append(RotateTransformOperation::create(1, 1, 1, 390, Tr ansformOperation::Rotate3D)); | |
| 257 | |
| 258 FloatBox box(1, 1, 1, 0, 0, 0); | |
| 259 FloatBox bounds; | |
| 260 | |
| 261 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 262 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, box, bounds); | |
| 263 } | |
| 264 | |
| 265 // This would have been best as anonymous structs, but |WTF_ARRAY_LENGTH| | |
| 266 // does not get along with anonymous structs once we support C++11 | |
| 267 // WTF_ARRAY_LENGTH will automatically support anonymous structs. | |
| 268 | |
| 269 struct ProblematicAxisTest { | |
| 270 double x; | |
| 271 double y; | |
| 272 double z; | |
| 273 FloatBox expected; | |
| 274 }; | |
| 275 | |
| 276 TEST(TransformOperationsTest, AbsoluteAnimatedProblematicAxisRotationBounds) | |
| 277 { | |
| 278 // Zeros in the components of the axis osf rotation turned out to be tricky to | |
| 279 // deal with in practice. This function tests some potentially problematic | |
| 280 // axes to ensure sane behavior. | |
| 281 | |
| 282 // Some common values used in the expected boxes. | |
| 283 float dim1 = 0.292893f; | |
| 284 float dim2 = sqrt(2); | |
| 285 float dim3 = 2 * dim2; | |
| 286 | |
| 287 ProblematicAxisTest tests[] = { | |
| 288 { 0, 0, 0, FloatBox(1, 1, 1, 0, 0, 0) }, | |
| 289 { 1, 0, 0, FloatBox(1, -dim2, -dim2, 0, dim3, dim3) }, | |
| 290 { 0, 1, 0, FloatBox(-dim2, 1, -dim2, dim3, 0, dim3) }, | |
| 291 { 0, 0, 1, FloatBox(-dim2, -dim2, 1, dim3, dim3, 0) }, | |
| 292 { 1, 1, 0, FloatBox(dim1, dim1, -1, dim2, dim2, 2) }, | |
| 293 { 0, 1, 1, FloatBox(-1, dim1, dim1, 2, dim2, dim2) }, | |
| 294 { 1, 0, 1, FloatBox(dim1, -1, dim1, dim2, 2, dim2) } | |
| 295 }; | |
| 296 | |
| 297 for (size_t i = 0; i < WTF_ARRAY_LENGTH(tests); ++i) { | |
| 298 float x = tests[i].x; | |
| 299 float y = tests[i].y; | |
| 300 float z = tests[i].z; | |
| 301 TransformOperations fromOps; | |
| 302 fromOps.operations().append(RotateTransformOperation::create(x, y, z, 0, TransformOperation::Rotate3D)); | |
| 303 TransformOperations toOps; | |
| 304 toOps.operations().append(RotateTransformOperation::create(x, y, z, 360, TransformOperation::Rotate3D)); | |
| 305 FloatBox box(1, 1, 1, 0, 0, 0); | |
| 306 FloatBox bounds; | |
| 307 | |
| 308 EXPECT_TRUE(toOps.blendedBoundsForBox( | |
| 309 box, fromOps, 0, 1, &bounds)); | |
| 310 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, tests[i].expected, bounds); | |
| 311 } | |
| 312 } | |
| 313 | |
| 314 | |
| 315 TEST(TransformOperationsTest, BlendedBoundsForRotationEmpiricalTests) | |
| 316 { | |
| 317 float axes[][3] = { | |
| 318 { 1, 1, 1 }, | |
| 319 { -1, -1, -1 }, | |
| 320 { -1, 2, 3 }, | |
| 321 { 1, -2, 3 }, | |
| 322 { 0, 0, 0 }, | |
| 323 { 1, 0, 0 }, | |
| 324 { 0, 1, 0 }, | |
| 325 { 0, 0, 1 }, | |
| 326 { 1, 1, 0 }, | |
| 327 { 0, 1, 1 }, | |
| 328 { 1, 0, 1 }, | |
| 329 { -1, 0, 0 }, | |
| 330 { 0, -1, 0 }, | |
| 331 { 0, 0, -1 }, | |
| 332 { -1, -1, 0 }, | |
| 333 { 0, -1, -1 }, | |
| 334 { -1, 0, -1 } | |
| 335 }; | |
| 336 | |
| 337 float angles[][2] = { | |
| 338 { 5, 100 }, | |
| 339 { 10, 5 }, | |
| 340 { 0, 360 }, | |
| 341 { 20, 180 }, | |
| 342 { -20, -180 }, | |
| 343 { 180, -220 }, | |
| 344 { 220, 320 }, | |
| 345 { 1020, 1120 }, | |
| 346 {-3200, 120 }, | |
| 347 {-9000, -9050 } | |
| 348 }; | |
| 349 | |
| 350 float progress[][2] = { | |
| 351 { 0, 1 }, | |
| 352 { -0.25f, 1.25f } | |
| 353 }; | |
| 354 | |
| 355 for (size_t i = 0; i < WTF_ARRAY_LENGTH(axes); ++i) { | |
| 356 for (size_t j = 0; j < WTF_ARRAY_LENGTH(angles); ++j) { | |
| 357 for (size_t k = 0; k < WTF_ARRAY_LENGTH(progress); ++k) { | |
| 358 float x = axes[i][0]; | |
| 359 float y = axes[i][1]; | |
| 360 float z = axes[i][2]; | |
| 361 | |
| 362 TransformOperations fromOps; | |
| 363 TransformOperations toOps; | |
| 364 | |
| 365 fromOps.operations().append(RotateTransformOperation::create(x, y, z, angles[j][0], TransformOperation::Rotate3D)); | |
| 366 toOps.operations().append(RotateTransformOperation::create(x, y, z, angles[j][1], TransformOperation::Rotate3D)); | |
| 367 EmpiricallyTestBounds(fromOps, toOps, progress[k][0], progress[k ][1]); | |
| 368 } | |
| 369 } | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 TEST(TransformOperationsTest, AbsoluteAnimatedPerspectiveBoundsTest) | |
| 374 { | |
| 375 TransformOperations fromOps; | |
| 376 TransformOperations toOps; | |
| 377 fromOps.operations().append(PerspectiveTransformOperation::create(10)); | |
| 378 toOps.operations().append(PerspectiveTransformOperation::create(30)); | |
| 379 FloatBox box(0, 0, 0, 10, 10, 10); | |
| 380 FloatBox bounds; | |
| 381 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | |
| 382 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 15, 1 5, 15), bounds); | |
| 383 | |
| 384 fromOps.blendedBoundsForBox(box, toOps, -0.25, 1.25, &bounds); | |
| 385 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-40, -40, -40, 52, 52, 52), bounds); | |
| 386 } | |
| 387 | |
| 388 TEST(TransformOperationsTest, EmpiricalAnimatedPerspectiveBoundsTest) | |
| 389 { | |
| 390 float depths[][2] = { | |
| 391 { 600, 400 }, | |
| 392 { 800, 1000 }, | |
| 393 { 800, std::numeric_limits<float>::infinity() } | |
| 394 }; | |
| 395 | |
| 396 float progress[][2] = { | |
| 397 { 0, 1 }, | |
| 398 {-0.1f, 1.1f } | |
| 399 }; | |
| 400 | |
| 401 for (size_t i = 0; i < WTF_ARRAY_LENGTH(depths); ++i) { | |
| 402 for (size_t j = 0; j < WTF_ARRAY_LENGTH(progress); ++j) { | |
| 403 TransformOperations fromOps; | |
| 404 TransformOperations toOps; | |
| 405 | |
| 406 fromOps.operations().append(PerspectiveTransformOperation::create(de pths[i][0])); | |
| 407 toOps.operations().append(PerspectiveTransformOperation::create(dept hs[i][1])); | |
| 408 | |
| 409 EmpiricallyTestBounds(fromOps, toOps, progress[j][0], progress[j][1] ); | |
| 410 } | |
| 411 } | |
| 412 } | |
| 413 | |
| 414 | |
| 415 TEST(TransformOperationsTest, AnimatedSkewBoundsTest) | |
| 416 { | |
| 417 TransformOperations fromOps; | |
| 418 TransformOperations toOps; | |
| 419 fromOps.operations().append(SkewTransformOperation::create(-45, 0, Transform Operation::Skew)); | |
| 420 toOps.operations().append(SkewTransformOperation::create(0, 45, TransformOpe ration::Skew)); | |
| 421 FloatBox box(0, 0, 0, 10, 10, 10); | |
| 422 FloatBox bounds; | |
| 423 | |
| 424 toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds); | |
| 425 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(0, 0, 0, 10, 2 0, 10), bounds); | |
| 426 | |
| 427 identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | |
| 428 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-10, 0, 0, 20, 10, 10), bounds); | |
| 429 | |
| 430 toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds); | |
| 431 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-10, 0, 0, 20, 20, 10), bounds); | |
| 432 | |
| 433 fromOps.blendedBoundsForBox(box, toOps, 0, 1, &bounds); | |
| 434 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-10, 0, 0, 20, 20, 10), bounds); | |
| 435 } | |
| 436 | |
| 437 TEST(TransformOperationsTest, NonCommutativeRotations) | |
| 438 { | |
| 439 TransformOperations fromOps; | |
| 440 fromOps.operations().append(RotateTransformOperation::create(1, 0, 0, 0, Tra nsformOperation::Rotate3D)); | |
| 441 fromOps.operations().append(RotateTransformOperation::create(0, 1, 0, 0, Tra nsformOperation::Rotate3D)); | |
| 442 TransformOperations toOps; | |
| 443 toOps.operations().append(RotateTransformOperation::create(1, 0, 0, 45, Tran sformOperation::Rotate3D)); | |
| 444 toOps.operations().append(RotateTransformOperation::create(0, 1, 0, 135, Tra nsformOperation::Rotate3D)); | |
| 445 | |
| 446 FloatBox box(0, 0, 0, 1, 1, 1); | |
| 447 FloatBox bounds; | |
| 448 | |
| 449 double minProgress = 0; | |
| 450 double maxProgress = 1; | |
| 451 EXPECT_TRUE(toOps.blendedBoundsForBox( | |
| 452 box, fromOps, minProgress, maxProgress, &bounds)); | |
| 453 | |
| 454 TransformOperations operations = toOps.blend(fromOps, maxProgress); | |
| 455 TransformationMatrix blendedTransform; | |
| 456 operations.apply(FloatSize(0, 0), blendedTransform); | |
| 457 | |
| 458 FloatPoint3D blendedPoint(0.9f, 0.9f, 0); | |
| 459 blendedPoint = blendedTransform.mapPoint(blendedPoint); | |
| 460 FloatBox expandedBounds = bounds; | |
| 461 expandedBounds.expandTo(blendedPoint); | |
| 462 | |
| 463 ASSERT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, bounds, expandedBounds) ; | |
| 464 } | |
| 465 | |
| 466 TEST(TransformOperationsTest, AbsoluteSequenceBoundsTest) | |
| 467 { | |
| 468 TransformOperations fromOps; | |
| 469 TransformOperations toOps; | |
| 470 | |
| 471 fromOps.operations().append(TranslateTransformOperation::create(Length(1, Fi xed), Length(-5, Fixed), 1, TransformOperation::Translate3D)); | |
| 472 fromOps.operations().append(ScaleTransformOperation::create(-1, 2, 3, Transf ormOperation::Scale3D)); | |
| 473 fromOps.operations().append(TranslateTransformOperation::create(Length(2, Fi xed), Length(4, Fixed), -1, TransformOperation::Translate3D)); | |
| 474 | |
| 475 toOps.operations().append(TranslateTransformOperation::create(Length(13, Fix ed), Length(-1, Fixed), 5, TransformOperation::Translate3D)); | |
| 476 toOps.operations().append(ScaleTransformOperation::create(-3, -2, 5, Transfo rmOperation::Scale3D)); | |
| 477 toOps.operations().append(TranslateTransformOperation::create(Length(6, Fixe d), Length(-2, Fixed), 3, TransformOperation::Translate3D)); | |
| 478 | |
| 479 FloatBox box(1, 2, 3, 4, 4, 4); | |
| 480 FloatBox bounds; | |
| 481 | |
| 482 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, -0.5, 1.5, &bounds)); | |
| 483 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-57, -59, -1, 76, 112, 80), bounds); | |
| 484 | |
| 485 EXPECT_TRUE(toOps.blendedBoundsForBox(box, fromOps, 0, 1, &bounds)); | |
| 486 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-32, -25, 7, 4 2, 44, 48), bounds); | |
| 487 | |
| 488 EXPECT_TRUE(toOps.blendedBoundsForBox(box, identityOperations, 0, 1, &bounds )); | |
| 489 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-33, -13, 3, 5 7, 19, 52), bounds); | |
| 490 | |
| 491 EXPECT_TRUE(identityOperations.blendedBoundsForBox(box, fromOps, 0, 1, &boun ds)); | |
| 492 EXPECT_PRED_FORMAT2(FloatBoxTest::AssertAlmostEqual, FloatBox(-7, -3, 2, 15, 23, 20), bounds); | |
| 493 } | |
| 494 | |
| 495 } // namespace | |
| OLD | NEW |