• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "include/core/SkTypes.h"
11 #include "src/pathops/SkPathOpsPoint.h"
12 #include "src/pathops/SkPathOpsTypes.h"
13 
14 #include <algorithm>
15 
16 class SkTCurve;
17 struct SkDConic;
18 struct SkDCubic;
19 struct SkDQuad;
20 
21 struct SkDRect {
22     double fLeft, fTop, fRight, fBottom;
23 
addSkDRect24     void add(const SkDPoint& pt) {
25         fLeft = std::min(fLeft, pt.fX);
26         fTop = std::min(fTop, pt.fY);
27         fRight = std::max(fRight, pt.fX);
28         fBottom = std::max(fBottom, pt.fY);
29     }
30 
containsSkDRect31     bool contains(const SkDPoint& pt) const {
32         return approximately_between(fLeft, pt.fX, fRight)
33                 && approximately_between(fTop, pt.fY, fBottom);
34     }
35 
36     void debugInit();
37 
intersectsSkDRect38     bool intersects(const SkDRect& r) const {
39         SkASSERT(fLeft <= fRight);
40         SkASSERT(fTop <= fBottom);
41         SkASSERT(r.fLeft <= r.fRight);
42         SkASSERT(r.fTop <= r.fBottom);
43         return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
44     }
45 
setSkDRect46     void set(const SkDPoint& pt) {
47         fLeft = fRight = pt.fX;
48         fTop = fBottom = pt.fY;
49     }
50 
widthSkDRect51     double width() const {
52         return fRight - fLeft;
53     }
54 
heightSkDRect55     double height() const {
56         return fBottom - fTop;
57     }
58 
setBoundsSkDRect59     void setBounds(const SkDConic& curve) {
60         setBounds(curve, curve, 0, 1);
61     }
62 
63     void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
64 
setBoundsSkDRect65     void setBounds(const SkDCubic& curve) {
66         setBounds(curve, curve, 0, 1);
67     }
68 
69     void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
70 
setBoundsSkDRect71     void setBounds(const SkDQuad& curve) {
72         setBounds(curve, curve, 0, 1);
73     }
74 
75     void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
76 
77     void setBounds(const SkTCurve& curve);
78 
validSkDRect79     bool valid() const {
80         return fLeft <= fRight && fTop <= fBottom;
81     }
82 };
83 
84 #endif
85