SkPathOpsRect.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "src/pathops/SkPathOpsPoint.h"
  10. class SkTCurve;
  11. struct SkDRect {
  12. double fLeft, fTop, fRight, fBottom;
  13. void add(const SkDPoint& pt) {
  14. fLeft = SkTMin(fLeft, pt.fX);
  15. fTop = SkTMin(fTop, pt.fY);
  16. fRight = SkTMax(fRight, pt.fX);
  17. fBottom = SkTMax(fBottom, pt.fY);
  18. }
  19. bool contains(const SkDPoint& pt) const {
  20. return approximately_between(fLeft, pt.fX, fRight)
  21. && approximately_between(fTop, pt.fY, fBottom);
  22. }
  23. void debugInit();
  24. bool intersects(const SkDRect& r) const {
  25. SkASSERT(fLeft <= fRight);
  26. SkASSERT(fTop <= fBottom);
  27. SkASSERT(r.fLeft <= r.fRight);
  28. SkASSERT(r.fTop <= r.fBottom);
  29. return r.fLeft <= fRight && fLeft <= r.fRight && r.fTop <= fBottom && fTop <= r.fBottom;
  30. }
  31. void set(const SkDPoint& pt) {
  32. fLeft = fRight = pt.fX;
  33. fTop = fBottom = pt.fY;
  34. }
  35. double width() const {
  36. return fRight - fLeft;
  37. }
  38. double height() const {
  39. return fBottom - fTop;
  40. }
  41. void setBounds(const SkDConic& curve) {
  42. setBounds(curve, curve, 0, 1);
  43. }
  44. void setBounds(const SkDConic& curve, const SkDConic& sub, double tStart, double tEnd);
  45. void setBounds(const SkDCubic& curve) {
  46. setBounds(curve, curve, 0, 1);
  47. }
  48. void setBounds(const SkDCubic& curve, const SkDCubic& sub, double tStart, double tEnd);
  49. void setBounds(const SkDQuad& curve) {
  50. setBounds(curve, curve, 0, 1);
  51. }
  52. void setBounds(const SkDQuad& curve, const SkDQuad& sub, double tStart, double tEnd);
  53. void setBounds(const SkTCurve& curve);
  54. bool valid() const {
  55. return fLeft <= fRight && fTop <= fBottom;
  56. }
  57. };
  58. #endif