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