gfx/skia/trunk/src/pathops/SkPathOpsRect.h

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:4b9a0ae15387
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 SkPathOpsRect_DEFINED
8 #define SkPathOpsRect_DEFINED
9
10 #include "SkPathOpsPoint.h"
11
12 struct SkDRect {
13 double fLeft, fTop, fRight, fBottom;
14
15 void add(const SkDPoint& pt) {
16 if (fLeft > pt.fX) {
17 fLeft = pt.fX;
18 }
19 if (fTop > pt.fY) {
20 fTop = pt.fY;
21 }
22 if (fRight < pt.fX) {
23 fRight = pt.fX;
24 }
25 if (fBottom < pt.fY) {
26 fBottom = pt.fY;
27 }
28 }
29
30 bool contains(const SkDPoint& pt) const {
31 return approximately_between(fLeft, pt.fX, fRight)
32 && approximately_between(fTop, pt.fY, fBottom);
33 }
34
35 bool intersects(SkDRect* r) const {
36 SkASSERT(fLeft <= fRight);
37 SkASSERT(fTop <= fBottom);
38 SkASSERT(r->fLeft <= r->fRight);
39 SkASSERT(r->fTop <= r->fBottom);
40 return r->fLeft <= fRight && fLeft <= r->fRight && r->fTop <= fBottom && fTop <= r->fBottom;
41 }
42
43 void set(const SkDPoint& pt) {
44 fLeft = fRight = pt.fX;
45 fTop = fBottom = pt.fY;
46 }
47
48 double width() const {
49 return fRight - fLeft;
50 }
51
52 double height() const {
53 return fBottom - fTop;
54 }
55
56 void setBounds(const SkDLine&);
57 void setBounds(const SkDCubic&);
58 void setBounds(const SkDQuad&);
59 void setRawBounds(const SkDCubic&);
60 void setRawBounds(const SkDQuad&);
61 };
62
63 #endif

mercurial