caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | */ |
deanm | 12670eb | 2016-04-26 14:09:01 -0700 | [diff] [blame] | 7 | #ifndef SkIntersectionHelper_DEFINED |
| 8 | #define SkIntersectionHelper_DEFINED |
| 9 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 10 | #include "SkOpContour.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 11 | #include "SkOpSegment.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 12 | #include "SkPath.h" |
| 13 | |
robertphillips@google.com | d998bec | 2013-11-03 13:40:34 +0000 | [diff] [blame] | 14 | #ifdef SK_DEBUG |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 15 | #include "SkPathOpsPoint.h" |
| 16 | #endif |
| 17 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 25 | kConic_Segment = SkPath::kConic_Verb, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 26 | kCubic_Segment = SkPath::kCubic_Verb, |
| 27 | }; |
| 28 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 29 | bool advance() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 30 | fSegment = fSegment->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 31 | return fSegment != nullptr; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 32 | } |
| 33 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 34 | SkScalar bottom() const { |
| 35 | return bounds().fBottom; |
| 36 | } |
| 37 | |
| 38 | const SkPathOpsBounds& bounds() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 39 | return fSegment->bounds(); |
| 40 | } |
| 41 | |
| 42 | SkOpContour* contour() const { |
| 43 | return fSegment->contour(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void init(SkOpContour* contour) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 47 | fSegment = contour->first(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 48 | } |
| 49 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 50 | SkScalar left() const { |
| 51 | return bounds().fLeft; |
| 52 | } |
| 53 | |
| 54 | const SkPoint* pts() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 55 | return fSegment->pts(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | SkScalar right() const { |
| 59 | return bounds().fRight; |
| 60 | } |
| 61 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 62 | SkOpSegment* segment() const { |
| 63 | return fSegment; |
| 64 | } |
| 65 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 66 | SegmentType segmentType() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 67 | SegmentType type = (SegmentType) fSegment->verb(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 68 | if (type != kLine_Segment) { |
| 69 | return type; |
| 70 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 71 | if (fSegment->isHorizontal()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 72 | return kHorizontalLine_Segment; |
| 73 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 74 | if (fSegment->isVertical()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 75 | return kVerticalLine_Segment; |
| 76 | } |
| 77 | return kLine_Segment; |
| 78 | } |
| 79 | |
| 80 | bool startAfter(const SkIntersectionHelper& after) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 81 | fSegment = after.fSegment->next(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 82 | return fSegment != nullptr; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | SkScalar top() const { |
| 86 | return bounds().fTop; |
| 87 | } |
| 88 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 89 | SkScalar weight() const { |
| 90 | return fSegment->weight(); |
| 91 | } |
| 92 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 93 | SkScalar x() const { |
| 94 | return bounds().fLeft; |
| 95 | } |
| 96 | |
| 97 | bool xFlipped() const { |
| 98 | return x() != pts()[0].fX; |
| 99 | } |
| 100 | |
| 101 | SkScalar y() const { |
| 102 | return bounds().fTop; |
| 103 | } |
| 104 | |
| 105 | bool yFlipped() const { |
| 106 | return y() != pts()[0].fY; |
| 107 | } |
| 108 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 109 | private: |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 110 | SkOpSegment* fSegment; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 111 | }; |
deanm | 12670eb | 2016-04-26 14:09:01 -0700 | [diff] [blame] | 112 | |
| 113 | #endif |