Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | 4b432fa | 2019-06-06 11:44:05 -0500 | [diff] [blame] | 8 | #include "gm/gm.h" |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 10 | #include "include/core/SkPathBuilder.h" |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 11 | |
| 12 | namespace { |
| 13 | |
| 14 | void test_collapse1(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 15 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 16 | canvas->translate(0, 0); |
| 17 | path.moveTo( 652.830078125, 673.9365234375); |
| 18 | path.lineTo( 479.50152587890625, 213.412628173828125); |
| 19 | path.lineTo( 511.840545654296875, 209.1551055908203125); |
| 20 | path.lineTo( 528.14959716796875, 208.6212158203125); |
| 21 | path.moveTo( 370.50653076171875, 73.684051513671875); |
| 22 | path.lineTo( 525.02093505859375, 208.6413726806640625); |
| 23 | path.lineTo( 478.403564453125, 213.5998992919921875); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 24 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 25 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void test_collapse2(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 29 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 30 | path.moveTo( 492.781982421875, 508.7139892578125); |
| 31 | path.lineTo( 361.946746826171875, 161.0923004150390625); |
| 32 | path.lineTo( 386.357513427734375, 157.8785552978515625); |
| 33 | path.lineTo( 398.668212890625, 157.475555419921875); |
| 34 | path.moveTo( 279.673004150390625, 55.619640350341796875); |
| 35 | path.lineTo( 396.30657958984375, 157.4907684326171875); |
| 36 | path.lineTo( 361.117950439453125, 161.2336578369140625); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 37 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void test_collapse3(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 41 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 42 | path.moveTo(31.9730987548828125, 69.4149169921875); |
| 43 | path.lineTo(36.630767822265625, 67.66190338134765625); |
| 44 | path.lineTo(51.1498870849609375, 64.2765045166015625); |
| 45 | path.moveTo(52.94580078125, 64.05560302734375); |
| 46 | path.lineTo(38.9994354248046875, 66.8980712890625); |
| 47 | path.lineTo(32.229583740234375, 69.31696319580078125); |
| 48 | path.lineTo(12.99810791015625, 22.4723663330078125); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 49 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void test_collapse4(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 53 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 54 | path.moveTo( 122.66265869140625, 77.81488800048828125); |
| 55 | path.lineTo( 161.983642578125, 128.557952880859375); |
| 56 | path.lineTo(22.599969863891601562, 76.61859893798828125); |
| 57 | path.lineTo(18.03154754638671875, 76.055633544921875); |
| 58 | path.lineTo(15.40312957763671875, 75.7647247314453125); |
| 59 | path.lineTo(18.572841644287109375, 75.2251129150390625); |
| 60 | path.lineTo(20.895002365112304688, 73.7937774658203125); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 61 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void test_collapse5(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 65 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 66 | path.moveTo(52.659847259521484375, 782.0546875); |
| 67 | path.lineTo(136.6915130615234375, 690.18011474609375); |
| 68 | path.lineTo( 392.147796630859375, 554.6090087890625); |
| 69 | path.lineTo( 516.51470947265625, 534.44134521484375); |
| 70 | path.moveTo(154.6182708740234375, 188.230926513671875); |
| 71 | path.lineTo( 430.242095947265625, 546.76605224609375); |
| 72 | path.lineTo( 373.1005859375, 559.0906982421875); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 73 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 74 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void test_collapse6(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 78 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 79 | path.moveTo(13.314494132995605469, 197.7343902587890625); |
| 80 | path.lineTo(34.56102752685546875, 174.5048675537109375); |
| 81 | path.lineTo(99.15048980712890625, 140.22711181640625); |
| 82 | path.lineTo( 130.595367431640625, 135.1279296875); |
| 83 | path.moveTo(39.09362030029296875, 47.59223175048828125); |
| 84 | path.lineTo(108.7822418212890625, 138.244110107421875); |
| 85 | path.lineTo(94.33460235595703125, 141.360260009765625); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 86 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 87 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void test_collapse7(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 91 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 92 | path.moveTo(13.737141609191894531, 204.0111541748046875); |
| 93 | path.lineTo( 35.658111572265625, 180.04425048828125); |
| 94 | path.lineTo(102.2978668212890625, 144.67840576171875); |
| 95 | path.lineTo( 134.74090576171875, 139.4173583984375); |
| 96 | path.moveTo(40.33458709716796875, 49.10297393798828125); |
| 97 | path.lineTo(112.2353668212890625, 142.6324462890625); |
| 98 | path.lineTo(97.32910919189453125, 145.8475189208984375); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 99 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 100 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void test_collapse8(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 104 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 105 | path.moveTo( 11.75, 174.50); |
| 106 | path.lineTo( 30.50, 154.00); |
| 107 | path.lineTo( 87.50, 123.75); |
| 108 | path.lineTo(115.25, 119.25); |
| 109 | path.moveTo( 34.50, 42.00); |
| 110 | path.lineTo( 96.00, 122.00); |
| 111 | path.lineTo( 83.25, 124.75); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 112 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 113 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void test_collapse9(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 117 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 118 | path.moveTo(SkDoubleToScalar( 13.25), SkDoubleToScalar(197.75)); |
| 119 | path.lineTo(SkDoubleToScalar( 34.75), SkDoubleToScalar(174.75)); |
| 120 | path.lineTo(SkDoubleToScalar( 99.0364), SkDoubleToScalar(140.364)); |
| 121 | path.lineTo(SkDoubleToScalar( 99.25), SkDoubleToScalar(140.25)); |
| 122 | path.lineTo(SkDoubleToScalar(100.167), SkDoubleToScalar(140.096)); |
| 123 | path.lineTo(SkDoubleToScalar(130.50), SkDoubleToScalar(135.00)); |
| 124 | path.moveTo(SkDoubleToScalar( 39.25), SkDoubleToScalar( 47.50)); |
| 125 | path.lineTo(SkDoubleToScalar(100.167), SkDoubleToScalar(140.096)); |
| 126 | path.lineTo(SkDoubleToScalar( 99.0364), SkDoubleToScalar(140.364)); |
| 127 | path.lineTo(SkDoubleToScalar( 94.25), SkDoubleToScalar(141.50)); |
Mike Reed | 7d34dc7 | 2019-11-26 12:17:17 -0500 | [diff] [blame] | 128 | path.setFillType(SkPathFillType::kEvenOdd); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 129 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | // This one is a thin inverted 'v', but the edges should not disappear at any point. |
| 133 | void test_collapse10(SkCanvas* canvas, const SkPaint& paint) { |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 134 | SkPathBuilder path; |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 135 | path.moveTo( 5.5, 36.0); |
| 136 | path.lineTo(47.5, 5.0); |
| 137 | path.lineTo(90.0, 36.0); |
| 138 | path.lineTo(88.5, 36.0); |
| 139 | path.lineTo(47.5, 6.0); |
| 140 | path.lineTo( 7.0, 36.0); |
Mike Reed | 2243d77 | 2020-07-31 21:57:51 -0400 | [diff] [blame] | 141 | canvas->drawPath(path.detach(), paint); |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 142 | } |
| 143 | |
John Stiles | a6841be | 2020-08-06 14:11:56 -0400 | [diff] [blame] | 144 | } // namespace |
Stephen White | c4dbc37 | 2019-05-22 10:50:14 -0400 | [diff] [blame] | 145 | |
| 146 | DEF_SIMPLE_GM(collapsepaths, canvas, 500, 600) { |
| 147 | SkPaint paint; |
| 148 | |
| 149 | paint.setAntiAlias(true); |
| 150 | paint.setStyle(SkPaint::kFill_Style); |
| 151 | test_collapse1(canvas, paint); |
| 152 | test_collapse2(canvas, paint); |
| 153 | test_collapse3(canvas, paint); |
| 154 | test_collapse4(canvas, paint); |
| 155 | test_collapse5(canvas, paint); |
| 156 | test_collapse6(canvas, paint); |
| 157 | test_collapse7(canvas, paint); |
| 158 | test_collapse8(canvas, paint); |
| 159 | test_collapse9(canvas, paint); |
| 160 | test_collapse10(canvas, paint); |
| 161 | } |