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

Unified Diff: tests/ScaleToSidesTest.cpp

Issue 1617763003: Fix bounds of checking if a radii are too long for a side. (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 side-by-side diff with in-line comments
Download patch
« src/core/SkScaleToSides.h ('K') | « src/core/SkScaleToSides.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ScaleToSidesTest.cpp
diff --git a/tests/ScaleToSidesTest.cpp b/tests/ScaleToSidesTest.cpp
index 60e82be52951201b54143f3a3a997d3cd55ad2c4..345853d63031ea975e5fe3f382cd7b66920e20c8 100644
--- a/tests/ScaleToSidesTest.cpp
+++ b/tests/ScaleToSidesTest.cpp
@@ -8,22 +8,37 @@
#include "SkScaleToSides.h"
#include <cfloat>
robertphillips 2016/01/22 14:42:51 Do we actually need all these new headers ?
herb_g 2016/01/22 16:01:05 Done.
+#include <algorithm>
+#include <cstdint>
+#include <string>
#include "Test.h"
+float BToF(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
+ uint8_t mem[4] = {a, b, c, d};
+ float val;
+ memcpy(&val, &mem, sizeof(mem));
+ //SkDebugf("BToF: %.12e\n", val);
+ return val;
+}
+
DEF_TEST(ScaleToSides, reporter) {
- float interestingValues[] = {
- 0.0f,
- 0.5f,
- 1.0f,
- 2.0f,
- 3.0f,
- 33.0f,
- 33554430.0f,
- 33554431.0f,
- 33554464.0f,
- 333333332.0f,
- 333333333.0f,
- 333333334.0f,
+ double interestingValues[] = {
+ // From skp bitbucket
+ 111.60000228881836,
+ 55.800003051757813,
+ 0.99999996581812677920,
+ 0.0,
+ 0.5,
+ 1.0,
+ 2.0,
+ 3.0,
+ 33.0,
+ 33554430.0,
+ 33554431.0,
+ 33554464.0,
+ 333333332.0,
+ 333333333.0,
+ 333333334.0,
FLT_MAX,
FLT_EPSILON,
FLT_MIN
@@ -31,16 +46,21 @@ DEF_TEST(ScaleToSides, reporter) {
int numInterestingValues = (int)SK_ARRAY_COUNT(interestingValues);
- for (int i = 0; i < numInterestingValues; i++) {
- for (int j = 0; j < numInterestingValues; j++) {
- for (int k = 0; k < numInterestingValues; k++) {
- float radius1 = interestingValues[i];
- float radius2 = interestingValues[j];
- float width = interestingValues[k];
- if (width > 0.0f) {
- double scale = (double)width / ((double)radius1 + (double)radius2);
- if (scale < 1.0) {
- ScaleToSides::AdjustRadii(width, scale, &radius1, &radius2);
+ for (int s = 0; s <= numInterestingValues; s++) {
+ for (int i = 0; i < numInterestingValues; i++) {
+ for (int j = 0; j < numInterestingValues; j++) {
+ for (int k = 0; k < numInterestingValues; k++) {
+ float radius1 = interestingValues[i];
+ float radius2 = interestingValues[j];
+ double width = interestingValues[k];
+ double scale = width / ((double)radius1 + (double)radius2);
+ if (width > 0.0) {
+ if (s != 0) {
+ scale = std::min(scale, (double)interestingValues[s-1]);
+ }
+ if (scale < 1.0 && scale > 0.0) {
+ ScaleToSides::AdjustRadii(width, scale, &radius1, &radius2);
+ }
}
}
}
« src/core/SkScaleToSides.h ('K') | « src/core/SkScaleToSides.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698