| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
| 4 * | 4 * |
| 5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
| 6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 | 9 |
| 10 #include "SkInterpolator.h" | 10 #include "SkInterpolator.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 262 } |
| 263 | 263 |
| 264 // Now we have t, so compute the coeff for Y and evaluate | 264 // Now we have t, so compute the coeff for Y and evaluate |
| 265 b = pin_and_convert(by); | 265 b = pin_and_convert(by); |
| 266 c = pin_and_convert(cy); | 266 c = pin_and_convert(cy); |
| 267 A = 3*b; | 267 A = 3*b; |
| 268 B = 3*(c - 2*b); | 268 B = 3*(c - 2*b); |
| 269 C = 3*(b - c) + Dot14_ONE; | 269 C = 3*(b - c) + Dot14_ONE; |
| 270 return SkFixedToScalar(eval_cubic(t, A, B, C) << 2); | 270 return SkFixedToScalar(eval_cubic(t, A, B, C) << 2); |
| 271 } | 271 } |
| 272 | |
| 273 /////////////////////////////////////////////////////////////////////////////// | |
| 274 /////////////////////////////////////////////////////////////////////////////// | |
| 275 | |
| 276 #ifdef SK_DEBUG | |
| 277 | |
| 278 #ifdef SK_SUPPORT_UNITTEST | |
| 279 static SkScalar* iset(SkScalar array[3], int a, int b, int c) { | |
| 280 array[0] = SkIntToScalar(a); | |
| 281 array[1] = SkIntToScalar(b); | |
| 282 array[2] = SkIntToScalar(c); | |
| 283 return array; | |
| 284 } | |
| 285 #endif | |
| 286 | |
| 287 void SkInterpolator::UnitTest() { | |
| 288 #ifdef SK_SUPPORT_UNITTEST | |
| 289 SkInterpolator inter(3, 2); | |
| 290 SkScalar v1[3], v2[3], v[3], vv[3]; | |
| 291 Result result; | |
| 292 | |
| 293 inter.setKeyFrame(0, 100, iset(v1, 10, 20, 30), 0); | |
| 294 inter.setKeyFrame(1, 200, iset(v2, 110, 220, 330)); | |
| 295 | |
| 296 result = inter.timeToValues(0, v); | |
| 297 SkASSERT(result == kFreezeStart_Result); | |
| 298 SkASSERT(memcmp(v, v1, sizeof(v)) == 0); | |
| 299 | |
| 300 result = inter.timeToValues(99, v); | |
| 301 SkASSERT(result == kFreezeStart_Result); | |
| 302 SkASSERT(memcmp(v, v1, sizeof(v)) == 0); | |
| 303 | |
| 304 result = inter.timeToValues(100, v); | |
| 305 SkASSERT(result == kNormal_Result); | |
| 306 SkASSERT(memcmp(v, v1, sizeof(v)) == 0); | |
| 307 | |
| 308 result = inter.timeToValues(200, v); | |
| 309 SkASSERT(result == kNormal_Result); | |
| 310 SkASSERT(memcmp(v, v2, sizeof(v)) == 0); | |
| 311 | |
| 312 result = inter.timeToValues(201, v); | |
| 313 SkASSERT(result == kFreezeEnd_Result); | |
| 314 SkASSERT(memcmp(v, v2, sizeof(v)) == 0); | |
| 315 | |
| 316 result = inter.timeToValues(150, v); | |
| 317 SkASSERT(result == kNormal_Result); | |
| 318 SkASSERT(memcmp(v, iset(vv, 60, 120, 180), sizeof(v)) == 0); | |
| 319 | |
| 320 result = inter.timeToValues(125, v); | |
| 321 SkASSERT(result == kNormal_Result); | |
| 322 result = inter.timeToValues(175, v); | |
| 323 SkASSERT(result == kNormal_Result); | |
| 324 #endif | |
| 325 } | |
| 326 | |
| 327 #endif | |
| OLD | NEW |