herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkScaleToSides.h" |
| 9 | |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 10 | #include <algorithm> |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 11 | #include "Test.h" |
| 12 | |
| 13 | DEF_TEST(ScaleToSides, reporter) { |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 14 | double interestingValues[] = { |
| 15 | // From skp bitbucket |
| 16 | 111.60000228881836, |
| 17 | 55.800003051757813, |
| 18 | 0.99999996581812677920, |
| 19 | 0.0, |
| 20 | 0.5, |
| 21 | 1.0, |
| 22 | 2.0, |
| 23 | 3.0, |
| 24 | 33.0, |
| 25 | 33554430.0, |
| 26 | 33554431.0, |
| 27 | 33554464.0, |
| 28 | 333333332.0, |
| 29 | 333333333.0, |
| 30 | 333333334.0, |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 31 | FLT_MAX, |
| 32 | FLT_EPSILON, |
| 33 | FLT_MIN |
| 34 | }; |
| 35 | |
| 36 | int numInterestingValues = (int)SK_ARRAY_COUNT(interestingValues); |
| 37 | |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 38 | for (int s = 0; s <= numInterestingValues; s++) { |
| 39 | for (int i = 0; i < numInterestingValues; i++) { |
| 40 | for (int j = 0; j < numInterestingValues; j++) { |
| 41 | for (int k = 0; k < numInterestingValues; k++) { |
| 42 | float radius1 = (float)interestingValues[i]; |
| 43 | float radius2 = (float)interestingValues[j]; |
| 44 | double width = interestingValues[k]; |
| 45 | double scale = width / ((double)radius1 + (double)radius2); |
| 46 | if (width > 0.0) { |
| 47 | if (s != 0) { |
| 48 | scale = std::min(scale, interestingValues[s-1]); |
| 49 | } |
| 50 | if (scale < 1.0 && scale > 0.0) { |
herb | 97293c6 | 2016-01-22 11:58:55 -0800 | [diff] [blame^] | 51 | SkScaleToSides::AdjustRadii(width, scale, &radius1, &radius2); |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 52 | } |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 53 | } |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | } |