Add SkRect::contains(SkScalar x, SkScalar y)

Similar to its SkIRect counterpart.

Change-Id: I6872694d8602ed4181a1a15b4cd1c2c32aeab3f9
Reviewed-on: https://skia-review.googlesource.com/108506
Reviewed-by: Cary Clark <caryclark@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2018-02-20 11:44:43 -05:00 committed by Skia Commit-Bot
parent 535ba8d2b8
commit eb420457fd
3 changed files with 45 additions and 2 deletions

View File

@ -1494,6 +1494,39 @@ describes an area: fLeft is less than fRight, and fTop is less than fBottom.
# ------------------------------------------------------------------------------
#Method bool contains(SkScalar x, SkScalar y) const
#In Intersection
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 ##
#Example
SkRect rect = { 30, 50, 40, 60 };
SkPoint tests[] = { { 30, 50 }, { 39, 49 }, { 29, 59 } };
for (auto contained : tests) {
SkDebugf("rect: (%g, %g, %g, %g) %s (%g, %g)\n",
rect.left(), rect.top(), rect.right(), rect.bottom(),
rect.contains(contained.x(), contained.y()) ? "contains" : "does not contain",
contained.x(), contained.y());
}
#StdOut
rect: (30, 50, 40, 60) contains (30, 50)
rect: (30, 50, 40, 60) does not contain (39, 49)
rect: (30, 50, 40, 60) does not contain (29, 59)
##
##
#SeeAlso SkIRect::contains
##
# ------------------------------------------------------------------------------
#Method bool contains(const SkRect& r) const
#In Intersection

View File

@ -1423,6 +1423,17 @@ public:
fBottom = SkMaxScalar(fBottom, r.bottom());
}
/** 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;
}
/** Returns true if SkRect contains r.
Returns false if SkRect is empty or r is empty.

View File

@ -153,8 +153,7 @@ public:
bool onMouse(SkScalar x, SkScalar y, sk_app::Window::InputState state, uint32_t modifiers) {
SkASSERT(fTarget);
// TODO: no SkRect::contains(SkPoint) ?!
if (x < fRect.fLeft || x > fRect.fRight || y < fRect.fTop || y > fRect.fBottom) {
if (!fRect.contains(x, y)) {
this->startUnfocus();
return true;
}