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 struct SkISize {
14  int32_t fWidth;
15  int32_t fHeight;
16 
17  static constexpr SkISize Make(int32_t w, int32_t h) { return {w, h}; }
18 
19  static constexpr SkISize MakeEmpty() { return {0, 0}; }
20 
21  void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
22 
25  bool isZero() const { return 0 == fWidth && 0 == fHeight; }
26 
28  bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
29 
31  void setEmpty() { fWidth = fHeight = 0; }
32 
33  constexpr int32_t width() const { return fWidth; }
34  constexpr int32_t height() const { return fHeight; }
35 
36  constexpr int64_t area() const { return fWidth * fHeight; }
37 
38  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 
48 
49 struct SkSize {
52 
53  static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
54 
55  static SkSize Make(const SkISize& src) {
56  return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
57  }
58 
59  static SkSize MakeEmpty() { return {0, 0}; }
60 
61  void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
62 
65  bool isZero() const { return 0 == fWidth && 0 == fHeight; }
66 
68  bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
69 
71  void setEmpty() { *this = SkSize{0, 0}; }
72 
73  SkScalar width() const { return fWidth; }
74  SkScalar height() const { return fHeight; }
75 
76  bool equals(SkScalar w, SkScalar h) const { return fWidth == w && fHeight == h; }
77 
79 
81 
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
SkSize::toFloor
SkISize toFloor() const
Definition: SkSize.h:82
SkScalarRoundToInt
#define SkScalarRoundToInt(x)
Definition: SkScalar.h:36
SkSize::set
void set(SkScalar w, SkScalar h)
Definition: SkSize.h:61
SkISize::fHeight
int32_t fHeight
Definition: SkSize.h:15
SkSize::Make
static SkSize Make(const SkISize &src)
Definition: SkSize.h:55
SkSize::toCeil
SkISize toCeil() const
Definition: SkSize.h:80
SkISize::width
constexpr int32_t width() const
Definition: SkSize.h:33
SkSize::equals
bool equals(SkScalar w, SkScalar h) const
Definition: SkSize.h:76
SkScalar.h
operator==
static bool operator==(const SkISize &a, const SkISize &b)
Definition: SkSize.h:41
SkISize::equals
bool equals(int32_t w, int32_t h) const
Definition: SkSize.h:38
SkSize::isEmpty
bool isEmpty() const
Returns true if either width or height are <= 0.
Definition: SkSize.h:68
SkISize
Definition: SkSize.h:13
SkSize
Definition: SkSize.h:49
SkSize::isZero
bool isZero() const
Returns true iff fWidth == 0 && fHeight == 0.
Definition: SkSize.h:65
SkSize::fHeight
SkScalar fHeight
Definition: SkSize.h:51
SkISize::Make
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:17
SkISize::isZero
bool isZero() const
Returns true iff fWidth == 0 && fHeight == 0.
Definition: SkSize.h:25
SkSize::MakeEmpty
static SkSize MakeEmpty()
Definition: SkSize.h:59
SkScalar
float SkScalar
Definition: SkScalar.h:16
SkISize::isEmpty
bool isEmpty() const
Returns true if either width or height are <= 0.
Definition: SkSize.h:28
SkSize::toRound
SkISize toRound() const
Definition: SkSize.h:78
SkSize::Make
static SkSize Make(SkScalar w, SkScalar h)
Definition: SkSize.h:53
SkISize::height
constexpr int32_t height() const
Definition: SkSize.h:34
SkScalarCeilToInt
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:35
SkSize::setEmpty
void setEmpty()
Set the width and height to 0.
Definition: SkSize.h:71
SkSize::width
SkScalar width() const
Definition: SkSize.h:73
SkISize::setEmpty
void setEmpty()
Set the width and height to 0.
Definition: SkSize.h:31
SkISize::area
constexpr int64_t area() const
Definition: SkSize.h:36
SkIntToScalar
#define SkIntToScalar(x)
Definition: SkScalar.h:56
SkScalarFloorToInt
#define SkScalarFloorToInt(x)
Definition: SkScalar.h:34
SkISize::MakeEmpty
static constexpr SkISize MakeEmpty()
Definition: SkSize.h:19
SkSize::height
SkScalar height() const
Definition: SkSize.h:74
SkSize::fWidth
SkScalar fWidth
Definition: SkSize.h:50
SkISize::set
void set(int32_t w, int32_t h)
Definition: SkSize.h:21
SkISize::fWidth
int32_t fWidth
Definition: SkSize.h:14
operator!=
static bool operator!=(const SkISize &a, const SkISize &b)
Definition: SkSize.h:45