blob: 4b209de32da3448d15d72e4d01be74bb5e988d0b [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#ifndef SkOpAngle_DEFINED
8#define SkOpAngle_DEFINED
9
10#include "SkLineParameters.h"
caryclark1049f122015-04-20 08:31:59 -070011#include "SkPathOpsCurve.h"
caryclark54359292015-03-26 07:52:43 -070012#if DEBUG_ANGLE
13#include "SkString.h"
14#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +000015
caryclark54359292015-03-26 07:52:43 -070016class SkOpContour;
17class SkOpPtT;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000018class SkOpSegment;
caryclark54359292015-03-26 07:52:43 -070019class SkOpSpanBase;
20class SkOpSpan;
caryclark@google.com07393ca2013-04-08 11:47:37 +000021
caryclark54359292015-03-26 07:52:43 -070022struct SkOpAngle {
caryclark@google.com570863f2013-09-16 15:55:01 +000023 enum IncludeType {
24 kUnaryWinding,
25 kUnaryXor,
26 kBinarySingle,
27 kBinaryOpp,
28 };
caryclark@google.comd892bd82013-06-17 14:10:36 +000029
caryclark54359292015-03-26 07:52:43 -070030 bool after(SkOpAngle* test);
31 int allOnOneSide(const SkOpAngle* test);
32 bool checkCrossesZero() const;
caryclark54359292015-03-26 07:52:43 -070033 bool checkParallel(SkOpAngle* );
34 bool computeSector();
35 int convexHullOverlaps(const SkOpAngle* ) const;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000036
caryclark54359292015-03-26 07:52:43 -070037 const SkOpAngle* debugAngle(int id) const;
38 SkOpContour* debugContour(int id);
39
40 int debugID() const {
caryclark1049f122015-04-20 08:31:59 -070041 return SkDEBUGRELEASE(fID, -1);
caryclark54359292015-03-26 07:52:43 -070042 }
43
caryclark624637c2015-05-11 07:21:27 -070044#if DEBUG_SORT
caryclark54359292015-03-26 07:52:43 -070045 void debugLoop() const;
46#endif
47
48#if DEBUG_ANGLE
caryclark26ad22a2015-10-16 09:03:38 -070049 void debugCheckNearCoincidence() const;
caryclark54359292015-03-26 07:52:43 -070050 SkString debugPart() const;
51#endif
52 const SkOpPtT* debugPtT(int id) const;
53 const SkOpSegment* debugSegment(int id) const;
caryclark624637c2015-05-11 07:21:27 -070054 int debugSign() const;
caryclark54359292015-03-26 07:52:43 -070055 const SkOpSpanBase* debugSpan(int id) const;
56 void debugValidate() const;
57 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted
58 double distEndRatio(double dist) const;
59 // available to testing only
60 void dump() const;
61 void dumpCurves() const;
62 void dumpLoop() const;
63 void dumpOne(bool functionHeader) const;
64 void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const;
65 void dumpTest() const;
66
67 SkOpSpanBase* end() const {
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 return fEnd;
69 }
70
caryclark54359292015-03-26 07:52:43 -070071 bool endsIntersect(SkOpAngle* );
72 bool endToSide(const SkOpAngle* rh, bool* inside) const;
caryclark54359292015-03-26 07:52:43 -070073 int findSector(SkPath::Verb verb, double x, double y) const;
74 SkOpGlobalState* globalState() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000075 void insert(SkOpAngle* );
caryclark54359292015-03-26 07:52:43 -070076 SkOpSpanBase* lastMarked() const;
77 bool loopContains(const SkOpAngle* ) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000078 int loopCount() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000079 bool merge(SkOpAngle* );
caryclark54359292015-03-26 07:52:43 -070080 double midT() const;
81 bool midToSide(const SkOpAngle* rh, bool* inside) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000082
83 SkOpAngle* next() const {
84 return fNext;
85 }
86
caryclark54359292015-03-26 07:52:43 -070087 bool oppositePlanes(const SkOpAngle* rh) const;
88 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000089 SkOpAngle* previous() const;
90
caryclark65f55312014-11-13 06:58:52 -080091 int sectorEnd() const {
92 return fSectorEnd;
93 }
94
95 int sectorStart() const {
96 return fSectorStart;
97 }
98
caryclark54359292015-03-26 07:52:43 -070099 SkOpSegment* segment() const;
caryclark@google.comad65a3e2013-04-15 19:13:59 +0000100
caryclark54359292015-03-26 07:52:43 -0700101 void set(SkOpSpanBase* start, SkOpSpanBase* end);
102 void setCurveHullSweep();
103
104 void setID(int id) {
caryclark1049f122015-04-20 08:31:59 -0700105 SkDEBUGCODE(fID = id);
caryclark54359292015-03-26 07:52:43 -0700106 }
107
108 void setLastMarked(SkOpSpanBase* marked) {
caryclark@google.com570863f2013-09-16 15:55:01 +0000109 fLastMarked = marked;
110 }
111
caryclark54359292015-03-26 07:52:43 -0700112 void setSector();
113 void setSpans();
caryclark@google.com07393ca2013-04-08 11:47:37 +0000114
caryclark54359292015-03-26 07:52:43 -0700115 SkOpSpanBase* start() const {
reed0dc4dd62015-03-24 13:55:33 -0700116 return fStart;
117 }
caryclarkccec0f92015-03-24 07:28:17 -0700118
caryclark54359292015-03-26 07:52:43 -0700119 SkOpSpan* starter();
120 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const;
121
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000122 bool unorderable() const {
123 return fUnorderable;
124 }
125
caryclark1049f122015-04-20 08:31:59 -0700126 SkDCurve fCurvePart; // the curve from start to end
caryclark@google.com07393ca2013-04-08 11:47:37 +0000127 double fSide;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000128 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000129 SkOpAngle* fNext;
caryclark54359292015-03-26 07:52:43 -0700130 SkOpSpanBase* fLastMarked;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000131 SkDVector fSweep[2];
caryclark54359292015-03-26 07:52:43 -0700132 SkOpSpanBase* fStart;
133 SkOpSpanBase* fEnd;
134 SkOpSpanBase* fComputedEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000135 int fSectorMask;
commit-bot@chromium.org86084632014-04-14 18:33:03 +0000136 int8_t fSectorStart; // in 32nds of a circle
137 int8_t fSectorEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000138 bool fIsCurve;
caryclark54359292015-03-26 07:52:43 -0700139 bool fUnorderable;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000140 bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors
141 bool fComputeSector;
142 bool fComputedSector;
caryclark54359292015-03-26 07:52:43 -0700143 bool fCheckCoincidence;
caryclark1049f122015-04-20 08:31:59 -0700144 SkDEBUGCODE(int fID);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000145
caryclark@google.com07393ca2013-04-08 11:47:37 +0000146};
147
caryclark54359292015-03-26 07:52:43 -0700148
caryclarkdac1d172014-06-17 05:15:38 -0700149
caryclark@google.com07393ca2013-04-08 11:47:37 +0000150#endif