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 15class SkIntersectionHelper { 16public: 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 26 bool advance() { 27 fSegment = fSegment->next(); 28 return fSegment != nullptr; 29 } 30 31 SkScalar bottom() const { 32 return bounds().fBottom; 33 } 34 35 const SkPathOpsBounds& bounds() const { 36 return fSegment->bounds(); 37 } 38 39 SkOpContour* contour() const { 40 return fSegment->contour(); 41 } 42 43 void init(SkOpContour* contour) { 44 fSegment = contour->first(); 45 } 46 47 SkScalar left() const { 48 return bounds().fLeft; 49 } 50 51 const SkPoint* pts() const { 52 return fSegment->pts(); 53 } 54 55 SkScalar right() const { 56 return bounds().fRight; 57 } 58 59 SkOpSegment* segment() const { 60 return fSegment; 61 } 62 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 77 bool startAfter(const SkIntersectionHelper& after) { 78 fSegment = after.fSegment->next(); 79 return fSegment != nullptr; 80 } 81 82 SkScalar top() const { 83 return bounds().fTop; 84 } 85 86 SkScalar weight() const { 87 return fSegment->weight(); 88 } 89 90 SkScalar x() const { 91 return bounds().fLeft; 92 } 93 94 bool xFlipped() const { 95 return x() != pts()[0].fX; 96 } 97 98 SkScalar y() const { 99 return bounds().fTop; 100 } 101 102 bool yFlipped() const { 103 return y() != pts()[0].fY; 104 } 105 106private: 107 SkOpSegment* fSegment; 108}; 109