SkIntersectionHelper.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 SkIntersectionHelper_DEFINED
  8. #define SkIntersectionHelper_DEFINED
  9. #include "include/core/SkPath.h"
  10. #include "src/pathops/SkOpContour.h"
  11. #include "src/pathops/SkOpSegment.h"
  12. #ifdef SK_DEBUG
  13. #include "src/pathops/SkPathOpsPoint.h"
  14. #endif
  15. class SkIntersectionHelper {
  16. public:
  17. enum SegmentType {
  18. kHorizontalLine_Segment = -1,
  19. kVerticalLine_Segment = 0,
  20. kLine_Segment = SkPath::kLine_Verb,
  21. kQuad_Segment = SkPath::kQuad_Verb,
  22. kConic_Segment = SkPath::kConic_Verb,
  23. kCubic_Segment = SkPath::kCubic_Verb,
  24. };
  25. bool advance() {
  26. fSegment = fSegment->next();
  27. return fSegment != nullptr;
  28. }
  29. SkScalar bottom() const {
  30. return bounds().fBottom;
  31. }
  32. const SkPathOpsBounds& bounds() const {
  33. return fSegment->bounds();
  34. }
  35. SkOpContour* contour() const {
  36. return fSegment->contour();
  37. }
  38. void init(SkOpContour* contour) {
  39. fSegment = contour->first();
  40. }
  41. SkScalar left() const {
  42. return bounds().fLeft;
  43. }
  44. const SkPoint* pts() const {
  45. return fSegment->pts();
  46. }
  47. SkScalar right() const {
  48. return bounds().fRight;
  49. }
  50. SkOpSegment* segment() const {
  51. return fSegment;
  52. }
  53. SegmentType segmentType() const {
  54. SegmentType type = (SegmentType) fSegment->verb();
  55. if (type != kLine_Segment) {
  56. return type;
  57. }
  58. if (fSegment->isHorizontal()) {
  59. return kHorizontalLine_Segment;
  60. }
  61. if (fSegment->isVertical()) {
  62. return kVerticalLine_Segment;
  63. }
  64. return kLine_Segment;
  65. }
  66. bool startAfter(const SkIntersectionHelper& after) {
  67. fSegment = after.fSegment->next();
  68. return fSegment != nullptr;
  69. }
  70. SkScalar top() const {
  71. return bounds().fTop;
  72. }
  73. SkScalar weight() const {
  74. return fSegment->weight();
  75. }
  76. SkScalar x() const {
  77. return bounds().fLeft;
  78. }
  79. bool xFlipped() const {
  80. return x() != pts()[0].fX;
  81. }
  82. SkScalar y() const {
  83. return bounds().fTop;
  84. }
  85. bool yFlipped() const {
  86. return y() != pts()[0].fY;
  87. }
  88. private:
  89. SkOpSegment* fSegment;
  90. };
  91. #endif