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, |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame^] | 22 | kConic_Segment = SkPath::kConic_Verb, |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 23 | kCubic_Segment = SkPath::kCubic_Verb, |
| 24 | }; |
| 25 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 26 | bool advance() { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 27 | fSegment = fSegment->next(); |
| 28 | return fSegment != NULL; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 29 | } |
| 30 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 31 | SkScalar bottom() const { |
| 32 | return bounds().fBottom; |
| 33 | } |
| 34 | |
| 35 | const SkPathOpsBounds& bounds() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 36 | return fSegment->bounds(); |
| 37 | } |
| 38 | |
| 39 | SkOpContour* contour() const { |
| 40 | return fSegment->contour(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void init(SkOpContour* contour) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 44 | fSegment = contour->first(); |
caryclark@google.com | a2bbc6e | 2013-11-01 17:36:03 +0000 | [diff] [blame] | 45 | } |
| 46 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 47 | SkScalar left() const { |
| 48 | return bounds().fLeft; |
| 49 | } |
| 50 | |
| 51 | const SkPoint* pts() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 52 | return fSegment->pts(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | SkScalar right() const { |
| 56 | return bounds().fRight; |
| 57 | } |
| 58 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 59 | SkOpSegment* segment() const { |
| 60 | return fSegment; |
| 61 | } |
| 62 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 63 | SegmentType segmentType() const { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 64 | SegmentType type = (SegmentType) fSegment->verb(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 65 | if (type != kLine_Segment) { |
| 66 | return type; |
| 67 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 68 | if (fSegment->isHorizontal()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | return kHorizontalLine_Segment; |
| 70 | } |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 71 | if (fSegment->isVertical()) { |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 72 | return kVerticalLine_Segment; |
| 73 | } |
| 74 | return kLine_Segment; |
| 75 | } |
| 76 | |
| 77 | bool startAfter(const SkIntersectionHelper& after) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 78 | fSegment = after.fSegment->next(); |
| 79 | return fSegment != NULL; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | SkScalar top() const { |
| 83 | return bounds().fTop; |
| 84 | } |
| 85 | |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame^] | 86 | SkScalar weight() const { |
| 87 | return fSegment->weight(); |
| 88 | } |
| 89 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 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 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 106 | private: |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 107 | SkOpSegment* fSegment; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 108 | }; |