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