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