diff options
author | Hal Canary <halcanary@google.com> | 2017-04-11 12:12:02 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-04-11 18:57:20 +0000 |
commit | fafe135349bd34961a12bfd8185733709cd0e45e (patch) | |
tree | b40dbd0a0787901843aba62eec1f21a1fe3936e1 /include | |
parent | 8a8e5fe290307952f9b8df1eb680eed52d83eca9 (diff) |
SkSize can be aggregate-initialized
Previosly, SkSize had a base class, which prevented it.
Also removes unused SkISize::clampNegToZero() and
SkSize::clampNegToZero().
Change-Id: I7b93b42f6f6381c66e294bbedee99ad53c6c3436
Reviewed-on: https://skia-review.googlesource.com/13187
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/core/SkSize.h | 121 |
1 files changed, 48 insertions, 73 deletions
diff --git a/include/core/SkSize.h b/include/core/SkSize.h index 153335da68..061e3c4ca2 100644 --- a/include/core/SkSize.h +++ b/include/core/SkSize.h @@ -10,108 +10,83 @@ #include "SkScalar.h" -template <typename T> struct SkTSize { - T fWidth; - T fHeight; - - static SkTSize Make(T w, T h) { - SkTSize s; - s.fWidth = w; - s.fHeight = h; - return s; - } +struct SkISize { + int32_t fWidth; + int32_t fHeight; - static SkTSize MakeEmpty() { - return {0, 0}; - } + static SkISize Make(int32_t w, int32_t h) { return {w, h}; } - void set(T w, T h) { - fWidth = w; - fHeight = h; - } + static SkISize MakeEmpty() { return {0, 0}; } + + void set(int32_t w, int32_t h) { *this = SkISize{w, h}; } /** Returns true iff fWidth == 0 && fHeight == 0 */ - bool isZero() const { - return 0 == fWidth && 0 == fHeight; - } + bool isZero() const { return 0 == fWidth && 0 == fHeight; } /** Returns true if either widht or height are <= 0 */ - bool isEmpty() const { - return fWidth <= 0 || fHeight <= 0; - } + bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } /** Set the width and height to 0 */ - void setEmpty() { - fWidth = fHeight = 0; - } + void setEmpty() { fWidth = fHeight = 0; } - T width() const { return fWidth; } - T height() const { return fHeight; } - - /** If width or height is < 0, it is set to 0 */ - void clampNegToZero() { - if (fWidth < 0) { - fWidth = 0; - } - if (fHeight < 0) { - fHeight = 0; - } - } + int32_t width() const { return fWidth; } + int32_t height() const { return fHeight; } - bool equals(T w, T h) const { - return fWidth == w && fHeight == h; - } + bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; } }; -template <typename T> -static inline bool operator==(const SkTSize<T>& a, const SkTSize<T>& b) { +static inline bool operator==(const SkISize& a, const SkISize& b) { return a.fWidth == b.fWidth && a.fHeight == b.fHeight; } -template <typename T> -static inline bool operator!=(const SkTSize<T>& a, const SkTSize<T>& b) { - return !(a == b); -} +static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); } /////////////////////////////////////////////////////////////////////////////// -typedef SkTSize<int32_t> SkISize; +struct SkSize { + SkScalar fWidth; + SkScalar fHeight; -struct SkSize : public SkTSize<SkScalar> { - static SkSize Make(SkScalar w, SkScalar h) { - SkSize s; - s.fWidth = w; - s.fHeight = h; - return s; - } + static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; } static SkSize Make(const SkISize& src) { - return Make(SkIntToScalar(src.width()), SkIntToScalar(src.height())); + return {SkIntToScalar(src.width()), SkIntToScalar(src.height())}; } SkSize& operator=(const SkISize& src) { - this->set(SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)); - return *this; + return *this = SkSize{SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)}; } - SkISize toRound() const { - SkISize s; - s.set(SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight)); - return s; - } + static SkSize MakeEmpty() { return {0, 0}; } - SkISize toCeil() const { - SkISize s; - s.set(SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight)); - return s; - } + void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; } - SkISize toFloor() const { - SkISize s; - s.set(SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight)); - return s; - } + /** Returns true iff fWidth == 0 && fHeight == 0 + */ + bool isZero() const { return 0 == fWidth && 0 == fHeight; } + + /** Returns true if either widht or height are <= 0 */ + bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; } + + /** Set the width and height to 0 */ + void setEmpty() { *this = SkSize{0, 0}; } + + SkScalar width() const { return fWidth; } + SkScalar height() const { return fHeight; } + + bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; } + + SkISize toRound() const { return {SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight)}; } + + SkISize toCeil() const { return {SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight)}; } + + SkISize toFloor() const { return {SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight)}; } }; +static inline bool operator==(const SkSize& a, const SkSize& b) { + return a.fWidth == b.fWidth && a.fHeight == b.fHeight; +} + +static inline bool operator!=(const SkSize& a, const SkSize& b) { return !(a == b); } #endif |