benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 "include/core/SkPaint.h" |
| 9 | #include "include/core/SkPath.h" |
| 10 | #include "include/core/SkTime.h" |
| 11 | #include "include/utils/SkRandom.h" |
| 12 | #include "src/core/SkPointPriv.h" |
| 13 | #include "src/core/SkStrokerPriv.h" |
| 14 | #include "src/pathops/SkPathOpsCubic.h" |
| 15 | #include "tests/PathOpsCubicIntersectionTestData.h" |
| 16 | #include "tests/PathOpsQuadIntersectionTestData.h" |
| 17 | #include "tests/Test.h" |
| 18 | #include "tools/flags/CommandLineFlags.h" |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 19 | |
Mike Klein | 84836b7 | 2019-03-21 11:31:36 -0500 | [diff] [blame] | 20 | static DEFINE_bool(timeout, true, "run until alloted time expires"); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 21 | |
| 22 | #define MS_TEST_DURATION 10 |
| 23 | |
| 24 | const SkScalar widths[] = {-FLT_MAX, -1, -0.1f, -FLT_EPSILON, 0, FLT_EPSILON, |
| 25 | 0.0000001f, 0.000001f, 0.00001f, 0.0001f, 0.001f, 0.01f, |
| 26 | 0.1f, 0.2f, 0.3f, 0.4f, 0.5f, 1, 1.1f, 2, 10, 10e2f, 10e3f, 10e4f, 10e5f, 10e6f, 10e7f, |
| 27 | 10e8f, 10e9f, 10e10f, 10e20f, FLT_MAX }; |
| 28 | size_t widths_count = SK_ARRAY_COUNT(widths); |
| 29 | |
| 30 | static void pathTest(const SkPath& path) { |
| 31 | SkPaint p; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 32 | SkPath fill; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 33 | p.setStyle(SkPaint::kStroke_Style); |
| 34 | for (size_t index = 0; index < widths_count; ++index) { |
| 35 | p.setStrokeWidth(widths[index]); |
| 36 | p.getFillPath(path, &fill); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | static void cubicTest(const SkPoint c[4]) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 41 | SkPath path; |
| 42 | path.moveTo(c[0].fX, c[0].fY); |
| 43 | path.cubicTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY, c[3].fX, c[3].fY); |
| 44 | pathTest(path); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | static void quadTest(const SkPoint c[3]) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 48 | SkPath path; |
| 49 | path.moveTo(c[0].fX, c[0].fY); |
| 50 | path.quadTo(c[1].fX, c[1].fY, c[2].fX, c[2].fY); |
| 51 | pathTest(path); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 52 | } |
| 53 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 54 | static void cubicSetTest(const CubicPts* dCubic, size_t count) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 55 | skiatest::Timer timer; |
| 56 | for (size_t index = 0; index < count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 57 | const CubicPts& dPts = dCubic[index]; |
| 58 | SkDCubic d; |
| 59 | d.debugSet(dPts.fPts); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 60 | SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (float) d[1].fY}, |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 61 | {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].fX, (float) d[3].fY} }; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 62 | cubicTest(c); |
| 63 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 64 | return; |
| 65 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 66 | } |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 67 | } |
| 68 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 69 | static void cubicPairSetTest(const CubicPts dCubic[][2], size_t count) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 70 | skiatest::Timer timer; |
| 71 | for (size_t index = 0; index < count; ++index) { |
| 72 | for (int pair = 0; pair < 2; ++pair) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 73 | const CubicPts& dPts = dCubic[index][pair]; |
| 74 | SkDCubic d; |
| 75 | d.debugSet(dPts.fPts); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 76 | SkPoint c[4] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (float) d[1].fY}, |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 77 | {(float) d[2].fX, (float) d[2].fY}, {(float) d[3].fX, (float) d[3].fY} }; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 78 | cubicTest(c); |
| 79 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 80 | return; |
| 81 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 84 | } |
| 85 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 86 | static void quadSetTest(const QuadPts* dQuad, size_t count) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 87 | skiatest::Timer timer; |
| 88 | for (size_t index = 0; index < count; ++index) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 89 | const QuadPts& dPts = dQuad[index]; |
| 90 | SkDQuad d; |
| 91 | d.debugSet(dPts.fPts); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 92 | SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (float) d[1].fY}, |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 93 | {(float) d[2].fX, (float) d[2].fY} }; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 94 | quadTest(c); |
| 95 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 96 | return; |
| 97 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 98 | } |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 99 | } |
| 100 | |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 101 | static void quadPairSetTest(const QuadPts dQuad[][2], size_t count) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 102 | skiatest::Timer timer; |
| 103 | for (size_t index = 0; index < count; ++index) { |
| 104 | for (int pair = 0; pair < 2; ++pair) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 105 | const QuadPts& dPts = dQuad[index][pair]; |
| 106 | SkDQuad d; |
| 107 | d.debugSet(dPts.fPts); |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 108 | SkPoint c[3] = { {(float) d[0].fX, (float) d[0].fY}, {(float) d[1].fX, (float) d[1].fY}, |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 109 | {(float) d[2].fX, (float) d[2].fY} }; |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 110 | quadTest(c); |
| 111 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 112 | return; |
| 113 | } |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 114 | } |
| 115 | } |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | DEF_TEST(QuadStrokerSet, reporter) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 119 | quadSetTest(quadraticLines, quadraticLines_count); |
| 120 | quadSetTest(quadraticPoints, quadraticPoints_count); |
| 121 | quadSetTest(quadraticModEpsilonLines, quadraticModEpsilonLines_count); |
| 122 | quadPairSetTest(quadraticTests, quadraticTests_count); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | DEF_TEST(CubicStrokerSet, reporter) { |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 126 | cubicSetTest(pointDegenerates, pointDegenerates_count); |
| 127 | cubicSetTest(notPointDegenerates, notPointDegenerates_count); |
| 128 | cubicSetTest(lines, lines_count); |
| 129 | cubicSetTest(notLines, notLines_count); |
| 130 | cubicSetTest(modEpsilonLines, modEpsilonLines_count); |
| 131 | cubicSetTest(lessEpsilonLines, lessEpsilonLines_count); |
| 132 | cubicSetTest(negEpsilonLines, negEpsilonLines_count); |
| 133 | cubicPairSetTest(tests, tests_count); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 134 | } |
| 135 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 136 | static SkScalar unbounded(SkRandom& r) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 137 | uint32_t val = r.nextU(); |
| 138 | return SkBits2Float(val); |
| 139 | } |
| 140 | |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 141 | static SkScalar unboundedPos(SkRandom& r) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 142 | uint32_t val = r.nextU() & 0x7fffffff; |
| 143 | return SkBits2Float(val); |
| 144 | } |
| 145 | |
| 146 | DEF_TEST(QuadStrokerUnbounded, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 147 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 148 | SkPaint p; |
| 149 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 150 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 151 | int best = 0; |
| 152 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 153 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 154 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 155 | for (int i = 0; i < 1000000; ++i) { |
| 156 | SkPath path, fill; |
| 157 | path.moveTo(unbounded(r), unbounded(r)); |
| 158 | path.quadTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r)); |
| 159 | p.setStrokeWidth(unboundedPos(r)); |
| 160 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 161 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 162 | if (best < gMaxRecursion[2]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 163 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 164 | SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[2], |
| 165 | p.getStrokeWidth()); |
| 166 | path.dumpHex(); |
| 167 | SkDebugf("fill:\n"); |
| 168 | fill.dumpHex(); |
| 169 | } |
| 170 | best = gMaxRecursion[2]; |
| 171 | } |
| 172 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 173 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 174 | return; |
| 175 | } |
| 176 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 177 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 178 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 179 | SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
| 180 | } |
| 181 | #endif |
| 182 | } |
| 183 | |
| 184 | DEF_TEST(CubicStrokerUnbounded, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 185 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 186 | SkPaint p; |
| 187 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 188 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 189 | int bestTan = 0; |
| 190 | int bestCubic = 0; |
| 191 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 192 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 193 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 194 | for (int i = 0; i < 1000000; ++i) { |
| 195 | SkPath path, fill; |
| 196 | path.moveTo(unbounded(r), unbounded(r)); |
| 197 | path.cubicTo(unbounded(r), unbounded(r), unbounded(r), unbounded(r), |
| 198 | unbounded(r), unbounded(r)); |
| 199 | p.setStrokeWidth(unboundedPos(r)); |
| 200 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 201 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 202 | if (bestTan < gMaxRecursion[0] || bestCubic < gMaxRecursion[1]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 203 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 204 | SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[0], |
| 205 | gMaxRecursion[1], p.getStrokeWidth()); |
| 206 | path.dumpHex(); |
| 207 | SkDebugf("fill:\n"); |
| 208 | fill.dumpHex(); |
| 209 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 210 | bestTan = std::max(bestTan, gMaxRecursion[0]); |
| 211 | bestCubic = std::max(bestCubic, gMaxRecursion[1]); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 212 | } |
| 213 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 214 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 215 | return; |
| 216 | } |
| 217 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 218 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 219 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 220 | SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic); |
| 221 | } |
| 222 | #endif |
| 223 | } |
| 224 | |
| 225 | DEF_TEST(QuadStrokerConstrained, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 226 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 227 | SkPaint p; |
| 228 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 229 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 230 | int best = 0; |
| 231 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 232 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 233 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 234 | for (int i = 0; i < 1000000; ++i) { |
| 235 | SkPath path, fill; |
| 236 | SkPoint quad[3]; |
| 237 | quad[0].fX = r.nextRangeF(0, 500); |
| 238 | quad[0].fY = r.nextRangeF(0, 500); |
| 239 | const SkScalar halfSquared = 0.5f * 0.5f; |
| 240 | do { |
| 241 | quad[1].fX = r.nextRangeF(0, 500); |
| 242 | quad[1].fY = r.nextRangeF(0, 500); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 243 | } while (SkPointPriv::DistanceToSqd(quad[0], quad[1]) < halfSquared); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 244 | do { |
| 245 | quad[2].fX = r.nextRangeF(0, 500); |
| 246 | quad[2].fY = r.nextRangeF(0, 500); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 247 | } while (SkPointPriv::DistanceToSqd(quad[0], quad[2]) < halfSquared |
| 248 | || SkPointPriv::DistanceToSqd(quad[1], quad[2]) < halfSquared); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 249 | path.moveTo(quad[0].fX, quad[0].fY); |
| 250 | path.quadTo(quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY); |
| 251 | p.setStrokeWidth(r.nextRangeF(0, 500)); |
| 252 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 253 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 254 | if (best < gMaxRecursion[2]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 255 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 256 | SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[2], |
| 257 | p.getStrokeWidth()); |
| 258 | path.dumpHex(); |
| 259 | SkDebugf("fill:\n"); |
| 260 | fill.dumpHex(); |
| 261 | } |
| 262 | best = gMaxRecursion[2]; |
| 263 | } |
| 264 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 265 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 266 | return; |
| 267 | } |
| 268 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 269 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 270 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 271 | SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
| 272 | } |
| 273 | #endif |
| 274 | } |
| 275 | |
| 276 | DEF_TEST(CubicStrokerConstrained, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 277 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 278 | SkPaint p; |
| 279 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 280 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 281 | int bestTan = 0; |
| 282 | int bestCubic = 0; |
| 283 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 284 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 285 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 286 | for (int i = 0; i < 1000000; ++i) { |
| 287 | SkPath path, fill; |
| 288 | SkPoint cubic[4]; |
| 289 | cubic[0].fX = r.nextRangeF(0, 500); |
| 290 | cubic[0].fY = r.nextRangeF(0, 500); |
| 291 | const SkScalar halfSquared = 0.5f * 0.5f; |
| 292 | do { |
| 293 | cubic[1].fX = r.nextRangeF(0, 500); |
| 294 | cubic[1].fY = r.nextRangeF(0, 500); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 295 | } while (SkPointPriv::DistanceToSqd(cubic[0], cubic[1]) < halfSquared); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 296 | do { |
| 297 | cubic[2].fX = r.nextRangeF(0, 500); |
| 298 | cubic[2].fY = r.nextRangeF(0, 500); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 299 | } while ( SkPointPriv::DistanceToSqd(cubic[0], cubic[2]) < halfSquared |
| 300 | || SkPointPriv::DistanceToSqd(cubic[1], cubic[2]) < halfSquared); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 301 | do { |
| 302 | cubic[3].fX = r.nextRangeF(0, 500); |
| 303 | cubic[3].fY = r.nextRangeF(0, 500); |
Cary Clark | df429f3 | 2017-11-08 11:44:31 -0500 | [diff] [blame] | 304 | } while ( SkPointPriv::DistanceToSqd(cubic[0], cubic[3]) < halfSquared |
| 305 | || SkPointPriv::DistanceToSqd(cubic[1], cubic[3]) < halfSquared |
| 306 | || SkPointPriv::DistanceToSqd(cubic[2], cubic[3]) < halfSquared); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 307 | path.moveTo(cubic[0].fX, cubic[0].fY); |
| 308 | path.cubicTo(cubic[1].fX, cubic[1].fY, cubic[2].fX, cubic[2].fY, cubic[3].fX, cubic[3].fY); |
| 309 | p.setStrokeWidth(r.nextRangeF(0, 500)); |
| 310 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 311 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 312 | if (bestTan < gMaxRecursion[0] || bestCubic < gMaxRecursion[1]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 313 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 314 | SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[0], |
| 315 | gMaxRecursion[1], p.getStrokeWidth()); |
| 316 | path.dumpHex(); |
| 317 | SkDebugf("fill:\n"); |
| 318 | fill.dumpHex(); |
| 319 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 320 | bestTan = std::max(bestTan, gMaxRecursion[0]); |
| 321 | bestCubic = std::max(bestCubic, gMaxRecursion[1]); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 322 | } |
| 323 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 324 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 325 | return; |
| 326 | } |
| 327 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 328 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 329 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 330 | SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, bestTan, bestCubic); |
| 331 | } |
| 332 | #endif |
| 333 | } |
| 334 | |
| 335 | DEF_TEST(QuadStrokerRange, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 336 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 337 | SkPaint p; |
| 338 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 339 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 340 | int best = 0; |
| 341 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 342 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 343 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 344 | for (int i = 0; i < 1000000; ++i) { |
| 345 | SkPath path, fill; |
| 346 | SkPoint quad[3]; |
| 347 | quad[0].fX = r.nextRangeF(0, 500); |
| 348 | quad[0].fY = r.nextRangeF(0, 500); |
| 349 | quad[1].fX = r.nextRangeF(0, 500); |
| 350 | quad[1].fY = r.nextRangeF(0, 500); |
| 351 | quad[2].fX = r.nextRangeF(0, 500); |
| 352 | quad[2].fY = r.nextRangeF(0, 500); |
| 353 | path.moveTo(quad[0].fX, quad[0].fY); |
| 354 | path.quadTo(quad[1].fX, quad[1].fY, quad[2].fX, quad[2].fY); |
| 355 | p.setStrokeWidth(r.nextRangeF(0, 500)); |
| 356 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 357 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 358 | if (best < gMaxRecursion[2]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 359 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 360 | SkDebugf("\n%s quad=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[2], |
| 361 | p.getStrokeWidth()); |
| 362 | path.dumpHex(); |
| 363 | SkDebugf("fill:\n"); |
| 364 | fill.dumpHex(); |
| 365 | } |
| 366 | best = gMaxRecursion[2]; |
| 367 | } |
| 368 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 369 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 370 | return; |
| 371 | } |
| 372 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 373 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 374 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 375 | SkDebugf("\n%s max quad=%d\n", __FUNCTION__, best); |
| 376 | } |
| 377 | #endif |
| 378 | } |
| 379 | |
| 380 | DEF_TEST(CubicStrokerRange, reporter) { |
scroggo | f9d6101 | 2014-12-15 12:54:51 -0800 | [diff] [blame] | 381 | SkRandom r; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 382 | SkPaint p; |
| 383 | p.setStyle(SkPaint::kStroke_Style); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 384 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 385 | int best[2] = { 0 }; |
| 386 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 387 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 388 | skiatest::Timer timer; |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 389 | for (int i = 0; i < 1000000; ++i) { |
| 390 | SkPath path, fill; |
| 391 | path.moveTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500)); |
| 392 | path.cubicTo(r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0, 500), |
| 393 | r.nextRangeF(0, 500), r.nextRangeF(0, 500), r.nextRangeF(0, 500)); |
| 394 | p.setStrokeWidth(r.nextRangeF(0, 100)); |
| 395 | p.getFillPath(path, &fill); |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 396 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 397 | if (best[0] < gMaxRecursion[0] || best[1] < gMaxRecursion[1]) { |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 398 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 399 | SkDebugf("\n%s tan=%d cubic=%d width=%1.9g\n", __FUNCTION__, gMaxRecursion[0], |
| 400 | gMaxRecursion[1], p.getStrokeWidth()); |
| 401 | path.dumpHex(); |
| 402 | SkDebugf("fill:\n"); |
| 403 | fill.dumpHex(); |
| 404 | } |
Brian Osman | 788b916 | 2020-02-07 10:36:46 -0500 | [diff] [blame] | 405 | best[0] = std::max(best[0], gMaxRecursion[0]); |
| 406 | best[1] = std::max(best[1], gMaxRecursion[1]); |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 407 | } |
| 408 | #endif |
benjaminwagner | ec4d4d7 | 2016-03-25 12:59:53 -0700 | [diff] [blame] | 409 | if (FLAGS_timeout && timer.elapsedMs() > MS_TEST_DURATION) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 410 | return; |
| 411 | } |
| 412 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 413 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 414 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 415 | SkDebugf("\n%s max tan=%d cubic=%d\n", __FUNCTION__, best[0], best[1]); |
| 416 | } |
| 417 | #endif |
| 418 | } |
| 419 | |
| 420 | |
| 421 | DEF_TEST(QuadStrokerOneOff, reporter) { |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 422 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 423 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 424 | #endif |
| 425 | SkPaint p; |
| 426 | p.setStyle(SkPaint::kStroke_Style); |
| 427 | p.setStrokeWidth(SkDoubleToScalar(164.683548)); |
| 428 | |
| 429 | SkPath path, fill; |
| 430 | path.moveTo(SkBits2Float(0x43c99223), SkBits2Float(0x42b7417e)); |
| 431 | path.quadTo(SkBits2Float(0x4285d839), SkBits2Float(0x43ed6645), SkBits2Float(0x43c941c8), SkBits2Float(0x42b3ace3)); |
| 432 | p.getFillPath(path, &fill); |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 433 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 434 | SkDebugf("\n%s path\n", __FUNCTION__); |
| 435 | path.dump(); |
| 436 | SkDebugf("fill:\n"); |
| 437 | fill.dump(); |
| 438 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 439 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 440 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 441 | SkDebugf("max quad=%d\n", gMaxRecursion[2]); |
| 442 | } |
| 443 | #endif |
| 444 | } |
| 445 | |
| 446 | DEF_TEST(CubicStrokerOneOff, reporter) { |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 447 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 448 | sk_bzero(gMaxRecursion, sizeof(gMaxRecursion[0]) * 3); |
| 449 | #endif |
| 450 | SkPaint p; |
| 451 | p.setStyle(SkPaint::kStroke_Style); |
| 452 | p.setStrokeWidth(SkDoubleToScalar(42.835968)); |
| 453 | |
| 454 | SkPath path, fill; |
| 455 | path.moveTo(SkBits2Float(0x433f5370), SkBits2Float(0x43d1f4b3)); |
| 456 | path.cubicTo(SkBits2Float(0x4331cb76), SkBits2Float(0x43ea3340), SkBits2Float(0x4388f498), SkBits2Float(0x42f7f08d), SkBits2Float(0x43f1cd32), SkBits2Float(0x42802ec1)); |
| 457 | p.getFillPath(path, &fill); |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 458 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 459 | SkDebugf("\n%s path\n", __FUNCTION__); |
| 460 | path.dump(); |
| 461 | SkDebugf("fill:\n"); |
| 462 | fill.dump(); |
| 463 | } |
Cary Clark | 66e393c | 2017-07-31 13:24:28 -0400 | [diff] [blame] | 464 | #if defined(SK_DEBUG) && QUAD_STROKE_APPROX_EXTENDED_DEBUGGING |
Mike Klein | d0f321b | 2019-03-22 13:15:11 -0500 | [diff] [blame] | 465 | if (reporter->verbose()) { |
caryclark | feff7d2 | 2014-10-09 05:36:03 -0700 | [diff] [blame] | 466 | SkDebugf("max tan=%d cubic=%d\n", gMaxRecursion[0], gMaxRecursion[1]); |
| 467 | } |
| 468 | #endif |
| 469 | } |