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 addSkDRect15 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 containsSkDRect22 bool contains(const SkDPoint& pt) const { 23 return approximately_between(fLeft, pt.fX, fRight) 24 && approximately_between(fTop, pt.fY, fBottom); 25 } 26 intersectsSkDRect27 bool intersects(const SkDRect& r) const { 28 if (fLeft > fRight) { 29 SkDebugf("!"); 30 } 31 SkASSERT(fLeft <= fRight); 32 SkASSERT(fTop <= fBottom); 33 SkASSERT(r.fLeft <= r.fRight); 34 SkASSERT(r.fTop <= r.fBottom); 35 return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom; 36 } 37 setSkDRect38 void set(const SkDPoint& pt) { 39 fLeft = fRight = pt.fX; 40 fTop = fBottom = pt.fY; 41 } 42 widthSkDRect43 double width() const { 44 return fRight - fLeft; 45 } 46 heightSkDRect47 double height() const { 48 return fBottom - fTop; 49 } 50 setBoundsSkDRect51 void setBounds(const SkDConic& curve) { 52 setBounds(curve, curve, 0, 1); 53 } 54 55 void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd); 56 setBoundsSkDRect57 void setBounds(const SkDCubic& curve) { 58 setBounds(curve, curve, 0, 1); 59 } 60 61 void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd); 62 setBoundsSkDRect63 void setBounds(const SkDQuad& curve) { 64 setBounds(curve, curve, 0, 1); 65 } 66 67 void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd); 68 }; 69 70 #endif 71