blob: 6b714323bb687878501cfca68e1d54ae15cde86e [file] [log] [blame]
Stephen Whitec4dbc372019-05-22 10:50:14 -04001/*
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 Klein4b432fa2019-06-06 11:44:05 -05008#include "gm/gm.h"
Stephen Whitec4dbc372019-05-22 10:50:14 -04009#include "include/core/SkCanvas.h"
Mike Reed2243d772020-07-31 21:57:51 -040010#include "include/core/SkPathBuilder.h"
Stephen Whitec4dbc372019-05-22 10:50:14 -040011
12namespace {
13
14void test_collapse1(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040015 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040016 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 Reed7d34dc72019-11-26 12:17:17 -050024 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -040025 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040026}
27
28void test_collapse2(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040029 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040030 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 Reed2243d772020-07-31 21:57:51 -040037 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040038}
39
40void test_collapse3(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040041 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040042 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 Reed2243d772020-07-31 21:57:51 -040049 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040050}
51
52void test_collapse4(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040053 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040054 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 Reed2243d772020-07-31 21:57:51 -040061 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040062}
63
64void test_collapse5(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040065 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040066 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 Reed7d34dc72019-11-26 12:17:17 -050073 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -040074 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040075}
76
77void test_collapse6(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040078 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040079 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 Reed7d34dc72019-11-26 12:17:17 -050086 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -040087 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -040088}
89
90void test_collapse7(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -040091 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -040092 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 Reed7d34dc72019-11-26 12:17:17 -050099 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -0400100 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -0400101}
102
103void test_collapse8(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -0400104 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -0400105 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 Reed7d34dc72019-11-26 12:17:17 -0500112 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -0400113 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -0400114}
115
116void test_collapse9(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -0400117 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -0400118 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 Reed7d34dc72019-11-26 12:17:17 -0500128 path.setFillType(SkPathFillType::kEvenOdd);
Mike Reed2243d772020-07-31 21:57:51 -0400129 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -0400130}
131
132// This one is a thin inverted 'v', but the edges should not disappear at any point.
133void test_collapse10(SkCanvas* canvas, const SkPaint& paint) {
Mike Reed2243d772020-07-31 21:57:51 -0400134 SkPathBuilder path;
Stephen Whitec4dbc372019-05-22 10:50:14 -0400135 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 Reed2243d772020-07-31 21:57:51 -0400141 canvas->drawPath(path.detach(), paint);
Stephen Whitec4dbc372019-05-22 10:50:14 -0400142}
143
John Stilesa6841be2020-08-06 14:11:56 -0400144} // namespace
Stephen Whitec4dbc372019-05-22 10:50:14 -0400145
146DEF_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}