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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/core/SkScaleToSides.h" |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 9 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 10 | #include "tests/Test.h" |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 11 | |
Hal Canary | 8a00144 | 2018-09-19 11:31:27 -0400 | [diff] [blame] | 12 | #include <algorithm> |
| 13 | |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 14 | DEF_TEST(ScaleToSides, reporter) { |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 15 | double interestingValues[] = { |
herb | f5d4746 | 2016-02-19 16:54:12 -0800 | [diff] [blame] | 16 | // From sample app - PathFuzzer |
| 17 | 260.01662826538085938, |
| 18 | 63.61007690429687500, |
| 19 | 795.98901367187500000, |
| 20 | 217.71697616577148438, |
| 21 | 686.15960693359375000, |
| 22 | 556.57641601562500000, |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 23 | // From skp bitbucket |
| 24 | 111.60000228881836, |
| 25 | 55.800003051757813, |
| 26 | 0.99999996581812677920, |
| 27 | 0.0, |
| 28 | 0.5, |
| 29 | 1.0, |
| 30 | 2.0, |
| 31 | 3.0, |
| 32 | 33.0, |
| 33 | 33554430.0, |
| 34 | 33554431.0, |
| 35 | 33554464.0, |
| 36 | 333333332.0, |
| 37 | 333333333.0, |
| 38 | 333333334.0, |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 39 | FLT_MAX, |
| 40 | FLT_EPSILON, |
Mike Klein | b64a26c | 2020-08-11 12:51:19 -0500 | [diff] [blame] | 41 | FLT_MIN, |
| 42 | 340282569745034499980078846904281071616.0, |
| 43 | 170141284872517249990039423452140535808.0, |
| 44 | 170141244307698042686698575557637963776.0, |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | int numInterestingValues = (int)SK_ARRAY_COUNT(interestingValues); |
| 48 | |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 49 | for (int s = 0; s <= numInterestingValues; s++) { |
| 50 | for (int i = 0; i < numInterestingValues; i++) { |
| 51 | for (int j = 0; j < numInterestingValues; j++) { |
| 52 | for (int k = 0; k < numInterestingValues; k++) { |
Mike Klein | ab6f9ef | 2020-08-11 16:44:39 -0500 | [diff] [blame] | 53 | // We're about to cast values i and j to float, don't bother if they won't fit. |
| 54 | // (Is there a more robust way to test this, like SkTFitsIn but double->float?) |
| 55 | if (interestingValues[i] > FLT_MAX || |
| 56 | interestingValues[j] > FLT_MAX) { |
| 57 | continue; |
| 58 | } |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 59 | float radius1 = (float)interestingValues[i]; |
| 60 | float radius2 = (float)interestingValues[j]; |
| 61 | double width = interestingValues[k]; |
Mike Klein | a4c277b | 2018-11-06 14:24:55 -0500 | [diff] [blame] | 62 | double scale = sk_ieee_double_divide(width, (double)radius1 + (double)radius2); |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 63 | if (width > 0.0) { |
| 64 | if (s != 0) { |
| 65 | scale = std::min(scale, interestingValues[s-1]); |
| 66 | } |
| 67 | if (scale < 1.0 && scale > 0.0) { |
herb | 97293c6 | 2016-01-22 11:58:55 -0800 | [diff] [blame] | 68 | SkScaleToSides::AdjustRadii(width, scale, &radius1, &radius2); |
herb | 5e0883c | 2016-01-22 08:34:35 -0800 | [diff] [blame] | 69 | } |
herb | 7cf12dd | 2016-01-11 08:08:56 -0800 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | } |
| 73 | } |
| 74 | } |
| 75 | } |