Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 58627cb

Browse files
cary-clarkSkia Commit-Bot
authored andcommitted
one more path is rect bug
Add a check to see that the close path generated line is horizontal or vertical when determining that path is a rect. Also change several tests to defer their initialization to reduce debugging interference. R=brianosman@google.com,robertphillips@google.com Bug: 824145,skia:7792 Change-Id: I4a081ee4ffd3558b499a7a1aede2d6232059715e Reviewed-on: https://skia-review.googlesource.com/120081 Reviewed-by: Brian Osman <brianosman@google.com> Commit-Queue: Cary Clark <caryclark@google.com>
1 parent 5c71518 commit 58627cb

File tree

6 files changed

+35
-27
lines changed

6 files changed

+35
-27
lines changed

gm/shapes.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,15 @@ namespace skiagm {
1919
class ShapesGM : public GM {
2020
protected:
2121
ShapesGM(const char* name, bool antialias) : fName(name), fAntialias(antialias) {
22+
if (!antialias) {
23+
fName.append("_bw");
24+
}
25+
}
26+
27+
SkString onShortName() override final { return fName; }
28+
SkISize onISize() override { return SkISize::Make(500, 500); }
29+
30+
void onOnceBeforeDraw() override {
2231
fShapes.push_back().setOval(SkRect::MakeXYWH(-5, 25, 200, 100));
2332
fRotations.push_back(21);
2433

@@ -50,15 +59,6 @@ class ShapesGM : public GM {
5059
fShapes.push_back().setRectRadii(SkRect::MakeXYWH(180, -30, 80, 60), radii2);
5160
fRotations.push_back(295);
5261

53-
if (!antialias) {
54-
fName.append("_bw");
55-
}
56-
}
57-
58-
SkString onShortName() override final { return fName; }
59-
SkISize onISize() override { return SkISize::Make(500, 500); }
60-
61-
void onOnceBeforeDraw() override {
6262
fPaint.setAntiAlias(fAntialias);
6363
}
6464

samplecode/SampleAARects.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,24 @@ class AARectView : public SampleView {
3838
enum {
3939
N = 64
4040
};
41-
public:
42-
AARectView() {
41+
42+
protected:
43+
void onOnceBeforeDraw() override {
4344
fBitmap = createBitmap(N);
4445

4546
fWidth = N;
4647
}
4748

48-
protected:
4949
// overrides from SkEventSink
50-
virtual bool onQuery(SkEvent* evt) {
50+
bool onQuery(SkEvent* evt) override {
5151
if (SampleCode::TitleQ(*evt)) {
5252
SampleCode::TitleR(evt, "AA Rects");
5353
return true;
5454
}
5555
return this->INHERITED::onQuery(evt);
5656
}
5757

58-
virtual void onDrawContent(SkCanvas* canvas) {
58+
void onDrawContent(SkCanvas* canvas) override {
5959
canvas->translate(SkIntToScalar(10), SkIntToScalar(10));
6060

6161
SkPaint bluePaint;

samplecode/SampleColorFilter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ class ColorFilterView : public SampleView {
113113
enum {
114114
N = 64
115115
};
116-
public:
117-
ColorFilterView() {
116+
117+
protected:
118+
void onOnceBeforeDraw() override {
118119
fBitmap = createBitmap(N);
119120
fShader = sk_tool_utils::create_checkerboard_shader(
120121
0xFFCCCCCC, 0xFFFFFFFF, 12);
@@ -124,23 +125,22 @@ class ColorFilterView : public SampleView {
124125
}
125126
}
126127

127-
protected:
128128
// overrides from SkEventSink
129-
virtual bool onQuery(SkEvent* evt) {
129+
bool onQuery(SkEvent* evt) override {
130130
if (SampleCode::TitleQ(*evt)) {
131131
SampleCode::TitleR(evt, "ColorFilter");
132132
return true;
133133
}
134134
return this->INHERITED::onQuery(evt);
135135
}
136136

137-
virtual void onDrawBackground(SkCanvas* canvas) {
137+
void onDrawBackground(SkCanvas* canvas) override {
138138
SkPaint paint;
139139
paint.setShader(fShader);
140140
canvas->drawPaint(paint);
141141
}
142142

143-
virtual void onDrawContent(SkCanvas* canvas) {
143+
void onDrawContent(SkCanvas* canvas) override {
144144
if (false) {
145145
SkPaint p;
146146
p.setAntiAlias(true);

samplecode/SampleDither.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ class DitherView : public SampleView {
108108
SkBitmap fBM, fBMPreDither, fBM16;
109109
SkScalar fAngle;
110110

111-
DitherView() {
111+
protected:
112+
void onOnceBeforeDraw() override {
112113
make_bm(&fBM);
113114
make_bm(&fBMPreDither);
114115
pre_dither(fBMPreDither);
@@ -119,17 +120,16 @@ class DitherView : public SampleView {
119120
this->setBGColor(0xFF181818);
120121
}
121122

122-
protected:
123123
// overrides from SkEventSink
124-
virtual bool onQuery(SkEvent* evt) {
124+
bool onQuery(SkEvent* evt) override {
125125
if (SampleCode::TitleQ(*evt)) {
126126
SampleCode::TitleR(evt, "Dither");
127127
return true;
128128
}
129129
return this->INHERITED::onQuery(evt);
130130
}
131131

132-
virtual void onDrawContent(SkCanvas* canvas) {
132+
void onDrawContent(SkCanvas* canvas) override {
133133
SkPaint paint;
134134
SkScalar x = SkIntToScalar(10);
135135
SkScalar y = SkIntToScalar(10);

src/core/SkPath.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,16 +539,17 @@ bool SkPath::isRectContour(bool allowPartial, int* currVerb, const SkPoint** pts
539539
;
540540
}
541541
// Success if 4 corners and first point equals last
542-
bool result = 4 == corners && (first == last || autoClose);
542+
SkScalar closeX = first.x() - last.x();
543+
SkScalar closeY = first.y() - last.y();
544+
// If autoClose, check if close generates diagonal
545+
bool result = 4 == corners && (first == last || (autoClose && (!closeX || !closeY)));
543546
if (!result) {
544547
// check if we are just an incomplete rectangle, in which case we can
545548
// return true, but not claim to be closed.
546549
// e.g.
547550
// 3 sided rectangle
548551
// 4 sided but the last edge is not long enough to reach the start
549552
//
550-
SkScalar closeX = first.x() - last.x();
551-
SkScalar closeY = first.y() - last.y();
552553
if (closeX && closeY) {
553554
return false; // we're diagonal, abort (can we ever reach this?)
554555
}

tests/PathTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4911,4 +4911,11 @@ DEF_TEST(Path_isRect, reporter) {
49114911
SkRect compare;
49124912
compare.set(&points[1], SK_ARRAY_COUNT(points) - 1);
49134913
REPORTER_ASSERT(reporter, rect == compare);
4914+
path.reset();
4915+
SkPoint points2[] = { {75, 50}, {100, 75}, {150, 75}, {150, 150}, {75, 150}, {75, 50} };
4916+
for (size_t index = 0; index < SK_ARRAY_COUNT(points); ++index) {
4917+
index < 2 ? path.moveTo(points2[index]) : path.lineTo(points2[index]);
4918+
}
4919+
path.close();
4920+
REPORTER_ASSERT(reporter, !path.isRect(&rect, nullptr, nullptr));
49144921
}

0 commit comments

Comments
 (0)