blob: 79de034706b2c74f71b6f72748c40309abaa36ff [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 */
7#include "SkOpContour.h"
caryclark54359292015-03-26 07:52:43 -07008#include "SkOpSegment.h"
caryclark@google.com07393ca2013-04-08 11:47:37 +00009#include "SkPath.h"
10
robertphillips@google.comd998bec2013-11-03 13:40:34 +000011#ifdef SK_DEBUG
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000012#include "SkPathOpsPoint.h"
13#endif
14
caryclark@google.com07393ca2013-04-08 11:47:37 +000015class 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,
caryclark1049f122015-04-20 08:31:59 -070022 kConic_Segment = SkPath::kConic_Verb,
caryclark@google.com07393ca2013-04-08 11:47:37 +000023 kCubic_Segment = SkPath::kCubic_Verb,
24 };
25
caryclark@google.com07393ca2013-04-08 11:47:37 +000026 bool advance() {
caryclark54359292015-03-26 07:52:43 -070027 fSegment = fSegment->next();
28 return fSegment != NULL;
caryclarkdac1d172014-06-17 05:15:38 -070029 }
30
caryclark@google.com07393ca2013-04-08 11:47:37 +000031 SkScalar bottom() const {
32 return bounds().fBottom;
33 }
34
35 const SkPathOpsBounds& bounds() const {
caryclark54359292015-03-26 07:52:43 -070036 return fSegment->bounds();
37 }
38
39 SkOpContour* contour() const {
40 return fSegment->contour();
caryclark@google.com07393ca2013-04-08 11:47:37 +000041 }
42
43 void init(SkOpContour* contour) {
caryclark54359292015-03-26 07:52:43 -070044 fSegment = contour->first();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000045 }
46
caryclark@google.com07393ca2013-04-08 11:47:37 +000047 SkScalar left() const {
48 return bounds().fLeft;
49 }
50
51 const SkPoint* pts() const {
caryclark54359292015-03-26 07:52:43 -070052 return fSegment->pts();
caryclark@google.com07393ca2013-04-08 11:47:37 +000053 }
54
55 SkScalar right() const {
56 return bounds().fRight;
57 }
58
caryclark54359292015-03-26 07:52:43 -070059 SkOpSegment* segment() const {
60 return fSegment;
61 }
62
caryclark@google.com07393ca2013-04-08 11:47:37 +000063 SegmentType segmentType() const {
caryclark54359292015-03-26 07:52:43 -070064 SegmentType type = (SegmentType) fSegment->verb();
caryclark@google.com07393ca2013-04-08 11:47:37 +000065 if (type != kLine_Segment) {
66 return type;
67 }
caryclark54359292015-03-26 07:52:43 -070068 if (fSegment->isHorizontal()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000069 return kHorizontalLine_Segment;
70 }
caryclark54359292015-03-26 07:52:43 -070071 if (fSegment->isVertical()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000072 return kVerticalLine_Segment;
73 }
74 return kLine_Segment;
75 }
76
77 bool startAfter(const SkIntersectionHelper& after) {
caryclark54359292015-03-26 07:52:43 -070078 fSegment = after.fSegment->next();
79 return fSegment != NULL;
caryclark@google.com07393ca2013-04-08 11:47:37 +000080 }
81
82 SkScalar top() const {
83 return bounds().fTop;
84 }
85
caryclark1049f122015-04-20 08:31:59 -070086 SkScalar weight() const {
87 return fSegment->weight();
88 }
89
caryclark@google.com07393ca2013-04-08 11:47:37 +000090 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.com07393ca2013-04-08 11:47:37 +0000106private:
caryclark54359292015-03-26 07:52:43 -0700107 SkOpSegment* fSegment;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000108};