Line data Source code
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 0 : void add(const SkDPoint& pt) {
16 0 : fLeft = SkTMin(fLeft, pt.fX);
17 0 : fTop = SkTMin(fTop, pt.fY);
18 0 : fRight = SkTMax(fRight, pt.fX);
19 0 : fBottom = SkTMax(fBottom, pt.fY);
20 0 : }
21 :
22 : bool contains(const SkDPoint& pt) const {
23 : return approximately_between(fLeft, pt.fX, fRight)
24 : && approximately_between(fTop, pt.fY, fBottom);
25 : }
26 :
27 : void debugInit();
28 :
29 0 : bool intersects(const SkDRect& r) const {
30 0 : SkASSERT(fLeft <= fRight);
31 0 : SkASSERT(fTop <= fBottom);
32 0 : SkASSERT(r.fLeft <= r.fRight);
33 0 : SkASSERT(r.fTop <= r.fBottom);
34 0 : return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
35 : }
36 :
37 0 : void set(const SkDPoint& pt) {
38 0 : fLeft = fRight = pt.fX;
39 0 : fTop = fBottom = pt.fY;
40 0 : }
41 :
42 0 : double width() const {
43 0 : return fRight - fLeft;
44 : }
45 :
46 0 : double height() const {
47 0 : return fBottom - fTop;
48 : }
49 :
50 0 : void setBounds(const SkDConic& curve) {
51 0 : setBounds(curve, curve, 0, 1);
52 0 : }
53 :
54 : void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
55 :
56 0 : void setBounds(const SkDCubic& curve) {
57 0 : setBounds(curve, curve, 0, 1);
58 0 : }
59 :
60 : void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
61 :
62 0 : void setBounds(const SkDQuad& curve) {
63 0 : setBounds(curve, curve, 0, 1);
64 0 : }
65 :
66 : void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
67 :
68 0 : bool valid() const {
69 0 : return fLeft <= fRight && fTop <= fBottom;
70 : }
71 : };
72 :
73 : #endif
|