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
12struct SkDRect {
13    double fLeft, fTop, fRight, fBottom;
14
15    void add(const SkDPoint& pt) {
16        fLeft = SkTMin(fLeft, pt.fX);
17        fTop = SkTMin(fTop, pt.fY);
18        fRight = SkTMax(fRight, pt.fX);
19        fBottom = SkTMax(fBottom, pt.fY);
20    }
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    bool intersects(const SkDRect& r) const {
30        SkASSERT(fLeft <= fRight);
31        SkASSERT(fTop <= fBottom);
32        SkASSERT(r.fLeft <= r.fRight);
33        SkASSERT(r.fTop <= r.fBottom);
34        return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
35    }
36
37    void set(const SkDPoint& pt) {
38        fLeft = fRight = pt.fX;
39        fTop = fBottom = pt.fY;
40    }
41
42    double width() const {
43        return fRight - fLeft;
44    }
45
46    double height() const {
47        return fBottom - fTop;
48    }
49
50    void setBounds(const SkDConic& curve) {
51        setBounds(curve, curve, 0, 1);
52    }
53
54    void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
55
56    void setBounds(const SkDCubic& curve) {
57        setBounds(curve, curve, 0, 1);
58    }
59
60    void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
61
62    void setBounds(const SkDQuad& curve) {
63        setBounds(curve, curve, 0, 1);
64    }
65
66    void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
67};
68
69#endif
70