SkPathOpsBounds.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 SkPathOpBounds_DEFINED
  8. #define SkPathOpBounds_DEFINED
  9. #include "include/core/SkRect.h"
  10. #include "src/pathops/SkPathOpsRect.h"
  11. // SkPathOpsBounds, unlike SkRect, does not consider a line to be empty.
  12. struct SkPathOpsBounds : public SkRect {
  13. static bool Intersects(const SkPathOpsBounds& a, const SkPathOpsBounds& b) {
  14. return AlmostLessOrEqualUlps(a.fLeft, b.fRight)
  15. && AlmostLessOrEqualUlps(b.fLeft, a.fRight)
  16. && AlmostLessOrEqualUlps(a.fTop, b.fBottom)
  17. && AlmostLessOrEqualUlps(b.fTop, a.fBottom);
  18. }
  19. // Note that add(), unlike SkRect::join() or SkRect::growToInclude()
  20. // does not treat the bounds of horizontal and vertical lines as
  21. // empty rectangles.
  22. void add(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
  23. if (left < fLeft) fLeft = left;
  24. if (top < fTop) fTop = top;
  25. if (right > fRight) fRight = right;
  26. if (bottom > fBottom) fBottom = bottom;
  27. }
  28. void add(const SkPathOpsBounds& toAdd) {
  29. add(toAdd.fLeft, toAdd.fTop, toAdd.fRight, toAdd.fBottom);
  30. }
  31. void add(const SkPoint& pt) {
  32. if (pt.fX < fLeft) fLeft = pt.fX;
  33. if (pt.fY < fTop) fTop = pt.fY;
  34. if (pt.fX > fRight) fRight = pt.fX;
  35. if (pt.fY > fBottom) fBottom = pt.fY;
  36. }
  37. void add(const SkDPoint& pt) {
  38. if (pt.fX < fLeft) fLeft = SkDoubleToScalar(pt.fX);
  39. if (pt.fY < fTop) fTop = SkDoubleToScalar(pt.fY);
  40. if (pt.fX > fRight) fRight = SkDoubleToScalar(pt.fX);
  41. if (pt.fY > fBottom) fBottom = SkDoubleToScalar(pt.fY);
  42. }
  43. bool almostContains(const SkPoint& pt) const {
  44. return AlmostLessOrEqualUlps(fLeft, pt.fX)
  45. && AlmostLessOrEqualUlps(pt.fX, fRight)
  46. && AlmostLessOrEqualUlps(fTop, pt.fY)
  47. && AlmostLessOrEqualUlps(pt.fY, fBottom);
  48. }
  49. bool contains(const SkPoint& pt) const {
  50. return fLeft <= pt.fX && fTop <= pt.fY &&
  51. fRight >= pt.fX && fBottom >= pt.fY;
  52. }
  53. typedef SkRect INHERITED;
  54. };
  55. #endif