blob: c633fd02dfdffbb397a18206bd4fdd83a6b4bc54 [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,
22 kCubic_Segment = SkPath::kCubic_Verb,
23 };
24
caryclark@google.com07393ca2013-04-08 11:47:37 +000025 bool advance() {
caryclark54359292015-03-26 07:52:43 -070026 fSegment = fSegment->next();
27 return fSegment != NULL;
caryclarkdac1d172014-06-17 05:15:38 -070028 }
29
caryclark@google.com07393ca2013-04-08 11:47:37 +000030 SkScalar bottom() const {
31 return bounds().fBottom;
32 }
33
34 const SkPathOpsBounds& bounds() const {
caryclark54359292015-03-26 07:52:43 -070035 return fSegment->bounds();
36 }
37
38 SkOpContour* contour() const {
39 return fSegment->contour();
caryclark@google.com07393ca2013-04-08 11:47:37 +000040 }
41
42 void init(SkOpContour* contour) {
caryclark54359292015-03-26 07:52:43 -070043 fSegment = contour->first();
caryclark@google.coma2bbc6e2013-11-01 17:36:03 +000044 }
45
caryclark@google.com07393ca2013-04-08 11:47:37 +000046 SkScalar left() const {
47 return bounds().fLeft;
48 }
49
50 const SkPoint* pts() const {
caryclark54359292015-03-26 07:52:43 -070051 return fSegment->pts();
caryclark@google.com07393ca2013-04-08 11:47:37 +000052 }
53
54 SkScalar right() const {
55 return bounds().fRight;
56 }
57
caryclark54359292015-03-26 07:52:43 -070058 SkOpSegment* segment() const {
59 return fSegment;
60 }
61
caryclark@google.com07393ca2013-04-08 11:47:37 +000062 SegmentType segmentType() const {
caryclark54359292015-03-26 07:52:43 -070063 SegmentType type = (SegmentType) fSegment->verb();
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 if (type != kLine_Segment) {
65 return type;
66 }
caryclark54359292015-03-26 07:52:43 -070067 if (fSegment->isHorizontal()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 return kHorizontalLine_Segment;
69 }
caryclark54359292015-03-26 07:52:43 -070070 if (fSegment->isVertical()) {
caryclark@google.com07393ca2013-04-08 11:47:37 +000071 return kVerticalLine_Segment;
72 }
73 return kLine_Segment;
74 }
75
76 bool startAfter(const SkIntersectionHelper& after) {
caryclark54359292015-03-26 07:52:43 -070077 fSegment = after.fSegment->next();
78 return fSegment != NULL;
caryclark@google.com07393ca2013-04-08 11:47:37 +000079 }
80
81 SkScalar top() const {
82 return bounds().fTop;
83 }
84
caryclark@google.com07393ca2013-04-08 11:47:37 +000085 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.com07393ca2013-04-08 11:47:37 +0000101private:
caryclark54359292015-03-26 07:52:43 -0700102 SkOpSegment* fSegment;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000103};