aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2018-02-13 12:48:57 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-13 18:14:20 +0000
commit655bf8f022a31b8a8624838d267b0e9cab0d8ef8 (patch)
tree51dadae4ad48b7dc3ab605342989ab70aaf103ac /include
parent0c6ea6c77ad39042759d781e65e3474ebc4ff7ee (diff)
saturate IPoint math, handle NaN in isEmpty
Bug: skia:7507 Change-Id: Ibdb40584effdea70e6499eab1bb64bb4b2260d06 Reviewed-on: https://skia-review.googlesource.com/106972 Commit-Queue: Mike Reed <reed@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/core/SkPoint.h13
-rw-r--r--include/core/SkRect.h18
2 files changed, 19 insertions, 12 deletions
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h
index 3ccc33e140..2d3a938693 100644
--- a/include/core/SkPoint.h
+++ b/include/core/SkPoint.h
@@ -10,6 +10,7 @@
#include "SkMath.h"
#include "SkScalar.h"
+#include "../private/SkSafe32.h"
/** \struct SkIPoint16
SkIPoint holds two 16 bit integer coordinates
@@ -115,8 +116,8 @@ struct SkIPoint {
@param v ivector to add
*/
void operator+=(const SkIVector& v) {
- fX += v.fX;
- fY += v.fY;
+ fX = Sk32_sat_add(fX, v.fX);
+ fY = Sk32_sat_add(fY, v.fY);
}
/** Subtracts ivector v from SkIPoint. Sets SkIPoint to: (fX - v.fX, fY - v.fY).
@@ -124,8 +125,8 @@ struct SkIPoint {
@param v ivector to subtract
*/
void operator-=(const SkIVector& v) {
- fX -= v.fX;
- fY -= v.fY;
+ fX = Sk32_sat_sub(fX, v.fX);
+ fY = Sk32_sat_sub(fY, v.fY);
}
/** Returns true if SkIPoint is equivalent to SkIPoint constructed from (x, y).
@@ -167,7 +168,7 @@ struct SkIPoint {
@return ivector from b to a
*/
friend SkIVector operator-(const SkIPoint& a, const SkIPoint& b) {
- return {a.fX - b.fX, a.fY - b.fY};
+ return { Sk32_sat_sub(a.fX, b.fX), Sk32_sat_sub(a.fY, b.fY) };
}
/** Returns SkIPoint resulting from SkIPoint a offset by ivector b, computed as: (a.fX + b.fX, a.fY + b.fY).
@@ -180,7 +181,7 @@ struct SkIPoint {
@return SkIPoint equal to a offset by b
*/
friend SkIPoint operator+(const SkIPoint& a, const SkIVector& b) {
- return {a.fX + b.fX, a.fY + b.fY};
+ return { Sk32_sat_add(a.fX, b.fX), Sk32_sat_add(a.fY, b.fY) };
}
};
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 5673980d49..ff7715853a 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -849,12 +849,18 @@ struct SK_API SkRect {
}
/** Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
- to or greater than fBottom. Call sort() to reverse rectangles with negative
- width() or height().
-
- @return true if width() or height() are zero or negative
- */
- bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; }
+ * to or greater than fBottom. Call sort() to reverse rectangles with negative
+ * width() or height().
+ *
+ * This function also returns true if any of the values are NaN.
+ *
+ * @return true if width() or height() are zero or negative
+ */
+ bool isEmpty() const {
+ // We write it as the NOT of a non-empty rect, so we will return true if any values
+ // are NaN.
+ return !(fLeft < fRight && fTop < fBottom);
+ }
/** Returns true if fLeft is equal to or less than fRight, or if fTop is equal
to or less than fBottom. Call sort() to reverse rectangles with negative