caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | #ifndef SkPathOpBounds_DEFINED |
| 8 | #define SkPathOpBounds_DEFINED |
| 9 | |
| 10 | #include "SkPathOpsRect.h" |
| 11 | #include "SkRect.h" |
| 12 | |
| 13 | // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. |
| 14 | struct SkPathOpsBounds : public SkRect { |
| 15 | static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 16 | return AlmostLessOrEqualUlps(a.fLeft, b.fRight) |
| 17 | && AlmostLessOrEqualUlps(b.fLeft, a.fRight) |
| 18 | && AlmostLessOrEqualUlps(a.fTop, b.fBottom) |
| 19 | && AlmostLessOrEqualUlps(b.fTop, a.fBottom); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 20 | } |
| 21 | |
caryclark@google.com | 3b97af5 | 2013-04-23 11:56:44 +0000 | [diff] [blame] | 22 | // Note that add(), unlike SkRect::join() or SkRect::growToInclude() |
| 23 | // does not treat the bounds of horizontal and vertical lines as |
| 24 | // empty rectangles. |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 25 | void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { |
| 26 | if (left < fLeft) fLeft = left; |
| 27 | if (top < fTop) fTop = top; |
| 28 | if (right > fRight) fRight = right; |
| 29 | if (bottom > fBottom) fBottom = bottom; |
| 30 | } |
| 31 | |
| 32 | void add(const SkPathOpsBounds& toAdd) { |
| 33 | add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); |
| 34 | } |
| 35 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 36 | void add(const SkPoint& pt) { |
| 37 | if (pt.fX < fLeft) fLeft = pt.fX; |
| 38 | if (pt.fY < fTop) fTop = pt.fY; |
| 39 | if (pt.fX > fRight) fRight = pt.fX; |
| 40 | if (pt.fY > fBottom) fBottom = pt.fY; |
| 41 | } |
| 42 | |
caryclark | aec2510 | 2015-04-29 08:28:30 -0700 | [diff] [blame] | 43 | void add(const SkDPoint& pt) { |
| 44 | if (pt.fX < fLeft) fLeft = SkDoubleToScalar(pt.fX); |
| 45 | if (pt.fY < fTop) fTop = SkDoubleToScalar(pt.fY); |
| 46 | if (pt.fX > fRight) fRight = SkDoubleToScalar(pt.fX); |
| 47 | if (pt.fY > fBottom) fBottom = SkDoubleToScalar(pt.fY); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 48 | } |
| 49 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 50 | bool almostContains(const SkPoint& pt) const { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 51 | return AlmostLessOrEqualUlps(fLeft, pt.fX) |
| 52 | && AlmostLessOrEqualUlps(pt.fX, fRight) |
| 53 | && AlmostLessOrEqualUlps(fTop, pt.fY) |
| 54 | && AlmostLessOrEqualUlps(pt.fY, fBottom); |
| 55 | } |
| 56 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 57 | bool contains(const SkPoint& pt) const { |
| 58 | return fLeft <= pt.fX && fTop <= pt.fY && |
| 59 | fRight >= pt.fX && fBottom >= pt.fY; |
| 60 | } |
| 61 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 62 | typedef SkRect INHERITED; |
| 63 | }; |
| 64 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 65 | #endif |