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