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

Side by Side Diff: tests/InterpolatorTest.cpp

Issue 1562333002: test & doc for SkUnitCubicInterp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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 | « include/utils/SkInterpolator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkInterpolator.h" 8 #include "SkInterpolator.h"
9 9
10 #include "Test.h" 10 #include "Test.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 #if 0 51 #if 0
52 SkScalar vv[3]; 52 SkScalar vv[3];
53 REPORTER_ASSERT(reporter, memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0) ; 53 REPORTER_ASSERT(reporter, memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0) ;
54 #endif 54 #endif
55 55
56 result = inter.timeToValues(125, v); 56 result = inter.timeToValues(125, v);
57 REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); 57 REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
58 result = inter.timeToValues(175, v); 58 result = inter.timeToValues(175, v);
59 REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result); 59 REPORTER_ASSERT(reporter, result == SkInterpolator::kNormal_Result);
60 60
61 for (SkScalar val = -0.1f; val <= 1.1f; val += 0.1f) {
62 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(SkTPin(0.f, val, 1.f),
63 SkUnitCubicInterp(val, 1.f/3, 1.f/3, 2.f/3, 2.f/3)));
64 }
65
66 // These numbers come from
67 // http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag.
68 const SkScalar testTransitions[][4] = {
69 { 0.25f, 0.1f, 0.25f, 1 }, // ease
70 { 0.42f, 0, 1, 1 }, // ease in
71 { 0, 0, 0.58f, 1 }, // ease out
72 { 0.42f, 0, 0.58f, 1 }, // ease in out
73 };
74
75 const SkScalar expectedOutput[][5] = {
76 { 0.0947876f, 0.513367f, 0.80249f, 0.940796f, 0.994263f }, // ease
77 { 0.0170288f, 0.129639f, 0.31543f, 0.554749f, 0.839417f }, // ease in
78 { 0.160583f, 0.445251f, 0.684692f, 0.870361f, 0.982971f }, // ease out
79 { 0.0197144f, 0.187439f, 0.500122f, 0.812561f, 0.980286f }, // ease in o ut
80 };
81
82 int i = 0;
83 for (const SkScalar* t : testTransitions) {
84 int j = 0;
85 for (SkScalar val = 0.1f; val < 1; val += 0.2f) {
86 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(expectedOutput[i][j++] ,
87 SkUnitCubicInterp(val, t[0], t[1], t[2], t[3])));
88 }
89 ++i;
90 SkDebugf("\n");
91 }
61 } 92 }
OLDNEW
« no previous file with comments | « include/utils/SkInterpolator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698