blob: 9a8a582af64e7d2e537c5d2096ae5455adaaf8c0 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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 */
deanm12670eb2016-04-26 14:09:01 -07007#ifndef SkIntersectionHelper_DEFINED
8#define SkIntersectionHelper_DEFINED
9
caryclark@google.com07393ca2013-04-08 11:47:37 +000010#include "SkOpContour.h"
caryclark54359292015-03-26 07:52:43 -070011#include "SkOpSegment.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +000012#include "SkPath.h"
13
robertphillips@google.comd998bec2013-11-03 13:40:34 +000014#ifdef SK_DEBUG
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000015#include "SkPathOpsPoint.h"
16#endif
17
caryclark@google.com07393ca2013-04-08 11:47:37 +000018class SkIntersectionHelper {
19public:
20 enum SegmentType {
21 kHorizontalLine_Segment = -1,
22 kVerticalLine_Segment = 0,
23 kLine_Segment = SkPath::kLine_Verb,
24 kQuad_Segment = SkPath::kQuad_Verb,
caryclark1049f122015-04-20 08:31:59 -070025 kConic_Segment = SkPath::kConic_Verb,
caryclark@google.com07393ca2013-04-08 11:47:37 +000026 kCubic_Segment = SkPath::kCubic_Verb,
27 };
28
caryclark@google.com07393ca2013-04-08 11:47:37 +000029 bool advance() {
caryclark54359292015-03-26 07:52:43 -070030 fSegment = fSegment->next();
halcanary96fcdcc2015-08-27 07:41:13 -070031 return fSegment != nullptr;
caryclarkdac1d172014-06-17 05:15:38 -070032 }
33
caryclark@google.com07393ca2013-04-08 11:47:37 +000034 SkScalar bottom() const {
35 return bounds().fBottom;
36 }
37
38 const SkPathOpsBounds& bounds() const {
caryclark54359292015-03-26 07:52:43 -070039 return fSegment->bounds();
40 }
41
42 SkOpContour* contour() const {
43 return fSegment->contour();
caryclark@google.com07393ca2013-04-08 11:47:37 +000044 }
45
46 void init(SkOpContour* contour) {
caryclark54359292015-03-26 07:52:43 -070047 fSegment = contour->first();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000048 }
49
caryclark@google.com07393ca2013-04-08 11:47:37 +000050 SkScalar left() const {
51 return bounds().fLeft;
52 }
53
54 const SkPoint* pts() const {
caryclark54359292015-03-26 07:52:43 -070055 return fSegment->pts();
caryclark@google.com07393ca2013-04-08 11:47:37 +000056 }
57
58 SkScalar right() const {
59 return bounds().fRight;
60 }
61
caryclark54359292015-03-26 07:52:43 -070062 SkOpSegment* segment() const {
63 return fSegment;
64 }
65
caryclark@google.com07393ca2013-04-08 11:47:37 +000066 SegmentType segmentType() const {
caryclark54359292015-03-26 07:52:43 -070067 SegmentType type = (SegmentType) fSegment->verb();
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 if (type != kLine_Segment) {
69 return type;
70 }
caryclark54359292015-03-26 07:52:43 -070071 if (fSegment->isHorizontal()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000072 return kHorizontalLine_Segment;
73 }
caryclark54359292015-03-26 07:52:43 -070074 if (fSegment->isVertical()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000075 return kVerticalLine_Segment;
76 }
77 return kLine_Segment;
78 }
79
80 bool startAfter(const SkIntersectionHelper& after) {
caryclark54359292015-03-26 07:52:43 -070081 fSegment = after.fSegment->next();
halcanary96fcdcc2015-08-27 07:41:13 -070082 return fSegment != nullptr;
caryclark@google.com07393ca2013-04-08 11:47:37 +000083 }
84
85 SkScalar top() const {
86 return bounds().fTop;
87 }
88
caryclark1049f122015-04-20 08:31:59 -070089 SkScalar weight() const {
90 return fSegment->weight();
91 }
92
caryclark@google.com07393ca2013-04-08 11:47:37 +000093 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.com07393ca2013-04-08 11:47:37 +0000109private:
caryclark54359292015-03-26 07:52:43 -0700110 SkOpSegment* fSegment;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000111};
deanm12670eb2016-04-26 14:09:01 -0700112
113#endif