/src/skia/src/pathops/SkPathOpsBounds.h
Line | Count | Source (jump to first uncovered line) |
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 "include/core/SkRect.h" |
11 | | #include "src/pathops/SkPathOpsRect.h" |
12 | | |
13 | | // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty. |
14 | | struct SkPathOpsBounds : public SkRect { |
15 | 2.26G | static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) { |
16 | 2.26G | return AlmostLessOrEqualUlps(a.fLeft, b.fRight) |
17 | 1.26G | && AlmostLessOrEqualUlps(b.fLeft, a.fRight) |
18 | 203M | && AlmostLessOrEqualUlps(a.fTop, b.fBottom) |
19 | 144M | && AlmostLessOrEqualUlps(b.fTop, a.fBottom); |
20 | 2.26G | } |
21 | | |
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. |
25 | 14.6M | void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) { |
26 | 14.6M | if (left < fLeft) fLeft = left; |
27 | 14.6M | if (top < fTop) fTop = top; |
28 | 14.6M | if (right > fRight) fRight = right; |
29 | 14.6M | if (bottom > fBottom) fBottom = bottom; |
30 | 14.6M | } |
31 | | |
32 | 14.6M | void add(const SkPathOpsBounds& toAdd) { |
33 | 14.6M | add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom); |
34 | 14.6M | } |
35 | | |
36 | 0 | void add(const SkPoint& pt) { |
37 | 0 | if (pt.fX < fLeft) fLeft = pt.fX; |
38 | 0 | if (pt.fY < fTop) fTop = pt.fY; |
39 | 0 | if (pt.fX > fRight) fRight = pt.fX; |
40 | 0 | if (pt.fY > fBottom) fBottom = pt.fY; |
41 | 0 | } |
42 | | |
43 | 0 | void add(const SkDPoint& pt) { |
44 | 0 | if (pt.fX < fLeft) fLeft = SkDoubleToScalar(pt.fX); |
45 | 0 | if (pt.fY < fTop) fTop = SkDoubleToScalar(pt.fY); |
46 | 0 | if (pt.fX > fRight) fRight = SkDoubleToScalar(pt.fX); |
47 | 0 | if (pt.fY > fBottom) fBottom = SkDoubleToScalar(pt.fY); |
48 | 0 | } |
49 | | |
50 | 0 | bool almostContains(const SkPoint& pt) const { |
51 | 0 | return AlmostLessOrEqualUlps(fLeft, pt.fX) |
52 | 0 | && AlmostLessOrEqualUlps(pt.fX, fRight) |
53 | 0 | && AlmostLessOrEqualUlps(fTop, pt.fY) |
54 | 0 | && AlmostLessOrEqualUlps(pt.fY, fBottom); |
55 | 0 | } |
56 | | |
57 | 0 | bool contains(const SkPoint& pt) const { |
58 | 0 | return fLeft <= pt.fX && fTop <= pt.fY && |
59 | 0 | fRight >= pt.fX && fBottom >= pt.fY; |
60 | 0 | } |
61 | | |
62 | | using INHERITED = SkRect; |
63 | | }; |
64 | | |
65 | | #endif |