Make simple coord/size getters on Sk[I]Rect constexpr

Bug: skia:12720
Change-Id: I349a3dd8ae58eefcadbace7847798fbe57227a41
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/482008
Auto-Submit: Brian Salomon <bsalomon@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
Brian Salomon 2021-12-09 14:59:57 -05:00 committed by SkCQ
parent a964a72174
commit eb6851ab51

View File

@ -108,66 +108,66 @@ struct SK_API SkIRect {
@return fLeft
*/
int32_t left() const { return fLeft; }
constexpr int32_t left() const { return fLeft; }
/** 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
*/
int32_t top() const { return fTop; }
constexpr int32_t top() const { return fTop; }
/** Returns right edge of SkIRect, if sorted.
Call sort() to reverse fLeft and fRight if needed.
@return fRight
*/
int32_t right() const { return fRight; }
constexpr int32_t right() const { return fRight; }
/** 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
*/
int32_t bottom() const { return fBottom; }
constexpr int32_t bottom() const { return fBottom; }
/** 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
*/
int32_t x() const { return fLeft; }
constexpr int32_t x() const { return fLeft; }
/** 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
*/
int32_t y() const { return fTop; }
constexpr int32_t y() const { return fTop; }
// Experimental
SkIPoint topLeft() const { return {fLeft, fTop}; }
constexpr SkIPoint topLeft() const { return {fLeft, fTop}; }
/** 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
*/
int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
constexpr int32_t width() const { return Sk32_can_overflow_sub(fRight, fLeft); }
/** 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
*/
int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
constexpr int32_t height() const { return Sk32_can_overflow_sub(fBottom, fTop); }
/** 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)
*/
SkISize size() const { return SkISize::Make(this->width(), this->height()); }
constexpr SkISize size() const { return SkISize::Make(this->width(), this->height()); }
/** 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
@ -175,7 +175,7 @@ struct SK_API SkIRect {
@return fRight minus fLeft cast to int64_t
*/
int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
constexpr int64_t width64() const { return (int64_t)fRight - (int64_t)fLeft; }
/** 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
@ -183,7 +183,7 @@ struct SK_API SkIRect {
@return fBottom minus fTop cast to int64_t
*/
int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
constexpr int64_t height64() const { return (int64_t)fBottom - (int64_t)fTop; }
/** 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
@ -727,56 +727,56 @@ struct SK_API SkRect {
@return fLeft
*/
SkScalar x() const { return fLeft; }
constexpr SkScalar x() const { return fLeft; }
/** 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
*/
SkScalar y() const { return fTop; }
constexpr SkScalar y() const { return fTop; }
/** 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
*/
SkScalar left() const { return fLeft; }
constexpr SkScalar left() const { return fLeft; }
/** 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
*/
SkScalar top() const { return fTop; }
constexpr SkScalar top() const { return fTop; }
/** 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
*/
SkScalar right() const { return fRight; }
constexpr SkScalar right() const { return fRight; }
/** 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
*/
SkScalar bottom() const { return fBottom; }
constexpr SkScalar bottom() const { return fBottom; }
/** 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
*/
SkScalar width() const { return fRight - fLeft; }
constexpr SkScalar width() const { return fRight - fLeft; }
/** Returns span on the y-axis. This does not check if SkRect is sorted, or if
result fits in 32-bit float; result may be negative or infinity.
@return fBottom minus fTop
*/
SkScalar height() const { return fBottom - fTop; }
constexpr SkScalar height() const { return fBottom - fTop; }
/** 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.