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