diff options
author | Cary Clark <caryclark@skia.org> | 2017-11-09 16:03:40 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-11-09 21:37:27 +0000 |
commit | ba2526bc6690250a37fcc70f6e2cea96653d01f6 (patch) | |
tree | aae1fe07db269eb84344cf240131de8debfee557 /include | |
parent | 98c5b8b4811fbda4f4e59c1c7b9b0b32d5cfe180 (diff) |
replace some points with vectors to clarify documentation
Some SkIPoint and SkPoint methods become clearer if their
parameters or return value is typed as a vector.
Since SkPoint is identical to SkVector (and SkIPoint is
identical to newly added SkIVector) this has no impact
on compiled code.
Some routines arguably have multiple possible point and
vector combinations which will be included in eventual
documentation; the interface should have the most common
and/or logical choice.
Some of my choices could be argued with as well. Does
SkPoint::Normalize take a SkPoint? Afternative points
of view encouraged.
R=reed@google.com,bsalomon@google.com
Bug: skia:6898
Change-Id: I2429b9d43b20351188d7c6433620a2e221f75bd8
Reviewed-on: https://skia-review.googlesource.com/69680
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Cary Clark <caryclark@skia.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkPoint.h | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/include/core/SkPoint.h b/include/core/SkPoint.h index 744abb77f5..57f0fd7d18 100644 --- a/include/core/SkPoint.h +++ b/include/core/SkPoint.h @@ -32,6 +32,9 @@ struct SkIPoint16 { } }; +struct SkIPoint; +typedef SkIPoint SkIVector; + /** \struct SkIPoint SkIPoint holds two 32 bit integer coordinates @@ -66,13 +69,13 @@ struct SkIPoint { } /** Add v's coordinates to this point's */ - void operator+=(const SkIPoint& v) { + void operator+=(const SkIVector& v) { fX += v.fX; fY += v.fY; } /** Subtract v's coordinates from this point's */ - void operator-=(const SkIPoint& v) { + void operator-=(const SkIVector& v) { fX -= v.fX; fY -= v.fY; } @@ -93,17 +96,20 @@ struct SkIPoint { /** Returns a new point whose coordinates are the difference between a and b (i.e. a - b) */ - friend SkIPoint operator-(const SkIPoint& a, const SkIPoint& b) { + friend SkIVector operator-(const SkIPoint& a, const SkIPoint& b) { return {a.fX - b.fX, a.fY - b.fY}; } /** Returns a new point whose coordinates are the sum of a and b (a + b) */ - friend SkIPoint operator+(const SkIPoint& a, const SkIPoint& b) { + friend SkIPoint operator+(const SkIPoint& a, const SkIVector& b) { return {a.fX + b.fX, a.fY + b.fY}; } }; +struct SkPoint; +typedef SkPoint SkVector; + struct SK_API SkPoint { SkScalar fX; SkScalar fY; @@ -147,7 +153,7 @@ struct SK_API SkPoint { fY = SkScalarAbs(pt.fY); } - static void Offset(SkPoint points[], int count, const SkPoint& offset) { + static void Offset(SkPoint points[], int count, const SkVector& offset) { Offset(points, count, offset.fX, offset.fY); } @@ -216,14 +222,14 @@ struct SK_API SkPoint { /** Add v's coordinates to the point's */ - void operator+=(const SkPoint& v) { + void operator+=(const SkVector& v) { fX += v.fX; fY += v.fY; } /** Subtract v's coordinates from the point's */ - void operator-=(const SkPoint& v) { + void operator-=(const SkVector& v) { fX -= v.fX; fY -= v.fY; } @@ -272,13 +278,13 @@ struct SK_API SkPoint { /** Returns a new point whose coordinates are the difference between a's and b's (a - b) */ - friend SkPoint operator-(const SkPoint& a, const SkPoint& b) { + friend SkVector operator-(const SkPoint& a, const SkPoint& b) { return {a.fX - b.fX, a.fY - b.fY}; } /** Returns a new point whose coordinates are the sum of a's and b's (a + b) */ - friend SkPoint operator+(const SkPoint& a, const SkPoint& b) { + friend SkPoint operator+(const SkPoint& a, const SkVector& b) { return {a.fX + b.fX, a.fY + b.fY}; } @@ -295,7 +301,7 @@ struct SK_API SkPoint { of the point. If you don't need the previous length, call the non-static normalize() method instead. */ - static SkScalar Normalize(SkPoint* pt); + static SkScalar Normalize(SkVector* vec); /** Returns the euclidian distance between a and b */ @@ -305,26 +311,24 @@ struct SK_API SkPoint { /** Returns the dot product of a and b, treating them as 2D vectors */ - static SkScalar DotProduct(const SkPoint& a, const SkPoint& b) { + static SkScalar DotProduct(const SkVector& a, const SkVector& b) { return a.fX * b.fX + a.fY * b.fY; } /** Returns the cross product of a and b, treating them as 2D vectors */ - static SkScalar CrossProduct(const SkPoint& a, const SkPoint& b) { + static SkScalar CrossProduct(const SkVector& a, const SkVector& b) { return a.fX * b.fY - a.fY * b.fX; } - SkScalar cross(const SkPoint& vec) const { + SkScalar cross(const SkVector& vec) const { return CrossProduct(*this, vec); } - SkScalar dot(const SkPoint& vec) const { + SkScalar dot(const SkVector& vec) const { return DotProduct(*this, vec); } }; -typedef SkPoint SkVector; - #endif |