aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-31 19:59:23 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-10-31 19:59:23 +0000
commite1e7d7a6b55504d97ce9f30202a179b63800093b (patch)
tree23b401593aa2a415d55f1bd705a2806055fbfa87
parent4d3c28158a65f9eac6b472dff29caa77b44f8134 (diff)
add SkScalarsEqual() so we don't have to use memcmp for arrays of floats.
git-svn-id: http://skia.googlecode.com/svn/trunk@6226 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--include/core/SkRect.h4
-rw-r--r--include/core/SkScalar.h17
2 files changed, 19 insertions, 2 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 21a37364d4..89014b365d 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -401,11 +401,11 @@ struct SK_API SkRect {
SkScalar centerY() const { return SkScalarHalf(fTop + fBottom); }
friend bool operator==(const SkRect& a, const SkRect& b) {
- return 0 == memcmp(&a, &b, sizeof(a));
+ return SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
}
friend bool operator!=(const SkRect& a, const SkRect& b) {
- return 0 != memcmp(&a, &b, sizeof(a));
+ return !SkScalarsEqual((SkScalar*)&a, (SkScalar*)&b, 4);
}
/** return the 4 points that enclose the rectangle
diff --git a/include/core/SkScalar.h b/include/core/SkScalar.h
index f357e6a05f..82ac6e33cf 100644
--- a/include/core/SkScalar.h
+++ b/include/core/SkScalar.h
@@ -355,4 +355,21 @@ static inline SkScalar SkScalarLog2(SkScalar x) {
SkScalar SkScalarInterpFunc(SkScalar searchKey, const SkScalar keys[],
const SkScalar values[], int length);
+/*
+ * Helper to compare an array of scalars.
+ */
+static inline bool SkScalarsEqual(const SkScalar a[], const SkScalar b[], int n) {
+#ifdef SK_SCALAR_IS_FLOAT
+ SkASSERT(n >= 0);
+ for (int i = 0; i < n; ++i) {
+ if (a[i] != b[i]) {
+ return false;
+ }
+ }
+ return true;
+#else
+ return 0 == memcmp(a, b, n * sizeof(SkScalar));
+#endif
+}
+
#endif