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[] = { |
herb | f5d4746 | 2016-02-19 16:54:12 -0800 | [diff] [blame] | 15 | // From sample app - PathFuzzer |
| 16 | 260.01662826538085938, |
| 17 | 63.61007690429687500, |
| 18 | 795.98901367187500000, |
| 19 | 217.71697616577148438, |
| 20 | 686.15960693359375000, |
| 21 | 556.57641601562500000, |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 22 | // From skp bitbucket |
| 23 | 111.60000228881836, |
| 24 | 55.800003051757813, |
| 25 | 0.99999996581812677920, |
| 26 | 0.0, |
| 27 | 0.5, |
| 28 | 1.0, |
| 29 | 2.0, |
| 30 | 3.0, |
| 31 | 33.0, |
| 32 | 33554430.0, |
| 33 | 33554431.0, |
| 34 | 33554464.0, |
| 35 | 333333332.0, |
| 36 | 333333333.0, |
| 37 | 333333334.0, |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 38 | FLT_MAX, |
| 39 | FLT_EPSILON, |
| 40 | FLT_MIN |
| 41 | }; |
| 42 | |
| 43 | int numInterestingValues = (int)SK_ARRAY_COUNT(interestingValues); |
| 44 | |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 45 | for (int s = 0; s <= numInterestingValues; s++) { |
| 46 | for (int i = 0; i < numInterestingValues; i++) { |
| 47 | for (int j = 0; j < numInterestingValues; j++) { |
| 48 | for (int k = 0; k < numInterestingValues; k++) { |
| 49 | float radius1 = (float)interestingValues[i]; |
| 50 | float radius2 = (float)interestingValues[j]; |
| 51 | double width = interestingValues[k]; |
| 52 | double scale = width / ((double)radius1 + (double)radius2); |
| 53 | if (width > 0.0) { |
| 54 | if (s != 0) { |
| 55 | scale = std::min(scale, interestingValues[s-1]); |
| 56 | } |
| 57 | if (scale < 1.0 && scale > 0.0) { |
herb | 97293c6 | 2016-01-22 11:58:55 -0800 | [diff] [blame] | 58 | SkScaleToSides::AdjustRadii(width, scale, &radius1, &radius2); |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 59 | } |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | } |