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 12 class SkTCurve; 13 14 struct SkDRect { 15 double fLeft, fTop, fRight, fBottom; 16 addSkDRect17 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 containsSkDRect24 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 intersectsSkDRect31 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 setSkDRect39 void set(const SkDPoint& pt) { 40 fLeft = fRight = pt.fX; 41 fTop = fBottom = pt.fY; 42 } 43 widthSkDRect44 double width() const { 45 return fRight - fLeft; 46 } 47 heightSkDRect48 double height() const { 49 return fBottom - fTop; 50 } 51 setBoundsSkDRect52 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 setBoundsSkDRect58 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 setBoundsSkDRect64 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 validSkDRect72 bool valid() const { 73 return fLeft <= fRight && fTop <= fBottom; 74 } 75 }; 76 77 #endif 78