• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2011 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkSize_DEFINED
9 #define SkSize_DEFINED
10 
11 #include "include/core/SkScalar.h"
12 
13 struct SkISize {
14     int32_t fWidth;
15     int32_t fHeight;
16 
MakeSkISize17     static constexpr SkISize Make(int32_t w, int32_t h) { return {w, h}; }
18 
MakeEmptySkISize19     static constexpr SkISize MakeEmpty() { return {0, 0}; }
20 
setSkISize21     void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
22 
23     /** Returns true iff fWidth == 0 && fHeight == 0
24      */
isZeroSkISize25     bool isZero() const { return 0 == fWidth && 0 == fHeight; }
26 
27     /** Returns true if either width or height are <= 0 */
isEmptySkISize28     bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
29 
30     /** Set the width and height to 0 */
setEmptySkISize31     void setEmpty() { fWidth = fHeight = 0; }
32 
widthSkISize33     constexpr int32_t width() const { return fWidth; }
heightSkISize34     constexpr int32_t height() const { return fHeight; }
35 
areaSkISize36     constexpr int64_t area() const { return fWidth * fHeight; }
37 
equalsSkISize38     bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
39 };
40 
41 static inline bool operator==(const SkISize& a, const SkISize& b) {
42     return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
43 }
44 
45 static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
46 
47 ///////////////////////////////////////////////////////////////////////////////
48 
49 struct SkSize {
50     SkScalar fWidth;
51     SkScalar fHeight;
52 
MakeSkSize53     static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
54 
MakeSkSize55     static SkSize Make(const SkISize& src) {
56         return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
57     }
58 
MakeEmptySkSize59     static SkSize MakeEmpty() { return {0, 0}; }
60 
setSkSize61     void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
62 
63     /** Returns true iff fWidth == 0 && fHeight == 0
64      */
isZeroSkSize65     bool isZero() const { return 0 == fWidth && 0 == fHeight; }
66 
67     /** Returns true if either width or height are <= 0 */
isEmptySkSize68     bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
69 
70     /** Set the width and height to 0 */
setEmptySkSize71     void setEmpty() { *this = SkSize{0, 0}; }
72 
widthSkSize73     SkScalar width() const { return fWidth; }
heightSkSize74     SkScalar height() const { return fHeight; }
75 
equalsSkSize76     bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; }
77 
toRoundSkSize78     SkISize toRound() const { return {SkScalarRoundToInt(fWidth), SkScalarRoundToInt(fHeight)}; }
79 
toCeilSkSize80     SkISize toCeil() const { return {SkScalarCeilToInt(fWidth), SkScalarCeilToInt(fHeight)}; }
81 
toFloorSkSize82     SkISize toFloor() const { return {SkScalarFloorToInt(fWidth), SkScalarFloorToInt(fHeight)}; }
83 };
84 
85 static inline bool operator==(const SkSize& a, const SkSize& b) {
86     return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
87 }
88 
89 static inline bool operator!=(const SkSize& a, const SkSize& b) { return !(a == b); }
90 #endif
91