2011-07-28 14:26:00 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2009-05-08 16:45:52 +00:00
|
|
|
#ifndef SkSize_DEFINED
|
|
|
|
#define SkSize_DEFINED
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkScalar.h"
|
2012-11-26 20:18:00 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
struct SkISize {
|
|
|
|
int32_t fWidth;
|
|
|
|
int32_t fHeight;
|
2010-02-11 11:09:39 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
static constexpr SkISize Make(int32_t w, int32_t h) { return {w, h}; }
|
2017-03-10 15:49:45 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
static constexpr SkISize MakeEmpty() { return {0, 0}; }
|
2017-04-11 16:12:02 +00:00
|
|
|
|
|
|
|
void set(int32_t w, int32_t h) { *this = SkISize{w, h}; }
|
2009-05-08 16:45:52 +00:00
|
|
|
|
2009-05-13 14:00:33 +00:00
|
|
|
/** Returns true iff fWidth == 0 && fHeight == 0
|
|
|
|
*/
|
2017-04-11 16:12:02 +00:00
|
|
|
bool isZero() const { return 0 == fWidth && 0 == fHeight; }
|
2009-05-13 14:00:33 +00:00
|
|
|
|
2018-09-27 05:11:55 +00:00
|
|
|
/** Returns true if either width or height are <= 0 */
|
2017-04-11 16:12:02 +00:00
|
|
|
bool isEmpty() const { return fWidth <= 0 || fHeight <= 0; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2009-05-08 16:45:52 +00:00
|
|
|
/** Set the width and height to 0 */
|
2017-04-11 16:12:02 +00:00
|
|
|
void setEmpty() { fWidth = fHeight = 0; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2019-12-04 16:05:35 +00:00
|
|
|
constexpr int32_t width() const { return fWidth; }
|
|
|
|
constexpr int32_t height() const { return fHeight; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2020-02-07 19:17:25 +00:00
|
|
|
constexpr int64_t area() const { return fWidth * fHeight; }
|
2019-11-04 20:04:54 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
bool equals(int32_t w, int32_t h) const { return fWidth == w && fHeight == h; }
|
2009-05-08 16:45:52 +00:00
|
|
|
};
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static inline bool operator==(const SkISize& a, const SkISize& b) {
|
2009-05-08 16:45:52 +00:00
|
|
|
return a.fWidth == b.fWidth && a.fHeight == b.fHeight;
|
|
|
|
}
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static inline bool operator!=(const SkISize& a, const SkISize& b) { return !(a == b); }
|
2009-05-08 16:45:52 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
struct SkSize {
|
|
|
|
SkScalar fWidth;
|
|
|
|
SkScalar fHeight;
|
2009-05-08 16:45:52 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static SkSize Make(SkScalar w, SkScalar h) { return {w, h}; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-02-17 22:06:11 +00:00
|
|
|
static SkSize Make(const SkISize& src) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return {SkIntToScalar(src.width()), SkIntToScalar(src.height())};
|
2017-02-17 22:06:11 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static SkSize MakeEmpty() { return {0, 0}; }
|
2010-06-15 00:57:50 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
void set(SkScalar w, SkScalar h) { *this = SkSize{w, h}; }
|
2009-05-08 16:45:52 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
/** Returns true iff fWidth == 0 && fHeight == 0
|
|
|
|
*/
|
|
|
|
bool isZero() const { return 0 == fWidth && 0 == fHeight; }
|
|
|
|
|
2018-11-08 22:55:48 +00:00
|
|
|
/** Returns true if either width or height are <= 0 */
|
2017-04-11 16:12:02 +00:00
|
|
|
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)}; }
|
2009-05-08 16:45:52 +00:00
|
|
|
};
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
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); }
|
2009-05-08 16:45:52 +00:00
|
|
|
#endif
|