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
|
|
|
|
|
2012-11-26 20:18:00 +00:00
|
|
|
#include "SkScalar.h"
|
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
struct SkISize {
|
|
|
|
int32_t fWidth;
|
|
|
|
int32_t fHeight;
|
2010-02-11 11:09:39 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static SkISize Make(int32_t w, int32_t h) { return {w, h}; }
|
2017-03-10 15:49:45 +00:00
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
static SkISize MakeEmpty() { return {0, 0}; }
|
|
|
|
|
|
|
|
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
|
|
|
|
2009-05-08 16:45:52 +00:00
|
|
|
/** Returns true if either widht 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
|
|
|
|
2017-04-11 16:12:02 +00:00
|
|
|
int32_t width() const { return fWidth; }
|
|
|
|
int32_t height() const { return fHeight; }
|
2012-08-23 18:09: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
|
|
|
|
2009-05-08 16:45:52 +00:00
|
|
|
SkSize& operator=(const SkISize& src) {
|
2017-04-11 16:12:02 +00:00
|
|
|
return *this = SkSize{SkIntToScalar(src.fWidth), SkIntToScalar(src.fHeight)};
|
2009-05-08 16:45:52 +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; }
|
|
|
|
|
|
|
|
/** Returns true if either widht or height are <= 0 */
|
|
|
|
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
|