Skia
2D Graphics Library
SkSize.h
Go to the documentation of this file.
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 #include <cstdint>
14 
15 struct SkISize {
16  int32_t fWidth;
17  int32_t fHeight;
18 
19  static constexpr SkISize Make(int32_t w, int32_t h) { return {w, h}; }
20 
21  static constexpr SkISize MakeEmpty() { return {0, 0}; }
22 
23  void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
24 
27  bool isZero() const { return 0 == fWidth && 0 == fHeight; }
28 
30  bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
31 
33  void setEmpty() { fWidth = fHeight = 0; }
34 
35  constexpr int32_t width() const { return fWidth; }
36  constexpr int32_t height() const { return fHeight; }
37 
38  constexpr int64_t area() const { return fWidth * fHeight; }
39 
40  bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
41 };
42 
43 static inline bool operator==(const SkISize& a, const SkISize& b) {
44  return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
45 }
46 
47 static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
48 
50 
51 struct SkSize {
54 
55  static constexpr SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
56 
57  static constexpr SkSize Make(const SkISize& src) {
58  return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
59  }
60 
61  static constexpr SkSize MakeEmpty() { return {0, 0}; }
62 
63  void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
64 
67  bool isZero() const { return 0 == fWidth && 0 == fHeight; }
68 
70  bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
71 
73  void setEmpty() { *this = SkSize{0, 0}; }
74 
75  SkScalar width() const { return fWidth; }
76  SkScalar height() const { return fHeight; }
77 
78  bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; }
79 
81 
83 
85 };
86 
87 static inline bool operator==(const SkSize& a, const SkSize& b) {
88  return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
89 }
90 
91 static inline bool operator!=(const SkSize& a, const SkSize& b) { return !(a == b); }
92 #endif
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:35
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:34
#define SkIntToScalar(x)
Definition: SkScalar.h:55
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:33
float SkScalar
Definition: SkScalar.h:14
static bool operator!=(const SkISize &a, const SkISize &b)
Definition: SkSize.h:47
static bool operator==(const SkISize &a, const SkISize &b)
Definition: SkSize.h:43
Definition: SkSize.h:15
static constexpr SkISize MakeEmpty()
Definition: SkSize.h:21
bool equals(int32_t w, int32_t h) const
Definition: SkSize.h:40
bool isEmpty() const
Returns true if either width or height are <= 0.
Definition: SkSize.h:30
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:19
int32_t fHeight
Definition: SkSize.h:17
void setEmpty()
Set the width and height to 0.
Definition: SkSize.h:33
int32_t fWidth
Definition: SkSize.h:16
constexpr int32_t width() const
Definition: SkSize.h:35
void set(int32_t w, int32_t h)
Definition: SkSize.h:23
constexpr int32_t height() const
Definition: SkSize.h:36
bool isZero() const
Returns true iff fWidth == 0 && fHeight == 0.
Definition: SkSize.h:27
constexpr int64_t area() const
Definition: SkSize.h:38
Definition: SkSize.h:51
static constexpr SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:55
static constexpr SkSize Make(const SkISize &src)
Definition: SkSize.h:57
SkISize toRound() const
Definition: SkSize.h:80
void set(SkScalar w, SkScalar h)
Definition: SkSize.h:63
bool isEmpty() const
Returns true if either width or height are <= 0.
Definition: SkSize.h:70
SkISize toCeil() const
Definition: SkSize.h:82
bool isZero() const
Returns true iff fWidth == 0 && fHeight == 0.
Definition: SkSize.h:67
bool equals(SkScalar w, SkScalar h) const
Definition: SkSize.h:78
void setEmpty()
Set the width and height to 0.
Definition: SkSize.h:73
SkScalar fHeight
Definition: SkSize.h:53
SkISize toFloor() const
Definition: SkSize.h:84
SkScalar width() const
Definition: SkSize.h:75
static constexpr SkSize MakeEmpty()
Definition: SkSize.h:61
SkScalar fWidth
Definition: SkSize.h:52
SkScalar height() const
Definition: SkSize.h:76