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

Unified Diff: include/core/SkRect.h

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Adding validation helper file Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: include/core/SkRect.h
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index d8919ae5d6b888d3195cc57ce7346bc905cf2a8c..d4cbed8089667ffd5e02ef0ba7b62e3bd6766964 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -100,6 +100,15 @@ struct SK_API SkIRect {
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+ bool isInverted() const { return fLeft > fRight || fTop > fBottom; }
+
+ bool isValid() const {
reed1 2013/09/04 18:49:36 Is this the same as return this->width() >= 0 &&
reed1 2013/09/04 18:49:36 Suggest we move this into SkValidatingUtils.h
sugoi1 2013/09/04 20:14:52 Done.
sugoi1 2013/09/04 20:14:52 Hmmm... I'm not sure. In the case of width(), for
+ return !isInverted() &&
+ // Make sure width() and height() are also valid
+ ((fLeft >= 0) || (fRight <= 0) || ((fRight - SK_MaxS32) <= fLeft)) &&
+ ((fTop >= 0) || (fBottom <= 0) || ((fBottom - SK_MaxS32) <= fTop));
+ }
+
bool isLargest() const { return SK_MinS32 == fLeft &&
SK_MinS32 == fTop &&
SK_MaxS32 == fRight &&
@@ -419,6 +428,17 @@ struct SK_API SkRect {
*/
bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+ bool isInverted() const { return fLeft > fRight || fTop > fBottom; }
+
+ bool isValid() const {
reed1 2013/09/04 18:49:36 Given the size an somewhat arbitrary nature of "va
sugoi1 2013/09/04 20:14:52 Done.
+ return SkScalarIsFinite(fLeft) &&
+ SkScalarIsFinite(fTop) &&
+ SkScalarIsFinite(fRight) &&
+ SkScalarIsFinite(fBottom) &&
+ !isInverted() &&
+ // Make sure width() and height() are also valid
+ ((fLeft >= 0) || (fRight <= 0) || ((fRight - SK_ScalarMax) <= fLeft)) &&
+ ((fTop >= 0) || (fBottom <= 0) || ((fBottom - SK_ScalarMax) <= fTop)); }
/**
* Returns true iff all values in the rect are finite. If any are
* infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this

Powered by Google App Engine
This is Rietveld 408576698