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

Side by Side Diff: include/core/SkRRect.h

Issue 1373293002: Handle inverted rects in SkRRect creation methods (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed SK_ARRAY_COUNT error Created 5 years, 2 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 unified diff | Download patch
« no previous file with comments | « gm/roundrects.cpp ('k') | src/core/SkRRect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRRect_DEFINED 8 #ifndef SkRRect_DEFINED
9 #define SkRRect_DEFINED 9 #define SkRRect_DEFINED
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 memset(fRadii, 0, sizeof(fRadii)); 120 memset(fRadii, 0, sizeof(fRadii));
121 fType = kEmpty_Type; 121 fType = kEmpty_Type;
122 122
123 SkDEBUGCODE(this->validate();) 123 SkDEBUGCODE(this->validate();)
124 } 124 }
125 125
126 /** 126 /**
127 * Set this RR to match the supplied rect. All radii will be 0. 127 * Set this RR to match the supplied rect. All radii will be 0.
128 */ 128 */
129 void setRect(const SkRect& rect) { 129 void setRect(const SkRect& rect) {
130 if (rect.isEmpty()) { 130 fRect = rect;
131 fRect.sort();
132
133 if (fRect.isEmpty()) {
131 this->setEmpty(); 134 this->setEmpty();
132 return; 135 return;
133 } 136 }
134 137
135 fRect = rect;
136 memset(fRadii, 0, sizeof(fRadii)); 138 memset(fRadii, 0, sizeof(fRadii));
137 fType = kRect_Type; 139 fType = kRect_Type;
138 140
139 SkDEBUGCODE(this->validate();) 141 SkDEBUGCODE(this->validate();)
140 } 142 }
141 143
142 static SkRRect MakeRect(const SkRect& r) { 144 static SkRRect MakeRect(const SkRect& r) {
143 SkRRect rr; 145 SkRRect rr;
144 rr.setRect(r); 146 rr.setRect(r);
145 return rr; 147 return rr;
146 } 148 }
147 149
148 static SkRRect MakeOval(const SkRect& oval) { 150 static SkRRect MakeOval(const SkRect& oval) {
149 SkRRect rr; 151 SkRRect rr;
150 rr.setOval(oval); 152 rr.setOval(oval);
151 return rr; 153 return rr;
152 } 154 }
153 155
154 /** 156 /**
155 * Set this RR to match the supplied oval. All x radii will equal half the 157 * Set this RR to match the supplied oval. All x radii will equal half the
156 * width and all y radii will equal half the height. 158 * width and all y radii will equal half the height.
157 */ 159 */
158 void setOval(const SkRect& oval) { 160 void setOval(const SkRect& oval) {
159 if (oval.isEmpty()) { 161 fRect = oval;
162 fRect.sort();
163
164 if (fRect.isEmpty()) {
160 this->setEmpty(); 165 this->setEmpty();
161 return; 166 return;
162 } 167 }
163 168
164 SkScalar xRad = SkScalarHalf(oval.width()); 169 SkScalar xRad = SkScalarHalf(fRect.width());
165 SkScalar yRad = SkScalarHalf(oval.height()); 170 SkScalar yRad = SkScalarHalf(fRect.height());
166 171
167 fRect = oval;
168 for (int i = 0; i < 4; ++i) { 172 for (int i = 0; i < 4; ++i) {
169 fRadii[i].set(xRad, yRad); 173 fRadii[i].set(xRad, yRad);
170 } 174 }
171 fType = kOval_Type; 175 fType = kOval_Type;
172 176
173 SkDEBUGCODE(this->validate();) 177 SkDEBUGCODE(this->validate();)
174 } 178 }
175 179
176 /** 180 /**
177 * Initialize the RR with the same radii for all four corners. 181 * Initialize the RR with the same radii for all four corners.
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // uninitialized data 319 // uninitialized data
316 320
317 void computeType(); 321 void computeType();
318 bool checkCornerContainment(SkScalar x, SkScalar y) const; 322 bool checkCornerContainment(SkScalar x, SkScalar y) const;
319 323
320 // to access fRadii directly 324 // to access fRadii directly
321 friend class SkPath; 325 friend class SkPath;
322 }; 326 };
323 327
324 #endif 328 #endif
OLDNEW
« no previous file with comments | « gm/roundrects.cpp ('k') | src/core/SkRRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698