2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-08 15:49:19 +00:00
|
|
|
/* Generated by tools/bookmaker from include/core/SkRect.h and docs/SkRect_Reference.bmh
|
2018-07-13 12:21:59 +00:00
|
|
|
on 2018-07-13 08:15:11. Additional documentation and examples can be found at:
|
2018-06-08 15:49:19 +00:00
|
|
|
https://skia.org/user/api/SkRect_Reference
|
|
|
|
|
|
|
|
You may edit either file directly. Structural changes to public interfaces require
|
|
|
|
editing both files. After editing docs/SkRect_Reference.bmh, run:
|
|
|
|
bookmaker -b docs -i include/core/SkRect.h -p
|
|
|
|
to create an updated version of this file.
|
|
|
|
*/
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkRect_DEFINED
|
|
|
|
#define SkRect_DEFINED
|
|
|
|
|
|
|
|
#include "SkPoint.h"
|
2010-02-24 01:49:13 +00:00
|
|
|
#include "SkSize.h"
|
2018-01-30 21:01:33 +00:00
|
|
|
#include "../private/SkSafe32.h"
|
2017-09-20 15:56:00 +00:00
|
|
|
#include "../private/SkTFitsIn.h"
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2018-06-18 19:11:00 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2015-02-23 22:44:57 +00:00
|
|
|
struct SkRect;
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/** \struct SkIRect
|
2018-05-30 13:20:29 +00:00
|
|
|
SkIRect holds four 32-bit integer coordinates describing the upper and
|
2017-10-30 15:48:35 +00:00
|
|
|
lower bounds of a rectangle. SkIRect may be created from outer bounds or
|
|
|
|
from position, width, and height. SkIRect describes an area; if its right
|
|
|
|
is less than or equal to its left, or if its bottom is less than or equal to
|
|
|
|
its top, it is considered empty.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
struct SK_API SkIRect {
|
2018-05-30 13:20:29 +00:00
|
|
|
int32_t fLeft; //!< smaller x-axis bounds
|
|
|
|
int32_t fTop; //!< smaller y-axis bounds
|
|
|
|
int32_t fRight; //!< larger x-axis bounds
|
|
|
|
int32_t fBottom; //!< larger y-axis bounds
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to (0, 0, 0, 0).
|
|
|
|
Many other rectangles are empty; if left is equal to or greater than right,
|
|
|
|
or if top is equal to or greater than bottom. Setting all members to zero
|
|
|
|
is a convenience, but does not designate a special empty rectangle.
|
|
|
|
|
|
|
|
@return bounds (0, 0, 0, 0)
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeEmpty() {
|
|
|
|
return SkIRect{0, 0, 0, 0};
|
2010-07-13 18:35:14 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-01-08 20:05:02 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_RECTMAKELARGEST
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Deprecated.
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2013-07-24 22:19:24 +00:00
|
|
|
static SkIRect SK_WARN_UNUSED_RESULT MakeLargest() {
|
2018-01-08 20:05:02 +00:00
|
|
|
return { SK_MinS32, SK_MinS32, SK_MaxS32, SK_MaxS32 };
|
2013-07-24 22:19:24 +00:00
|
|
|
}
|
2018-01-08 20:05:02 +00:00
|
|
|
#endif
|
2013-07-24 22:19:24 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to (0, 0, w, h). Does not validate input; w or h
|
|
|
|
may be negative.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param w width of constructed SkIRect
|
|
|
|
@param h height of constructed SkIRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return bounds (0, 0, w, h)
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeWH(int32_t w, int32_t h) {
|
|
|
|
return SkIRect{0, 0, w, h};
|
2010-07-13 18:35:14 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
|
|
|
|
Does not validate input; size.width() or size.height() may be negative.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param size values for SkIRect width and height
|
2017-10-30 15:48:35 +00:00
|
|
|
@return bounds (0, 0, size.width(), size.height())
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeSize(const SkISize& size) {
|
|
|
|
return SkIRect{0, 0, size.fWidth, size.fHeight};
|
2010-07-13 18:35:14 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns constructed SkIRect set to (l, t, r, b). Does not sort input; SkIRect may
|
2017-10-30 15:48:35 +00:00
|
|
|
result in fLeft greater than fRight, or fTop greater than fBottom.
|
|
|
|
|
|
|
|
@param l integer stored in fLeft
|
|
|
|
@param t integer stored in fTop
|
|
|
|
@param r integer stored in fRight
|
|
|
|
@param b integer stored in fBottom
|
|
|
|
@return bounds (l, t, r, b)
|
|
|
|
*/
|
2018-01-30 21:01:33 +00:00
|
|
|
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeLTRB(int32_t l, int32_t t,
|
|
|
|
int32_t r, int32_t b) {
|
2017-10-05 15:27:53 +00:00
|
|
|
return SkIRect{l, t, r, b};
|
2010-07-13 18:35:14 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to: (x, y, x + w, y + h). Does not validate input;
|
|
|
|
w or h may be negative.
|
|
|
|
|
|
|
|
@param x stored in fLeft
|
|
|
|
@param y stored in fTop
|
|
|
|
@param w added to x and stored in fRight
|
|
|
|
@param h added to y and stored in fBottom
|
|
|
|
@return bounds at (x, y) with width w and height h
|
|
|
|
*/
|
2018-01-30 21:01:33 +00:00
|
|
|
static constexpr SkIRect SK_WARN_UNUSED_RESULT MakeXYWH(int32_t x, int32_t y,
|
|
|
|
int32_t w, int32_t h) {
|
|
|
|
return { x, y, Sk32_sat_add(x, w), Sk32_sat_add(y, h) };
|
2010-07-13 18:35:14 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns left edge of SkIRect, if sorted.
|
|
|
|
Call sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fLeft
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t left() const { return fLeft; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns top edge of SkIRect, if sorted. Call isEmpty() to see if SkIRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fTop
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t top() const { return fTop; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns right edge of SkIRect, if sorted.
|
|
|
|
Call sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fRight
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t right() const { return fRight; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns bottom edge of SkIRect, if sorted. Call isEmpty() to see if SkIRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fBottom
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t bottom() const { return fBottom; }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns left edge of SkIRect, if sorted. Call isEmpty() to see if SkIRect may be invalid,
|
|
|
|
and sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fLeft
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t x() const { return fLeft; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns top edge of SkIRect, if sorted. Call isEmpty() to see if SkIRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fTop
|
|
|
|
*/
|
2018-01-03 20:35:33 +00:00
|
|
|
int32_t y() const { return fTop; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns span on the x-axis. This does not check if SkIRect is sorted, or if
|
|
|
|
result fits in 32-bit signed integer; result may be negative.
|
|
|
|
|
|
|
|
@return fRight minus fLeft
|
|
|
|
*/
|
2018-01-30 21:01:33 +00:00
|
|
|
int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns span on the y-axis. This does not check if SkIRect is sorted, or if
|
|
|
|
result fits in 32-bit signed integer; result may be negative.
|
|
|
|
|
|
|
|
@return fBottom minus fTop
|
|
|
|
*/
|
2018-01-30 21:01:33 +00:00
|
|
|
int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns spans on the x-axis and y-axis. This does not check if SkIRect is sorted,
|
|
|
|
or if result fits in 32-bit signed integer; result may be negative.
|
|
|
|
|
|
|
|
@return SkISize (width, height)
|
|
|
|
*/
|
2014-10-15 14:05:09 +00:00
|
|
|
SkISize size() const { return SkISize::Make(this->width(), this->height()); }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns span on the x-axis. This does not check if SkIRect is sorted, so the
|
|
|
|
result may be negative. This is safer than calling width() since width() might
|
|
|
|
overflow in its calculation.
|
|
|
|
|
|
|
|
@return fRight minus fLeft cast to int64_t
|
|
|
|
*/
|
2018-01-09 16:31:53 +00:00
|
|
|
int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
|
2018-02-27 15:22:04 +00:00
|
|
|
|
|
|
|
/** Returns span on the y-axis. This does not check if SkIRect is sorted, so the
|
|
|
|
result may be negative. This is safer than calling height() since height() might
|
|
|
|
overflow in its calculation.
|
|
|
|
|
|
|
|
@return fBottom minus fTop cast to int64_t
|
|
|
|
*/
|
2018-01-09 16:31:53 +00:00
|
|
|
int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
|
|
|
|
to or greater than fBottom. Call sort() to reverse rectangles with negative
|
|
|
|
width64() or height64().
|
|
|
|
|
|
|
|
@return true if width64() or height64() are zero or negative
|
|
|
|
*/
|
2018-01-10 19:31:18 +00:00
|
|
|
bool isEmpty64() const { return fRight <= fLeft || fBottom <= fTop; }
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if width() or height() .
|
|
|
|
|
|
|
|
@return true if width() or height() are zero or negative
|
|
|
|
*/
|
2018-01-09 16:31:53 +00:00
|
|
|
bool isEmpty() const {
|
|
|
|
int64_t w = this->width64();
|
|
|
|
int64_t h = this->height64();
|
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// Return true if either exceeds int32_t
|
2017-09-20 15:56:00 +00:00
|
|
|
return !SkTFitsIn<int32_t>(w | h);
|
2018-01-09 16:31:53 +00:00
|
|
|
}
|
2013-07-24 22:19:24 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
|
|
|
|
identical to corresponding members in b.
|
|
|
|
|
|
|
|
@param a SkIRect to compare
|
|
|
|
@param b SkIRect to compare
|
|
|
|
@return true if members are equal
|
|
|
|
*/
|
2011-07-20 19:55:42 +00:00
|
|
|
friend bool operator==(const SkIRect& a, const SkIRect& b) {
|
2008-12-17 15:59:43 +00:00
|
|
|
return !memcmp(&a, &b, sizeof(a));
|
|
|
|
}
|
2010-02-19 21:41:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if any member in a: fLeft, fTop, fRight, and fBottom; is not
|
|
|
|
identical to the corresponding member in b.
|
|
|
|
|
|
|
|
@param a SkIRect to compare
|
|
|
|
@param b SkIRect to compare
|
|
|
|
@return true if members are not equal
|
|
|
|
*/
|
2011-07-20 19:55:42 +00:00
|
|
|
friend bool operator!=(const SkIRect& a, const SkIRect& b) {
|
|
|
|
return !(a == b);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
Many other rectangles are empty; if left is equal to or greater than right,
|
|
|
|
or if top is equal to or greater than bottom. Setting all members to zero
|
|
|
|
is a convenience, but does not designate a special empty rectangle.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void setEmpty() { memset(this, 0, sizeof(*this)); }
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect to (left, top, right, bottom).
|
|
|
|
left and right are not sorted; left is not necessarily less than right.
|
|
|
|
top and bottom are not sorted; top is not necessarily less than bottom.
|
|
|
|
|
|
|
|
@param left assigned to fLeft
|
|
|
|
@param top assigned to fTop
|
|
|
|
@param right assigned to fRight
|
|
|
|
@param bottom assigned to fBottom
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void set(int32_t left, int32_t top, int32_t right, int32_t bottom) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft = left;
|
|
|
|
fTop = top;
|
|
|
|
fRight = right;
|
|
|
|
fBottom = bottom;
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Sets SkIRect to (left, top, right, bottom).
|
|
|
|
left and right are not sorted; left is not necessarily less than right.
|
|
|
|
top and bottom are not sorted; top is not necessarily less than bottom.
|
|
|
|
|
|
|
|
@param left stored in fLeft
|
|
|
|
@param top stored in fTop
|
|
|
|
@param right stored in fRight
|
|
|
|
@param bottom stored in fBottom
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
void setLTRB(int32_t left, int32_t top, int32_t right, int32_t bottom) {
|
|
|
|
this->set(left, top, right, bottom);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect to: (x, y, x + width, y + height). Does not validate input;
|
|
|
|
width or height may be negative.
|
|
|
|
|
|
|
|
@param x stored in fLeft
|
|
|
|
@param y stored in fTop
|
|
|
|
@param width added to x and stored in fRight
|
|
|
|
@param height added to y and stored in fBottom
|
|
|
|
*/
|
2011-03-03 13:23:35 +00:00
|
|
|
void setXYWH(int32_t x, int32_t y, int32_t width, int32_t height) {
|
2018-01-30 21:01:33 +00:00
|
|
|
fLeft = x;
|
|
|
|
fTop = y;
|
|
|
|
fRight = Sk32_sat_add(x, width);
|
|
|
|
fBottom = Sk32_sat_add(y, height);
|
2011-03-03 13:23:35 +00:00
|
|
|
}
|
2011-05-09 17:00:02 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect offset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkIRect returned is moved to the left.
|
|
|
|
If dx is positive, SkIRect returned is moved to the right.
|
|
|
|
If dy is negative, SkIRect returned is moved upward.
|
|
|
|
If dy is positive, SkIRect returned is moved downward.
|
|
|
|
|
|
|
|
@param dx offset added to fLeft and fRight
|
|
|
|
@param dy offset added to fTop and fBottom
|
2018-06-14 17:21:08 +00:00
|
|
|
@return SkIRect offset by dx and dy, with original width and height
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2015-03-13 13:08:28 +00:00
|
|
|
SkIRect makeOffset(int32_t dx, int32_t dy) const {
|
2018-01-30 21:01:33 +00:00
|
|
|
return {
|
|
|
|
Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
|
|
|
|
Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
|
|
|
|
};
|
2014-06-02 21:38:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect, inset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkIRect returned is wider.
|
|
|
|
If dx is positive, SkIRect returned is narrower.
|
|
|
|
If dy is negative, SkIRect returned is taller.
|
|
|
|
If dy is positive, SkIRect returned is shorter.
|
|
|
|
|
|
|
|
@param dx offset added to fLeft and subtracted from fRight
|
|
|
|
@param dy offset added to fTop and subtracted from fBottom
|
2018-02-27 15:22:04 +00:00
|
|
|
@return SkIRect inset symmetrically left and right, top and bottom
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2015-03-13 13:08:28 +00:00
|
|
|
SkIRect makeInset(int32_t dx, int32_t dy) const {
|
2018-01-30 21:01:33 +00:00
|
|
|
return {
|
|
|
|
Sk32_sat_add(fLeft, dx), Sk32_sat_add(fTop, dy),
|
|
|
|
Sk32_sat_sub(fRight, dx), Sk32_sat_sub(fBottom, dy),
|
|
|
|
};
|
2014-06-02 21:38:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect, outset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkIRect returned is narrower.
|
|
|
|
If dx is positive, SkIRect returned is wider.
|
|
|
|
If dy is negative, SkIRect returned is shorter.
|
|
|
|
If dy is positive, SkIRect returned is taller.
|
|
|
|
|
|
|
|
@param dx offset subtracted to fLeft and added from fRight
|
|
|
|
@param dy offset subtracted to fTop and added from fBottom
|
2018-02-27 15:22:04 +00:00
|
|
|
@return SkIRect outset symmetrically left and right, top and bottom
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2015-03-13 13:08:28 +00:00
|
|
|
SkIRect makeOutset(int32_t dx, int32_t dy) const {
|
2018-01-30 21:01:33 +00:00
|
|
|
return {
|
|
|
|
Sk32_sat_sub(fLeft, dx), Sk32_sat_sub(fTop, dy),
|
|
|
|
Sk32_sat_add(fRight, dx), Sk32_sat_add(fBottom, dy),
|
|
|
|
};
|
2015-03-13 13:08:28 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkIRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
|
|
|
|
|
|
|
|
If dx is negative, moves SkIRect returned to the left.
|
|
|
|
If dx is positive, moves SkIRect returned to the right.
|
|
|
|
If dy is negative, moves SkIRect returned upward.
|
|
|
|
If dy is positive, moves SkIRect returned downward.
|
|
|
|
|
|
|
|
@param dx offset added to fLeft and fRight
|
|
|
|
@param dy offset added to fTop and fBottom
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void offset(int32_t dx, int32_t dy) {
|
2018-01-30 21:01:33 +00:00
|
|
|
fLeft = Sk32_sat_add(fLeft, dx);
|
|
|
|
fTop = Sk32_sat_add(fTop, dy);
|
|
|
|
fRight = Sk32_sat_add(fRight, dx);
|
|
|
|
fBottom = Sk32_sat_add(fBottom, dy);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkIRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
|
|
|
|
fTop, fBottom.
|
|
|
|
|
|
|
|
If delta.fX is negative, moves SkIRect returned to the left.
|
|
|
|
If delta.fX is positive, moves SkIRect returned to the right.
|
|
|
|
If delta.fY is negative, moves SkIRect returned upward.
|
|
|
|
If delta.fY is positive, moves SkIRect returned downward.
|
|
|
|
|
|
|
|
@param delta offset added to SkIRect
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void offset(const SkIPoint& delta) {
|
|
|
|
this->offset(delta.fX, delta.fY);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkIRect so that fLeft equals newX, and fTop equals newY. width and height
|
|
|
|
are unchanged.
|
|
|
|
|
|
|
|
@param newX stored in fLeft, preserving width()
|
|
|
|
@param newY stored in fTop, preserving height()
|
|
|
|
*/
|
2012-11-06 22:02:51 +00:00
|
|
|
void offsetTo(int32_t newX, int32_t newY) {
|
2018-01-30 21:01:33 +00:00
|
|
|
fRight = Sk64_pin_to_s32((int64_t)fRight + newX - fLeft);
|
|
|
|
fBottom = Sk64_pin_to_s32((int64_t)fBottom + newY - fTop);
|
|
|
|
fLeft = newX;
|
|
|
|
fTop = newY;
|
2012-11-06 22:02:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Insets SkIRect by (dx,dy).
|
|
|
|
|
|
|
|
If dx is positive, makes SkIRect narrower.
|
|
|
|
If dx is negative, makes SkIRect wider.
|
|
|
|
If dy is positive, makes SkIRect shorter.
|
|
|
|
If dy is negative, makes SkIRect taller.
|
|
|
|
|
|
|
|
@param dx offset added to fLeft and subtracted from fRight
|
|
|
|
@param dy offset added to fTop and subtracted from fBottom
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void inset(int32_t dx, int32_t dy) {
|
2018-01-30 21:01:33 +00:00
|
|
|
fLeft = Sk32_sat_add(fLeft, dx);
|
|
|
|
fTop = Sk32_sat_add(fTop, dy);
|
|
|
|
fRight = Sk32_sat_sub(fRight, dx);
|
|
|
|
fBottom = Sk32_sat_sub(fBottom, dy);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2010-02-19 21:41:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Outsets SkIRect by (dx, dy).
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
If dx is positive, makes SkIRect wider.
|
|
|
|
If dx is negative, makes SkIRect narrower.
|
|
|
|
If dy is positive, makes SkIRect taller.
|
|
|
|
If dy is negative, makes SkIRect shorter.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param dx subtracted to fLeft and added from fRight
|
|
|
|
@param dy subtracted to fTop and added from fBottom
|
2012-05-15 16:47:23 +00:00
|
|
|
*/
|
|
|
|
void outset(int32_t dx, int32_t dy) { this->inset(-dx, -dy); }
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Adjusts SkIRect by adding dL to fLeft, dT to fTop, dR to fRight, and dB to fBottom.
|
2018-05-18 14:19:05 +00:00
|
|
|
|
|
|
|
If dL is positive, narrows SkIRect on the left. If negative, widens it on the left.
|
|
|
|
If dT is positive, shrinks SkIRect on the top. If negative, lengthens it on the top.
|
|
|
|
If dR is positive, narrows SkIRect on the right. If negative, widens it on the right.
|
|
|
|
If dB is positive, shrinks SkIRect on the bottom. If negative, lengthens it on the bottom.
|
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
The resulting SkIRect is not checked for validity. Thus, if the resulting SkIRect left is
|
|
|
|
greater than right, the SkIRect will be considered empty. Call sort() after this call
|
|
|
|
if that is not the desired behavior.
|
|
|
|
|
2018-05-18 14:19:05 +00:00
|
|
|
@param dL offset added to fLeft
|
|
|
|
@param dT offset added to fTop
|
|
|
|
@param dR offset added to fRight
|
|
|
|
@param dB offset added to fBottom
|
|
|
|
*/
|
|
|
|
void adjust(int32_t dL, int32_t dT, int32_t dR, int32_t dB) {
|
|
|
|
fLeft = Sk32_sat_add(fLeft, dL);
|
|
|
|
fTop = Sk32_sat_add(fTop, dT);
|
|
|
|
fRight = Sk32_sat_add(fRight, dR);
|
|
|
|
fBottom = Sk32_sat_add(fBottom, dB);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if SkIRect is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
Considers input to describe constructed SkIRect: (x, y, x + 1, y + 1) and
|
|
|
|
returns true if constructed area is completely enclosed by SkIRect area.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param x test SkIPoint x-coordinate
|
|
|
|
@param y test SkIPoint y-coordinate
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if (x, y) is inside SkIRect
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
bool contains(int32_t x, int32_t y) const {
|
2018-02-09 21:16:12 +00:00
|
|
|
return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort
|
2017-10-30 15:48:35 +00:00
|
|
|
construction.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns true if SkIRect contains construction.
|
|
|
|
Returns false if SkIRect is empty or construction is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkIRect
|
|
|
|
@param top y-axis minimum of constructed SkIRect
|
|
|
|
@param right x-axis maximum of constructed SkIRect
|
|
|
|
@param bottom y-axis maximum of constructed SkIRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if all sides of SkIRect are outside construction
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
bool contains(int32_t left, int32_t top, int32_t right, int32_t bottom) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
return left < right && top < bottom && !this->isEmpty() && // check for empties
|
|
|
|
fLeft <= left && fTop <= top &&
|
|
|
|
fRight >= right && fBottom >= bottom;
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkIRect contains r.
|
|
|
|
Returns false if SkIRect is empty or r is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
SkIRect contains r when SkIRect area completely includes r area.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param r SkIRect contained
|
|
|
|
@return true if all sides of SkIRect are outside r
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
bool contains(const SkIRect& r) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
return !r.isEmpty() && !this->isEmpty() && // check for empties
|
|
|
|
fLeft <= r.fLeft && fTop <= r.fTop &&
|
|
|
|
fRight >= r.fRight && fBottom >= r.fBottom;
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkIRect contains r.
|
|
|
|
Returns false if SkIRect is empty or r is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
SkIRect contains r when SkIRect area completely includes r area.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param r SkRect contained
|
|
|
|
@return true if all sides of SkIRect are outside r
|
2015-02-23 22:44:57 +00:00
|
|
|
*/
|
|
|
|
bool contains(const SkRect& r) const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Constructs SkIRect from (left, top, right, bottom). Does not sort
|
|
|
|
construction.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns true if SkIRect contains construction.
|
2017-10-30 15:48:35 +00:00
|
|
|
Asserts if SkIRect is empty or construction is empty, and if SK_DEBUG is defined.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Return is undefined if SkIRect is empty or construction is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkIRect
|
|
|
|
@param top y-axis minimum of constructed SkIRect
|
|
|
|
@param right x-axis maximum of constructed SkIRect
|
|
|
|
@param bottom y-axis maximum of constructed SkIRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if all sides of SkIRect are outside construction
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
bool containsNoEmptyCheck(int32_t left, int32_t top,
|
2012-05-10 14:50:44 +00:00
|
|
|
int32_t right, int32_t bottom) const {
|
|
|
|
SkASSERT(fLeft < fRight && fTop < fBottom);
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(left < right && top < bottom);
|
|
|
|
|
|
|
|
return fLeft <= left && fTop <= top &&
|
2012-05-10 14:50:44 +00:00
|
|
|
fRight >= right && fBottom >= bottom;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns true if SkIRect contains construction.
|
2017-10-30 15:48:35 +00:00
|
|
|
Asserts if SkIRect is empty or construction is empty, and if SK_DEBUG is defined.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Return is undefined if SkIRect is empty or construction is empty.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param r SkIRect contained
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if all sides of SkIRect are outside r
|
|
|
|
*/
|
2012-05-31 18:28:59 +00:00
|
|
|
bool containsNoEmptyCheck(const SkIRect& r) const {
|
|
|
|
return containsNoEmptyCheck(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkIRect intersects r, and sets SkIRect to intersection.
|
|
|
|
Returns false if SkIRect does not intersect r, and leaves SkIRect unchanged.
|
|
|
|
|
|
|
|
Returns false if either r or SkIRect is empty, leaving SkIRect unchanged.
|
|
|
|
|
|
|
|
@param r limit of result
|
2018-02-27 15:22:04 +00:00
|
|
|
@return true if r and SkIRect have area in common
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-03-07 19:55:37 +00:00
|
|
|
bool intersect(const SkIRect& r) {
|
2018-01-10 19:31:18 +00:00
|
|
|
return this->intersect(*this, r);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b, and sets SkIRect to intersection.
|
|
|
|
Returns false if a does not intersect b, and leaves SkIRect unchanged.
|
|
|
|
|
2018-01-10 19:31:18 +00:00
|
|
|
Asserts if either a or b is empty, and if SK_DEBUG is defined.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param a SkIRect to intersect
|
|
|
|
@param b SkIRect to intersect
|
|
|
|
@return true if a and b have area in common
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2018-01-10 19:31:18 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
|
|
|
|
SkASSERT(!a.isEmpty64() && !b.isEmpty64());
|
|
|
|
SkIRect r = {
|
|
|
|
SkMax32(a.fLeft, b.fLeft),
|
|
|
|
SkMax32(a.fTop, b.fTop),
|
|
|
|
SkMin32(a.fRight, b.fRight),
|
|
|
|
SkMin32(a.fBottom, b.fBottom)
|
|
|
|
};
|
|
|
|
if (r.isEmpty()) {
|
|
|
|
return false;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2018-01-10 19:31:18 +00:00
|
|
|
*this = r;
|
|
|
|
return true;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b, and sets SkIRect to intersection.
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if a does not intersect b, and leaves SkIRect unchanged.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Returns false if either a or b is empty, leaving SkIRect unchanged.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param a SkIRect to intersect
|
|
|
|
@param b SkIRect to intersect
|
|
|
|
@return true if a and b have area in common
|
|
|
|
*/
|
2018-01-10 19:31:18 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) {
|
|
|
|
if (a.isEmpty64() || b.isEmpty64()) {
|
|
|
|
return false;
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2018-01-10 19:31:18 +00:00
|
|
|
return this->intersectNoEmptyCheck(a, b);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort
|
|
|
|
construction.
|
|
|
|
|
|
|
|
Returns true if SkIRect intersects construction, and sets SkIRect to intersection.
|
|
|
|
Returns false if SkIRect does not intersect construction, and leaves SkIRect unchanged.
|
|
|
|
|
|
|
|
Returns false if either construction or SkIRect is empty, leaving SkIRect unchanged.
|
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkIRect
|
|
|
|
@param top y-axis minimum of constructed SkIRect
|
|
|
|
@param right x-axis maximum of constructed SkIRect
|
|
|
|
@param bottom y-axis maximum of constructed SkIRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if construction and SkIRect have area in common
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-03-31 14:03:45 +00:00
|
|
|
bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) {
|
2018-01-10 19:31:18 +00:00
|
|
|
return this->intersect(*this, {left, top, right, bottom});
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b.
|
|
|
|
Returns false if either a or b is empty, or do not intersect.
|
|
|
|
|
|
|
|
@param a SkIRect to intersect
|
|
|
|
@param b SkIRect to intersect
|
|
|
|
@return true if a and b have area in common
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
static bool Intersects(const SkIRect& a, const SkIRect& b) {
|
2018-01-10 19:31:18 +00:00
|
|
|
SkIRect dummy;
|
|
|
|
return dummy.intersect(a, b);
|
2012-05-31 18:28:59 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b.
|
|
|
|
Asserts if either a or b is empty, and if SK_DEBUG is defined.
|
|
|
|
|
|
|
|
@param a SkIRect to intersect
|
|
|
|
@param b SkIRect to intersect
|
|
|
|
@return true if a and b have area in common
|
|
|
|
*/
|
2012-05-31 18:28:59 +00:00
|
|
|
static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) {
|
2018-01-10 19:31:18 +00:00
|
|
|
SkIRect dummy;
|
|
|
|
return dummy.intersectNoEmptyCheck(a, b);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Constructs SkIRect to intersect from (left, top, right, bottom). Does not sort
|
2017-10-30 15:48:35 +00:00
|
|
|
construction.
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Sets SkIRect to the union of itself and the construction.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Has no effect if construction is empty. Otherwise, if SkIRect is empty, sets
|
|
|
|
SkIRect to construction.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkIRect
|
|
|
|
@param top y-axis minimum of constructed SkIRect
|
|
|
|
@param right x-axis maximum of constructed SkIRect
|
|
|
|
@param bottom y-axis maximum of constructed SkIRect
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
void join(int32_t left, int32_t top, int32_t right, int32_t bottom);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Sets SkIRect to the union of itself and r.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
Has no effect if r is empty. Otherwise, if SkIRect is empty, sets SkIRect to r.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
@param r expansion SkIRect
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void join(const SkIRect& r) {
|
2008-12-17 15:59:43 +00:00
|
|
|
this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
|
|
|
|
fTop and fBottom if fTop is greater than fBottom. Result may be empty,
|
|
|
|
and width() and height() will be zero or positive.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-05-12 15:21:36 +00:00
|
|
|
void sort() {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
2017-05-12 15:21:36 +00:00
|
|
|
if (fLeft > fRight) {
|
2018-06-18 19:11:00 +00:00
|
|
|
swap(fLeft, fRight);
|
2017-05-12 15:21:36 +00:00
|
|
|
}
|
|
|
|
if (fTop > fBottom) {
|
2018-06-18 19:11:00 +00:00
|
|
|
swap(fTop, fBottom);
|
2017-05-12 15:21:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Returns SkIRect with fLeft and fRight swapped if fLeft is greater than fRight; and
|
2017-10-30 15:48:35 +00:00
|
|
|
with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
|
|
|
|
and width() and height() will be zero or positive.
|
|
|
|
|
|
|
|
@return sorted SkIRect
|
|
|
|
*/
|
2017-05-12 15:21:36 +00:00
|
|
|
SkIRect makeSorted() const {
|
|
|
|
return MakeLTRB(SkMin32(fLeft, fRight), SkMin32(fTop, fBottom),
|
|
|
|
SkMax32(fLeft, fRight), SkMax32(fTop, fBottom));
|
|
|
|
}
|
2011-05-09 17:00:02 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns a reference to immutable empty SkIRect, set to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
@return global SkIRect set to all zeroes
|
|
|
|
*/
|
2012-05-10 14:50:44 +00:00
|
|
|
static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect() {
|
2011-05-16 18:24:19 +00:00
|
|
|
static const SkIRect gEmpty = { 0, 0, 0, 0 };
|
2011-05-09 17:00:02 +00:00
|
|
|
return gEmpty;
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** \struct SkRect
|
2017-10-30 15:48:35 +00:00
|
|
|
SkRect holds four SkScalar coordinates describing the upper and
|
|
|
|
lower bounds of a rectangle. SkRect may be created from outer bounds or
|
|
|
|
from position, width, and height. SkRect describes an area; if its right
|
|
|
|
is less than or equal to its left, or if its bottom is less than or equal to
|
|
|
|
its top, it is considered empty.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
struct SK_API SkRect {
|
2018-05-30 13:20:29 +00:00
|
|
|
SkScalar fLeft; //!< smaller x-axis bounds
|
|
|
|
SkScalar fTop; //!< smaller y-axis bounds
|
|
|
|
SkScalar fRight; //!< larger x-axis bounds
|
|
|
|
SkScalar fBottom; //!< larger y-axis bounds
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns constructed SkRect set to (0, 0, 0, 0).
|
|
|
|
Many other rectangles are empty; if left is equal to or greater than right,
|
|
|
|
or if top is equal to or greater than bottom. Setting all members to zero
|
|
|
|
is a convenience, but does not designate a special empty rectangle.
|
|
|
|
|
|
|
|
@return bounds (0, 0, 0, 0)
|
|
|
|
*/
|
2016-05-13 16:23:38 +00:00
|
|
|
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeEmpty() {
|
|
|
|
return SkRect{0, 0, 0, 0};
|
2010-04-12 21:21:59 +00:00
|
|
|
}
|
|
|
|
|
2018-01-08 20:05:02 +00:00
|
|
|
#ifdef SK_SUPPORT_LEGACY_RECTMAKELARGEST
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Deprecated.
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2013-10-10 13:51:19 +00:00
|
|
|
static SkRect SK_WARN_UNUSED_RESULT MakeLargest() {
|
2018-01-08 20:05:02 +00:00
|
|
|
return { SK_ScalarMin, SK_ScalarMin, SK_ScalarMax, SK_ScalarMax };
|
2017-10-09 22:58:53 +00:00
|
|
|
}
|
2018-01-08 20:05:02 +00:00
|
|
|
#endif
|
2017-10-09 22:58:53 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkRect set to SkScalar values (0, 0, w, h). Does not
|
|
|
|
validate input; w or h may be negative.
|
|
|
|
|
|
|
|
Passing integer values may generate a compiler warning since SkRect cannot
|
|
|
|
represent 32-bit integers exactly. Use SkIRect for an exact integer rectangle.
|
|
|
|
|
|
|
|
@param w SkScalar width of constructed SkRect
|
|
|
|
@param h SkScalar height of constructed SkRect
|
|
|
|
@return bounds (0, 0, w, h)
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeWH(SkScalar w, SkScalar h) {
|
|
|
|
return SkRect{0, 0, w, h};
|
2010-04-12 21:21:59 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkRect set to integer values (0, 0, w, h). Does not validate
|
|
|
|
input; w or h may be negative.
|
|
|
|
|
|
|
|
Use to avoid a compiler warning that input may lose precision when stored.
|
|
|
|
Use SkIRect for an exact integer rectangle.
|
|
|
|
|
|
|
|
@param w integer width of constructed SkRect
|
|
|
|
@param h integer height of constructed SkRect
|
|
|
|
@return bounds (0, 0, w, h)
|
|
|
|
*/
|
2014-12-15 21:42:51 +00:00
|
|
|
static SkRect SK_WARN_UNUSED_RESULT MakeIWH(int w, int h) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(0, 0, SkIntToScalar(w), SkIntToScalar(h));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkRect set to (0, 0, size.width(), size.height()). Does not
|
|
|
|
validate input; size.width() or size.height() may be negative.
|
|
|
|
|
|
|
|
@param size SkScalar values for SkRect width and height
|
|
|
|
@return bounds (0, 0, size.width(), size.height())
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeSize(const SkSize& size) {
|
|
|
|
return SkRect{0, 0, size.fWidth, size.fHeight};
|
2010-02-24 01:49:13 +00:00
|
|
|
}
|
2013-01-17 07:06:06 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkRect set to (l, t, r, b). Does not sort input; SkRect may
|
|
|
|
result in fLeft greater than fRight, or fTop greater than fBottom.
|
|
|
|
|
|
|
|
@param l SkScalar stored in fLeft
|
|
|
|
@param t SkScalar stored in fTop
|
|
|
|
@param r SkScalar stored in fRight
|
|
|
|
@param b SkScalar stored in fBottom
|
|
|
|
@return bounds (l, t, r, b)
|
|
|
|
*/
|
2016-07-18 14:31:13 +00:00
|
|
|
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeLTRB(SkScalar l, SkScalar t, SkScalar r,
|
|
|
|
SkScalar b) {
|
|
|
|
return SkRect {l, t, r, b};
|
2010-02-24 01:49:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkRect set to (x, y, x + w, y + h). Does not validate input;
|
|
|
|
w or h may be negative.
|
|
|
|
|
|
|
|
@param x stored in fLeft
|
|
|
|
@param y stored in fTop
|
|
|
|
@param w added to x and stored in fRight
|
|
|
|
@param h added to y and stored in fBottom
|
|
|
|
@return bounds at (x, y) with width w and height h
|
|
|
|
*/
|
2017-10-05 15:27:53 +00:00
|
|
|
static constexpr SkRect SK_WARN_UNUSED_RESULT MakeXYWH(SkScalar x, SkScalar y, SkScalar w, SkScalar h) {
|
|
|
|
return SkRect {x, y, x + w, y + h};
|
2012-11-07 16:17:24 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Deprecated.
|
|
|
|
*/
|
2013-10-31 17:28:30 +00:00
|
|
|
SK_ATTR_DEPRECATED("use Make()")
|
2012-11-07 16:17:24 +00:00
|
|
|
static SkRect SK_WARN_UNUSED_RESULT MakeFromIRect(const SkIRect& irect) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(SkIntToScalar(irect.fLeft),
|
|
|
|
SkIntToScalar(irect.fTop),
|
|
|
|
SkIntToScalar(irect.fRight),
|
|
|
|
SkIntToScalar(irect.fBottom));
|
2010-02-24 01:49:13 +00:00
|
|
|
return r;
|
|
|
|
}
|
2013-01-24 07:06:13 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to (0, 0, size.width(), size.height()).
|
|
|
|
Does not validate input; size.width() or size.height() may be negative.
|
|
|
|
|
|
|
|
@param size integer values for SkRect width and height
|
|
|
|
@return bounds (0, 0, size.width(), size.height())
|
|
|
|
*/
|
2016-09-12 13:32:07 +00:00
|
|
|
static SkRect Make(const SkISize& size) {
|
|
|
|
return MakeIWH(size.width(), size.height());
|
|
|
|
}
|
2017-07-24 12:58:37 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns constructed SkIRect set to irect, promoting integers to scalar.
|
|
|
|
Does not validate input; fLeft may be greater than fRight, fTop may be greater
|
|
|
|
than fBottom.
|
|
|
|
|
|
|
|
@param irect integer unsorted bounds
|
|
|
|
@return irect members converted to SkScalar
|
|
|
|
*/
|
2013-01-23 15:37:56 +00:00
|
|
|
static SkRect SK_WARN_UNUSED_RESULT Make(const SkIRect& irect) {
|
|
|
|
SkRect r;
|
|
|
|
r.set(SkIntToScalar(irect.fLeft),
|
|
|
|
SkIntToScalar(irect.fTop),
|
|
|
|
SkIntToScalar(irect.fRight),
|
|
|
|
SkIntToScalar(irect.fBottom));
|
|
|
|
return r;
|
|
|
|
}
|
2013-01-24 07:06:13 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if fLeft is equal to or greater than fRight, or if fTop is equal
|
2018-02-27 15:22:04 +00:00
|
|
|
to or greater than fBottom. Call sort() to reverse rectangles with negative
|
|
|
|
width() or height().
|
|
|
|
|
|
|
|
@return true if width() or height() are zero or negative
|
|
|
|
*/
|
2018-02-13 17:48:57 +00:00
|
|
|
bool isEmpty() const {
|
|
|
|
// We write it as the NOT of a non-empty rect, so we will return true if any values
|
|
|
|
// are NaN.
|
|
|
|
return !(fLeft < fRight && fTop < fBottom);
|
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if fLeft is equal to or less than fRight, or if fTop is equal
|
|
|
|
to or less than fBottom. Call sort() to reverse rectangles with negative
|
|
|
|
width() or height().
|
|
|
|
|
|
|
|
@return true if width() or height() are zero or positive
|
|
|
|
*/
|
2017-05-12 15:21:36 +00:00
|
|
|
bool isSorted() const { return fLeft <= fRight && fTop <= fBottom; }
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if all values in the rectangle are finite: SK_ScalarMin or larger,
|
|
|
|
and SK_ScalarMax or smaller.
|
|
|
|
|
|
|
|
@return true if no member is infinite or NaN
|
|
|
|
*/
|
2011-12-06 18:56:37 +00:00
|
|
|
bool isFinite() const {
|
2012-05-16 13:35:36 +00:00
|
|
|
float accum = 0;
|
|
|
|
accum *= fLeft;
|
|
|
|
accum *= fTop;
|
|
|
|
accum *= fRight;
|
|
|
|
accum *= fBottom;
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2012-05-16 13:35:36 +00:00
|
|
|
// accum is either NaN or it is finite (zero).
|
2014-12-15 20:08:47 +00:00
|
|
|
SkASSERT(0 == accum || SkScalarIsNaN(accum));
|
2012-05-16 13:35:36 +00:00
|
|
|
|
2011-12-06 18:56:37 +00:00
|
|
|
// value==value will be true iff value is not NaN
|
2012-05-16 13:35:36 +00:00
|
|
|
// TODO: is it faster to say !accum or accum==accum?
|
2014-12-15 20:08:47 +00:00
|
|
|
return !SkScalarIsNaN(accum);
|
2011-12-06 18:56:37 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns left edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid.
|
|
|
|
Call sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fLeft
|
|
|
|
*/
|
2012-04-19 21:01:24 +00:00
|
|
|
SkScalar x() const { return fLeft; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns top edge of SkRect, if sorted. Call isEmpty() to see if SkRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fTop
|
|
|
|
*/
|
2012-04-19 21:01:24 +00:00
|
|
|
SkScalar y() const { return fTop; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns left edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid.
|
|
|
|
Call sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fLeft
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
SkScalar left() const { return fLeft; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns top edge of SkRect, if sorted. Call isEmpty() to see if SkRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fTop
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
SkScalar top() const { return fTop; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns right edge of SkRect, if sorted. Call isSorted() to see if SkRect is valid.
|
|
|
|
Call sort() to reverse fLeft and fRight if needed.
|
|
|
|
|
|
|
|
@return fRight
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
SkScalar right() const { return fRight; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns bottom edge of SkRect, if sorted. Call isEmpty() to see if SkRect may be invalid,
|
|
|
|
and sort() to reverse fTop and fBottom if needed.
|
|
|
|
|
|
|
|
@return fBottom
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
SkScalar bottom() const { return fBottom; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns span on the x-axis. This does not check if SkRect is sorted, or if
|
|
|
|
result fits in 32-bit float; result may be negative or infinity.
|
|
|
|
|
|
|
|
@return fRight minus fLeft
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar width() const { return fRight - fLeft; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
2018-07-13 12:21:59 +00:00
|
|
|
/** Returns span on the y-axis. This does not check if SkRect is sorted, or if
|
2017-10-30 15:48:35 +00:00
|
|
|
result fits in 32-bit float; result may be negative or infinity.
|
|
|
|
|
|
|
|
@return fBottom minus fTop
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
SkScalar height() const { return fBottom - fTop; }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns average of left edge and right edge. Result does not change if SkRect
|
|
|
|
is sorted. Result may overflow to infinity if SkRect is far from the origin.
|
|
|
|
|
|
|
|
@return midpoint in x
|
|
|
|
*/
|
2018-05-24 14:39:57 +00:00
|
|
|
SkScalar centerX() const {
|
|
|
|
// don't use SkScalarHalf(fLeft + fBottom) as that might overflow before the 0.5
|
|
|
|
return SkScalarHalf(fLeft) + SkScalarHalf(fRight);
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Returns average of top edge and bottom edge. Result does not change if SkRect
|
2018-07-13 12:21:59 +00:00
|
|
|
is sorted.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@return midpoint in y
|
|
|
|
*/
|
2018-05-24 14:39:57 +00:00
|
|
|
SkScalar centerY() const {
|
|
|
|
// don't use SkScalarHalf(fTop + fBottom) as that might overflow before the 0.5
|
|
|
|
return SkScalarHalf(fTop) + SkScalarHalf(fBottom);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if all members in a: fLeft, fTop, fRight, and fBottom; are
|
|
|
|
equal to the corresponding members in b.
|
|
|
|
|
|
|
|
a and b are not equal if either contain NaN. a and b are equal if members
|
|
|
|
contain zeroes width different signs.
|
|
|
|
|
|
|
|
@param a SkRect to compare
|
|
|
|
@param b SkRect to compare
|
|
|
|
@return true if members are equal
|
|
|
|
*/
|
2011-09-01 15:34:14 +00:00
|
|
|
friend bool operator==(const SkRect& a, const SkRect& b) {
|
2017-07-24 12:58:37 +00:00
|
|
|
return SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2010-02-19 21:41:30 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if any in a: fLeft, fTop, fRight, and fBottom; does not
|
|
|
|
equal the corresponding members in b.
|
|
|
|
|
|
|
|
a and b are not equal if either contain NaN. a and b are equal if members
|
|
|
|
contain zeroes width different signs.
|
|
|
|
|
|
|
|
@param a SkRect to compare
|
|
|
|
@param b SkRect to compare
|
|
|
|
@return true if members are not equal
|
|
|
|
*/
|
2011-09-01 15:34:14 +00:00
|
|
|
friend bool operator!=(const SkRect& a, const SkRect& b) {
|
2017-07-24 12:58:37 +00:00
|
|
|
return !SkScalarsEqual((const SkScalar*)&a, (const SkScalar*)&b, 4);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns four points in quad that enclose SkRect ordered as: top-left, top-right,
|
|
|
|
bottom-right, bottom-left.
|
2018-05-30 13:20:29 +00:00
|
|
|
Consider adding param to control whether quad is clockwise or counterclockwise.
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
@param quad storage for corners of SkRect
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void toQuad(SkPoint quad[4]) const;
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
Many other rectangles are empty; if left is equal to or greater than right,
|
|
|
|
or if top is equal to or greater than bottom. Setting all members to zero
|
|
|
|
is a convenience, but does not designate a special empty rectangle.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2016-05-13 16:23:38 +00:00
|
|
|
void setEmpty() { *this = MakeEmpty(); }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to src, promoting src members from integer to scalar.
|
|
|
|
Very large values in src may lose precision.
|
|
|
|
|
|
|
|
@param src integer SkRect
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void set(const SkIRect& src) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft = SkIntToScalar(src.fLeft);
|
|
|
|
fTop = SkIntToScalar(src.fTop);
|
|
|
|
fRight = SkIntToScalar(src.fRight);
|
|
|
|
fBottom = SkIntToScalar(src.fBottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (left, top, right, bottom).
|
|
|
|
left and right are not sorted; left is not necessarily less than right.
|
|
|
|
top and bottom are not sorted; top is not necessarily less than bottom.
|
|
|
|
|
|
|
|
@param left stored in fLeft
|
|
|
|
@param top stored in fTop
|
|
|
|
@param right stored in fRight
|
|
|
|
@param bottom stored in fBottom
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void set(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft = left;
|
|
|
|
fTop = top;
|
|
|
|
fRight = right;
|
|
|
|
fBottom = bottom;
|
|
|
|
}
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Sets SkRect to (left, top, right, bottom).
|
|
|
|
left and right are not sorted; left is not necessarily less than right.
|
|
|
|
top and bottom are not sorted; top is not necessarily less than bottom.
|
|
|
|
|
|
|
|
@param left stored in fLeft
|
|
|
|
@param top stored in fTop
|
|
|
|
@param right stored in fRight
|
|
|
|
@param bottom stored in fBottom
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
void setLTRB(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
|
|
|
|
this->set(left, top, right, bottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (left, top, right, bottom).
|
|
|
|
All parameters are promoted from integer to scalar.
|
|
|
|
left and right are not sorted; left is not necessarily less than right.
|
|
|
|
top and bottom are not sorted; top is not necessarily less than bottom.
|
|
|
|
|
|
|
|
@param left promoted to SkScalar and stored in fLeft
|
|
|
|
@param top promoted to SkScalar and stored in fTop
|
|
|
|
@param right promoted to SkScalar and stored in fRight
|
|
|
|
@param bottom promoted to SkScalar and stored in fBottom
|
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void iset(int left, int top, int right, int bottom) {
|
|
|
|
fLeft = SkIntToScalar(left);
|
|
|
|
fTop = SkIntToScalar(top);
|
|
|
|
fRight = SkIntToScalar(right);
|
|
|
|
fBottom = SkIntToScalar(bottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (0, 0, width, height).
|
|
|
|
width and height may be zero or negative. width and height are promoted from
|
|
|
|
integer to SkScalar, large values may lose precision.
|
|
|
|
|
|
|
|
@param width promoted to SkScalar and stored in fRight
|
|
|
|
@param height promoted to SkScalar and stored in fBottom
|
|
|
|
*/
|
2013-01-16 15:15:24 +00:00
|
|
|
void isetWH(int width, int height) {
|
|
|
|
fLeft = fTop = 0;
|
|
|
|
fRight = SkIntToScalar(width);
|
|
|
|
fBottom = SkIntToScalar(height);
|
|
|
|
}
|
2013-01-17 07:06:06 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets to bounds of SkPoint array with count entries. If count is zero or smaller,
|
|
|
|
or if SkPoint array contains an infinity or NaN, sets SkRect to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
Result is either empty or sorted: fLeft is less than or equal to fRight, and
|
|
|
|
fTop is less than or equal to fBottom.
|
|
|
|
|
|
|
|
@param pts SkPoint array
|
|
|
|
@param count entries in array
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2012-07-26 15:20:36 +00:00
|
|
|
void set(const SkPoint pts[], int count) {
|
|
|
|
// set() had been checking for non-finite values, so keep that behavior
|
|
|
|
// for now. Now that we have setBoundsCheck(), we may decide to make
|
|
|
|
// set() be simpler/faster, and not check for those.
|
|
|
|
(void)this->setBoundsCheck(pts, count);
|
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets to bounds of SkPoint array with count entries. If count is zero or smaller,
|
|
|
|
or if SkPoint array contains an infinity or NaN, sets to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
Result is either empty or sorted: fLeft is less than or equal to fRight, and
|
|
|
|
fTop is less than or equal to fBottom.
|
|
|
|
|
|
|
|
@param pts SkPoint array
|
|
|
|
@param count entries in array
|
|
|
|
*/
|
2011-05-09 17:00:02 +00:00
|
|
|
void setBounds(const SkPoint pts[], int count) {
|
2012-07-26 15:20:36 +00:00
|
|
|
(void)this->setBoundsCheck(pts, count);
|
2011-05-09 17:00:02 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets to bounds of SkPoint array with count entries. Returns false if count is
|
|
|
|
zero or smaller, or if SkPoint array contains an infinity or NaN; in these cases
|
|
|
|
sets SkRect to (0, 0, 0, 0).
|
|
|
|
|
|
|
|
Result is either empty or sorted: fLeft is less than or equal to fRight, and
|
|
|
|
fTop is less than or equal to fBottom.
|
|
|
|
|
|
|
|
@param pts SkPoint array
|
|
|
|
@param count entries in array
|
|
|
|
@return true if all SkPoint values are finite
|
|
|
|
*/
|
2012-07-26 15:20:36 +00:00
|
|
|
bool setBoundsCheck(const SkPoint pts[], int count);
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2018-05-30 13:20:29 +00:00
|
|
|
/** Sets to bounds of SkPoint pts array with count entries. If any SkPoint in pts
|
|
|
|
contains infinity or NaN, all SkRect dimensions are set to NaN.
|
|
|
|
|
|
|
|
@param pts SkPoint array
|
|
|
|
@param count entries in array
|
|
|
|
*/
|
2018-05-17 01:28:55 +00:00
|
|
|
void setBoundsNoCheck(const SkPoint pts[], int count);
|
|
|
|
|
2018-02-27 15:22:04 +00:00
|
|
|
/** Sets bounds to the smallest SkRect enclosing SkPoint p0 and p1. The result is
|
2017-10-30 15:48:35 +00:00
|
|
|
sorted and may be empty. Does not check to see if values are finite.
|
|
|
|
|
|
|
|
@param p0 corner to include
|
|
|
|
@param p1 corner to include
|
|
|
|
*/
|
2012-05-16 13:35:36 +00:00
|
|
|
void set(const SkPoint& p0, const SkPoint& p1) {
|
|
|
|
fLeft = SkMinScalar(p0.fX, p1.fX);
|
|
|
|
fRight = SkMaxScalar(p0.fX, p1.fX);
|
|
|
|
fTop = SkMinScalar(p0.fY, p1.fY);
|
|
|
|
fBottom = SkMaxScalar(p0.fY, p1.fY);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (x, y, x + width, y + height). Does not validate input;
|
|
|
|
width or height may be negative.
|
|
|
|
|
|
|
|
@param x stored in fLeft
|
|
|
|
@param y stored in fTop
|
|
|
|
@param width added to x and stored in fRight
|
|
|
|
@param height added to y and stored in fBottom
|
|
|
|
*/
|
2011-03-03 13:23:35 +00:00
|
|
|
void setXYWH(SkScalar x, SkScalar y, SkScalar width, SkScalar height) {
|
|
|
|
fLeft = x;
|
|
|
|
fTop = y;
|
|
|
|
fRight = x + width;
|
|
|
|
fBottom = y + height;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to (0, 0, width, height). Does not validate input;
|
|
|
|
width or height may be negative.
|
|
|
|
|
|
|
|
@param width stored in fRight
|
|
|
|
@param height stored in fBottom
|
|
|
|
*/
|
2012-10-11 19:39:09 +00:00
|
|
|
void setWH(SkScalar width, SkScalar height) {
|
|
|
|
fLeft = 0;
|
|
|
|
fTop = 0;
|
|
|
|
fRight = width;
|
|
|
|
fBottom = height;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkRect offset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkRect returned is moved to the left.
|
|
|
|
If dx is positive, SkRect returned is moved to the right.
|
|
|
|
If dy is negative, SkRect returned is moved upward.
|
|
|
|
If dy is positive, SkRect returned is moved downward.
|
|
|
|
|
|
|
|
@param dx added to fLeft and fRight
|
|
|
|
@param dy added to fTop and fBottom
|
2018-06-14 17:21:08 +00:00
|
|
|
@return SkRect offset on axes, with original width and height
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2014-06-02 21:38:28 +00:00
|
|
|
SkRect makeOffset(SkScalar dx, SkScalar dy) const {
|
|
|
|
return MakeLTRB(fLeft + dx, fTop + dy, fRight + dx, fBottom + dy);
|
|
|
|
}
|
2017-07-24 12:58:37 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkRect, inset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkRect returned is wider.
|
|
|
|
If dx is positive, SkRect returned is narrower.
|
|
|
|
If dy is negative, SkRect returned is taller.
|
|
|
|
If dy is positive, SkRect returned is shorter.
|
|
|
|
|
|
|
|
@param dx added to fLeft and subtracted from fRight
|
|
|
|
@param dy added to fTop and subtracted from fBottom
|
|
|
|
@return SkRect inset symmetrically left and right, top and bottom
|
|
|
|
*/
|
2014-06-02 21:38:28 +00:00
|
|
|
SkRect makeInset(SkScalar dx, SkScalar dy) const {
|
|
|
|
return MakeLTRB(fLeft + dx, fTop + dy, fRight - dx, fBottom - dy);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkRect, outset by (dx, dy).
|
|
|
|
|
|
|
|
If dx is negative, SkRect returned is narrower.
|
|
|
|
If dx is positive, SkRect returned is wider.
|
|
|
|
If dy is negative, SkRect returned is shorter.
|
|
|
|
If dy is positive, SkRect returned is taller.
|
|
|
|
|
|
|
|
@param dx subtracted to fLeft and added from fRight
|
|
|
|
@param dy subtracted to fTop and added from fBottom
|
|
|
|
@return SkRect outset symmetrically left and right, top and bottom
|
|
|
|
*/
|
2015-03-13 13:08:28 +00:00
|
|
|
SkRect makeOutset(SkScalar dx, SkScalar dy) const {
|
|
|
|
return MakeLTRB(fLeft - dx, fTop - dy, fRight + dx, fBottom + dy);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkRect by adding dx to fLeft, fRight; and by adding dy to fTop, fBottom.
|
|
|
|
|
|
|
|
If dx is negative, moves SkRect to the left.
|
|
|
|
If dx is positive, moves SkRect to the right.
|
|
|
|
If dy is negative, moves SkRect upward.
|
|
|
|
If dy is positive, moves SkRect downward.
|
|
|
|
|
|
|
|
@param dx offset added to fLeft and fRight
|
|
|
|
@param dy offset added to fTop and fBottom
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void offset(SkScalar dx, SkScalar dy) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft += dx;
|
|
|
|
fTop += dy;
|
|
|
|
fRight += dx;
|
|
|
|
fBottom += dy;
|
2012-08-23 18:09:54 +00:00
|
|
|
}
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkRect by adding delta.fX to fLeft, fRight; and by adding delta.fY to
|
|
|
|
fTop, fBottom.
|
|
|
|
|
|
|
|
If delta.fX is negative, moves SkRect to the left.
|
|
|
|
If delta.fX is positive, moves SkRect to the right.
|
|
|
|
If delta.fY is negative, moves SkRect upward.
|
|
|
|
If delta.fY is positive, moves SkRect downward.
|
|
|
|
|
|
|
|
@param delta added to SkRect
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void offset(const SkPoint& delta) {
|
|
|
|
this->offset(delta.fX, delta.fY);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Offsets SkRect so that fLeft equals newX, and fTop equals newY. width and height
|
|
|
|
are unchanged.
|
|
|
|
|
|
|
|
@param newX stored in fLeft, preserving width()
|
|
|
|
@param newY stored in fTop, preserving height()
|
|
|
|
*/
|
2012-11-06 22:02:51 +00:00
|
|
|
void offsetTo(SkScalar newX, SkScalar newY) {
|
|
|
|
fRight += newX - fLeft;
|
|
|
|
fBottom += newY - fTop;
|
|
|
|
fLeft = newX;
|
|
|
|
fTop = newY;
|
|
|
|
}
|
2012-11-08 02:03:56 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Insets SkRect by (dx, dy).
|
|
|
|
|
|
|
|
If dx is positive, makes SkRect narrower.
|
|
|
|
If dx is negative, makes SkRect wider.
|
|
|
|
If dy is positive, makes SkRect shorter.
|
|
|
|
If dy is negative, makes SkRect taller.
|
|
|
|
|
|
|
|
@param dx added to fLeft and subtracted from fRight
|
|
|
|
@param dy added to fTop and subtracted from fBottom
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void inset(SkScalar dx, SkScalar dy) {
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft += dx;
|
|
|
|
fTop += dy;
|
|
|
|
fRight -= dx;
|
|
|
|
fBottom -= dy;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Outsets SkRect by (dx, dy).
|
|
|
|
|
|
|
|
If dx is positive, makes SkRect wider.
|
|
|
|
If dx is negative, makes SkRect narrower.
|
|
|
|
If dy is positive, makes SkRect taller.
|
|
|
|
If dy is negative, makes SkRect shorter.
|
|
|
|
|
|
|
|
@param dx subtracted to fLeft and added from fRight
|
|
|
|
@param dy subtracted to fTop and added from fBottom
|
2011-08-23 14:39:01 +00:00
|
|
|
*/
|
|
|
|
void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); }
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkRect intersects r, and sets SkRect to intersection.
|
|
|
|
Returns false if SkRect does not intersect r, and leaves SkRect unchanged.
|
|
|
|
|
|
|
|
Returns false if either r or SkRect is empty, leaving SkRect unchanged.
|
|
|
|
|
|
|
|
@param r limit of result
|
|
|
|
@return true if r and SkRect have area in common
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-03-07 19:55:37 +00:00
|
|
|
bool intersect(const SkRect& r);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Constructs SkRect to intersect from (left, top, right, bottom). Does not sort
|
|
|
|
construction.
|
|
|
|
|
|
|
|
Returns true if SkRect intersects construction, and sets SkRect to intersection.
|
|
|
|
Returns false if SkRect does not intersect construction, and leaves SkRect unchanged.
|
|
|
|
|
|
|
|
Returns false if either construction or SkRect is empty, leaving SkRect unchanged.
|
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkRect
|
|
|
|
@param top y-axis minimum of constructed SkRect
|
|
|
|
@param right x-axis maximum of constructed SkRect
|
|
|
|
@param bottom y-axis maximum of constructed SkRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if construction and SkRect have area in common
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2017-03-07 19:55:37 +00:00
|
|
|
bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b, and sets SkRect to intersection.
|
|
|
|
Returns false if a does not intersect b, and leaves SkRect unchanged.
|
|
|
|
|
|
|
|
Returns false if either a or b is empty, leaving SkRect unchanged.
|
|
|
|
|
|
|
|
@param a SkRect to intersect
|
|
|
|
@param b SkRect to intersect
|
|
|
|
@return true if a and b have area in common
|
|
|
|
*/
|
2015-01-07 20:16:10 +00:00
|
|
|
bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b);
|
2014-10-09 21:29:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
|
|
|
|
SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
|
|
|
|
SkScalar L = SkMaxScalar(al, bl);
|
|
|
|
SkScalar R = SkMinScalar(ar, br);
|
|
|
|
SkScalar T = SkMaxScalar(at, bt);
|
|
|
|
SkScalar B = SkMinScalar(ab, bb);
|
|
|
|
return L < R && T < B;
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Constructs SkRect to intersect from (left, top, right, bottom). Does not sort
|
|
|
|
construction.
|
|
|
|
|
|
|
|
Returns true if SkRect intersects construction.
|
|
|
|
Returns false if either construction or SkRect is empty, or do not intersect.
|
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkRect
|
|
|
|
@param top y-axis minimum of constructed SkRect
|
|
|
|
@param right x-axis maximum of constructed SkRect
|
|
|
|
@param bottom y-axis maximum of constructed SkRect
|
2017-10-30 15:48:35 +00:00
|
|
|
@return true if construction and SkRect have area in common
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const {
|
2014-10-09 21:29:01 +00:00
|
|
|
return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2011-10-21 14:05:06 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkRect intersects r.
|
|
|
|
Returns false if either r or SkRect is empty, or do not intersect.
|
|
|
|
|
|
|
|
@param r SkRect to intersect
|
|
|
|
@return true if r and SkRect have area in common
|
|
|
|
*/
|
2014-12-16 16:07:43 +00:00
|
|
|
bool intersects(const SkRect& r) const {
|
|
|
|
return Intersects(fLeft, fTop, fRight, fBottom,
|
|
|
|
r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if a intersects b.
|
|
|
|
Returns false if either a or b is empty, or do not intersect.
|
|
|
|
|
|
|
|
@param a SkRect to intersect
|
|
|
|
@param b SkRect to intersect
|
|
|
|
@return true if a and b have area in common
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
static bool Intersects(const SkRect& a, const SkRect& b) {
|
2014-10-09 21:29:01 +00:00
|
|
|
return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
|
|
|
|
b.fLeft, b.fTop, b.fRight, b.fBottom);
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Constructs SkRect to intersect from (left, top, right, bottom). Does not sort
|
|
|
|
construction.
|
|
|
|
|
|
|
|
Sets SkRect to the union of itself and the construction.
|
|
|
|
|
|
|
|
Has no effect if construction is empty. Otherwise, if SkRect is empty, sets
|
|
|
|
SkRect to construction.
|
|
|
|
|
2018-06-14 17:21:08 +00:00
|
|
|
@param left x-axis minimum of constructed SkRect
|
|
|
|
@param top y-axis minimum of constructed SkRect
|
|
|
|
@param right x-axis maximum of constructed SkRect
|
|
|
|
@param bottom y-axis maximum of constructed SkRect
|
2017-10-30 15:48:35 +00:00
|
|
|
*/
|
2008-12-17 15:59:43 +00:00
|
|
|
void join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to the union of itself and r.
|
|
|
|
|
|
|
|
Has no effect if r is empty. Otherwise, if SkRect is empty, sets
|
|
|
|
SkRect to r.
|
|
|
|
|
|
|
|
@param r expansion SkRect
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void join(const SkRect& r) {
|
2008-12-17 15:59:43 +00:00
|
|
|
this->join(r.fLeft, r.fTop, r.fRight, r.fBottom);
|
|
|
|
}
|
2014-10-01 16:24:12 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to the union of itself and r.
|
|
|
|
|
|
|
|
Asserts if r is empty and SK_DEBUG is defined.
|
|
|
|
If SkRect is empty, sets SkRect to r.
|
|
|
|
|
|
|
|
May produce incorrect results if r is empty.
|
|
|
|
|
|
|
|
@param r expansion SkRect
|
|
|
|
*/
|
2014-10-01 16:24:12 +00:00
|
|
|
void joinNonEmptyArg(const SkRect& r) {
|
|
|
|
SkASSERT(!r.isEmpty());
|
|
|
|
// if we are empty, just assign
|
|
|
|
if (fLeft >= fRight || fTop >= fBottom) {
|
|
|
|
*this = r;
|
|
|
|
} else {
|
2015-05-01 15:51:48 +00:00
|
|
|
this->joinPossiblyEmptyRect(r);
|
2014-10-01 16:24:12 +00:00
|
|
|
}
|
|
|
|
}
|
2011-05-09 17:00:02 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect to the union of itself and the construction.
|
|
|
|
|
|
|
|
May produce incorrect results if SkRect or r is empty.
|
|
|
|
|
|
|
|
@param r expansion SkRect
|
|
|
|
*/
|
2015-05-01 15:51:48 +00:00
|
|
|
void joinPossiblyEmptyRect(const SkRect& r) {
|
|
|
|
fLeft = SkMinScalar(fLeft, r.left());
|
|
|
|
fTop = SkMinScalar(fTop, r.top());
|
|
|
|
fRight = SkMaxScalar(fRight, r.right());
|
|
|
|
fBottom = SkMaxScalar(fBottom, r.bottom());
|
|
|
|
}
|
|
|
|
|
2018-02-20 16:44:43 +00:00
|
|
|
/** Returns true if: fLeft <= x < fRight && fTop <= y < fBottom.
|
|
|
|
Returns false if SkRect is empty.
|
|
|
|
|
|
|
|
@param x test SkPoint x-coordinate
|
|
|
|
@param y test SkPoint y-coordinate
|
|
|
|
@return true if (x, y) is inside SkRect
|
|
|
|
*/
|
|
|
|
bool contains(SkScalar x, SkScalar y) const {
|
|
|
|
return x >= fLeft && x < fRight && y >= fTop && y < fBottom;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkRect contains r.
|
|
|
|
Returns false if SkRect is empty or r is empty.
|
|
|
|
|
|
|
|
SkRect contains r when SkRect area completely includes r area.
|
|
|
|
|
|
|
|
@param r SkRect contained
|
|
|
|
@return true if all sides of SkRect are outside r
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
bool contains(const SkRect& r) const {
|
2013-10-30 17:39:43 +00:00
|
|
|
// todo: can we eliminate the this->isEmpty check?
|
2011-05-12 22:31:01 +00:00
|
|
|
return !r.isEmpty() && !this->isEmpty() &&
|
2008-12-17 15:59:43 +00:00
|
|
|
fLeft <= r.fLeft && fTop <= r.fTop &&
|
|
|
|
fRight >= r.fRight && fBottom >= r.fBottom;
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns true if SkRect contains r.
|
|
|
|
Returns false if SkRect is empty or r is empty.
|
|
|
|
|
|
|
|
SkRect contains r when SkRect area completely includes r area.
|
|
|
|
|
|
|
|
@param r SkIRect contained
|
|
|
|
@return true if all sides of SkRect are outside r
|
|
|
|
*/
|
2015-02-25 21:19:48 +00:00
|
|
|
bool contains(const SkIRect& r) const {
|
|
|
|
// todo: can we eliminate the this->isEmpty check?
|
|
|
|
return !r.isEmpty() && !this->isEmpty() &&
|
|
|
|
fLeft <= SkIntToScalar(r.fLeft) && fTop <= SkIntToScalar(r.fTop) &&
|
|
|
|
fRight >= SkIntToScalar(r.fRight) && fBottom >= SkIntToScalar(r.fBottom);
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect by adding 0.5 and discarding the fractional portion of SkRect
|
|
|
|
members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
|
|
|
|
SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).
|
|
|
|
|
|
|
|
@param dst storage for SkIRect
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void round(SkIRect* dst) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(dst);
|
2012-11-06 22:02:51 +00:00
|
|
|
dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
|
|
|
|
SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect by discarding the fractional portion of fLeft and fTop; and
|
2018-02-27 15:22:04 +00:00
|
|
|
rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
|
2017-10-30 15:48:35 +00:00
|
|
|
SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
|
|
|
|
|
|
|
|
@param dst storage for SkIRect
|
|
|
|
*/
|
2010-02-19 21:41:30 +00:00
|
|
|
void roundOut(SkIRect* dst) const {
|
2008-12-17 15:59:43 +00:00
|
|
|
SkASSERT(dst);
|
2012-11-06 22:02:51 +00:00
|
|
|
dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
|
|
|
|
SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
|
2008-12-17 15:59:43 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect by discarding the fractional portion of fLeft and fTop; and
|
2018-02-27 15:22:04 +00:00
|
|
|
rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
|
2017-10-30 15:48:35 +00:00
|
|
|
SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
|
|
|
|
|
|
|
|
@param dst storage for SkRect
|
|
|
|
*/
|
2014-11-19 02:06:45 +00:00
|
|
|
void roundOut(SkRect* dst) const {
|
|
|
|
dst->set(SkScalarFloorToScalar(fLeft),
|
|
|
|
SkScalarFloorToScalar(fTop),
|
|
|
|
SkScalarCeilToScalar(fRight),
|
|
|
|
SkScalarCeilToScalar(fBottom));
|
2011-08-01 20:53:19 +00:00
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkRect by rounding up fLeft and fTop; and
|
2018-02-27 15:22:04 +00:00
|
|
|
discarding the fractional portion of fRight and fBottom, using
|
2017-10-30 15:48:35 +00:00
|
|
|
(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
|
|
|
|
SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)).
|
|
|
|
|
|
|
|
@param dst storage for SkIRect
|
|
|
|
*/
|
2012-11-06 22:02:51 +00:00
|
|
|
void roundIn(SkIRect* dst) const {
|
|
|
|
SkASSERT(dst);
|
|
|
|
dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
|
|
|
|
SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
|
|
|
|
}
|
2012-11-08 02:03:56 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkIRect by adding 0.5 and discarding the fractional portion of SkRect
|
|
|
|
members, using (SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
|
|
|
|
SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)).
|
|
|
|
|
|
|
|
@return rounded SkIRect
|
|
|
|
*/
|
2013-11-07 16:06:53 +00:00
|
|
|
SkIRect round() const {
|
|
|
|
SkIRect ir;
|
|
|
|
this->round(&ir);
|
|
|
|
return ir;
|
|
|
|
}
|
2017-07-24 12:58:37 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Sets SkIRect by discarding the fractional portion of fLeft and fTop; and
|
2018-02-27 15:22:04 +00:00
|
|
|
rounding up fRight and fBottom, using (SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
|
2017-10-30 15:48:35 +00:00
|
|
|
SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)).
|
|
|
|
|
|
|
|
@return rounded SkIRect
|
|
|
|
*/
|
2014-11-19 13:03:18 +00:00
|
|
|
SkIRect roundOut() const {
|
|
|
|
SkIRect ir;
|
|
|
|
this->roundOut(&ir);
|
|
|
|
return ir;
|
|
|
|
}
|
2017-07-24 12:58:37 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Swaps fLeft and fRight if fLeft is greater than fRight; and swaps
|
|
|
|
fTop and fBottom if fTop is greater than fBottom. Result may be empty;
|
|
|
|
and width() and height() will be zero or positive.
|
|
|
|
*/
|
2014-10-10 12:50:15 +00:00
|
|
|
void sort() {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
2014-11-03 22:34:30 +00:00
|
|
|
if (fLeft > fRight) {
|
2018-06-18 19:11:00 +00:00
|
|
|
swap(fLeft, fRight);
|
2014-11-03 22:34:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fTop > fBottom) {
|
2018-06-18 19:11:00 +00:00
|
|
|
swap(fTop, fBottom);
|
2014-11-03 22:34:30 +00:00
|
|
|
}
|
2014-10-10 12:50:15 +00:00
|
|
|
}
|
2013-03-09 07:01:15 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns SkRect with fLeft and fRight swapped if fLeft is greater than fRight; and
|
|
|
|
with fTop and fBottom swapped if fTop is greater than fBottom. Result may be empty;
|
|
|
|
and width() and height() will be zero or positive.
|
|
|
|
|
|
|
|
@return sorted SkRect
|
|
|
|
*/
|
2017-05-12 15:21:36 +00:00
|
|
|
SkRect makeSorted() const {
|
|
|
|
return MakeLTRB(SkMinScalar(fLeft, fRight), SkMinScalar(fTop, fBottom),
|
|
|
|
SkMaxScalar(fLeft, fRight), SkMaxScalar(fTop, fBottom));
|
|
|
|
}
|
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Returns pointer to first scalar in SkRect, to treat it as an array with four
|
|
|
|
entries.
|
|
|
|
|
|
|
|
@return pointer to fLeft
|
|
|
|
*/
|
2013-03-08 16:07:54 +00:00
|
|
|
const SkScalar* asScalars() const { return &fLeft; }
|
2014-06-09 14:59:06 +00:00
|
|
|
|
2017-10-30 15:48:35 +00:00
|
|
|
/** Writes text representation of SkRect to standard output. Set asHex to true to
|
|
|
|
generate exact binary representations of floating point numbers.
|
|
|
|
|
|
|
|
@param asHex true if SkScalar values are written as hexadecimal
|
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dump(bool asHex) const;
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Writes text representation of SkRect to standard output. The representation may be
|
|
|
|
directly compiled as C++ code. Floating point values are written
|
|
|
|
with limited precision; it may not be possible to reconstruct original SkRect
|
|
|
|
from output.
|
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dump() const { this->dump(false); }
|
2017-10-30 15:48:35 +00:00
|
|
|
|
|
|
|
/** Writes text representation of SkRect to standard output. The representation may be
|
|
|
|
directly compiled as C++ code. Floating point values are written
|
|
|
|
in hexadecimal to preserve their exact bit pattern. The output reconstructs the
|
|
|
|
original SkRect.
|
|
|
|
|
|
|
|
Use instead of dump() when submitting
|
|
|
|
*/
|
2014-12-15 15:59:53 +00:00
|
|
|
void dumpHex() const { this->dump(true); }
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
|
2015-02-23 22:44:57 +00:00
|
|
|
inline bool SkIRect::contains(const SkRect& r) const {
|
|
|
|
return !r.isEmpty() && !this->isEmpty() && // check for empties
|
|
|
|
(SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop &&
|
|
|
|
(SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom;
|
|
|
|
}
|
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#endif
|