blob: d8615c322944e02ffcff6f19da0d9304b1ec32a9 [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
caryclark55888e42016-07-18 10:01:36 -070022class SkOpAngle {
23public:
caryclark@google.com570863f2013-09-16 15:55:01 +000024 enum IncludeType {
25 kUnaryWinding,
26 kUnaryXor,
27 kBinarySingle,
28 kBinaryOpp,
29 };
caryclark@google.comd892bd82013-06-17 14:10:36 +000030
caryclark54359292015-03-26 07:52:43 -070031 const SkOpAngle* debugAngle(int id) const;
caryclark55888e42016-07-18 10:01:36 -070032 const SkOpCoincidence* debugCoincidence() const;
caryclark30b9fdd2016-08-31 14:36:29 -070033 SkOpContour* debugContour(int id) const;
caryclark54359292015-03-26 07:52:43 -070034
35 int debugID() const {
caryclark1049f122015-04-20 08:31:59 -070036 return SkDEBUGRELEASE(fID, -1);
caryclark54359292015-03-26 07:52:43 -070037 }
38
caryclark624637c2015-05-11 07:21:27 -070039#if DEBUG_SORT
caryclark54359292015-03-26 07:52:43 -070040 void debugLoop() const;
41#endif
42
43#if DEBUG_ANGLE
caryclark55888e42016-07-18 10:01:36 -070044 bool debugCheckCoincidence() const { return fCheckCoincidence; }
caryclark26ad22a2015-10-16 09:03:38 -070045 void debugCheckNearCoincidence() const;
caryclark54359292015-03-26 07:52:43 -070046 SkString debugPart() const;
47#endif
48 const SkOpPtT* debugPtT(int id) const;
49 const SkOpSegment* debugSegment(int id) const;
caryclark624637c2015-05-11 07:21:27 -070050 int debugSign() const;
caryclark54359292015-03-26 07:52:43 -070051 const SkOpSpanBase* debugSpan(int id) const;
caryclark55888e42016-07-18 10:01:36 -070052 void debugValidate() const;
caryclark54359292015-03-26 07:52:43 -070053 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted
54 double distEndRatio(double dist) const;
55 // available to testing only
56 void dump() const;
57 void dumpCurves() const;
58 void dumpLoop() const;
59 void dumpOne(bool functionHeader) const;
60 void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const;
61 void dumpTest() const;
62
63 SkOpSpanBase* end() const {
caryclark@google.com07393ca2013-04-08 11:47:37 +000064 return fEnd;
65 }
66
caryclarkb36a3cd2016-10-18 07:59:44 -070067 bool insert(SkOpAngle* );
caryclark54359292015-03-26 07:52:43 -070068 SkOpSpanBase* lastMarked() const;
69 bool loopContains(const SkOpAngle* ) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000070 int loopCount() const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000071
72 SkOpAngle* next() const {
73 return fNext;
74 }
75
76 SkOpAngle* previous() const;
caryclark54359292015-03-26 07:52:43 -070077 SkOpSegment* segment() const;
caryclark54359292015-03-26 07:52:43 -070078 void set(SkOpSpanBase* start, SkOpSpanBase* end);
caryclark54359292015-03-26 07:52:43 -070079
80 void setLastMarked(SkOpSpanBase* marked) {
caryclark@google.com570863f2013-09-16 15:55:01 +000081 fLastMarked = marked;
82 }
83
caryclark54359292015-03-26 07:52:43 -070084 SkOpSpanBase* start() const {
reed0dc4dd62015-03-24 13:55:33 -070085 return fStart;
86 }
caryclarkccec0f92015-03-24 07:28:17 -070087
caryclark54359292015-03-26 07:52:43 -070088 SkOpSpan* starter();
caryclark54359292015-03-26 07:52:43 -070089
caryclarkb36a3cd2016-10-18 07:59:44 -070090 bool tangentsAmbiguous() const {
91 return fTangentsAmbiguous;
92 }
93
caryclark@google.comcffbcc32013-06-04 17:59:42 +000094 bool unorderable() const {
95 return fUnorderable;
96 }
97
caryclark55888e42016-07-18 10:01:36 -070098private:
99 bool after(SkOpAngle* test);
Cary Clarkff114282016-12-14 11:56:16 -0500100 void alignmentSameSide(const SkOpAngle* test, int* order) const;
caryclark55888e42016-07-18 10:01:36 -0700101 int allOnOneSide(const SkOpAngle* test);
Cary Clark59d5a0e2017-01-23 14:38:52 +0000102 bool checkCrossesZero() const;
caryclark55888e42016-07-18 10:01:36 -0700103 bool checkParallel(SkOpAngle* );
104 bool computeSector();
caryclarkb36a3cd2016-10-18 07:59:44 -0700105 int convexHullOverlaps(const SkOpAngle* );
caryclark55888e42016-07-18 10:01:36 -0700106 bool endToSide(const SkOpAngle* rh, bool* inside) const;
107 bool endsIntersect(SkOpAngle* );
108 int findSector(SkPath::Verb verb, double x, double y) const;
109 SkOpGlobalState* globalState() const;
110 bool merge(SkOpAngle* );
111 double midT() const;
112 bool midToSide(const SkOpAngle* rh, bool* inside) const;
113 bool oppositePlanes(const SkOpAngle* rh) const;
114 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh
caryclark55888e42016-07-18 10:01:36 -0700115 void setSector();
116 void setSpans();
caryclarkb36a3cd2016-10-18 07:59:44 -0700117 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0);
caryclark55888e42016-07-18 10:01:36 -0700118
119 SkDCurve fOriginalCurvePart; // the curve from start to end
caryclarkeed356d2016-09-14 07:18:20 -0700120 SkDCurveSweep fPart; // the curve from start to end offset as needed
caryclark@google.com07393ca2013-04-08 11:47:37 +0000121 double fSide;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000122 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000123 SkOpAngle* fNext;
caryclark54359292015-03-26 07:52:43 -0700124 SkOpSpanBase* fLastMarked;
caryclark54359292015-03-26 07:52:43 -0700125 SkOpSpanBase* fStart;
126 SkOpSpanBase* fEnd;
127 SkOpSpanBase* fComputedEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000128 int fSectorMask;
commit-bot@chromium.org86084632014-04-14 18:33:03 +0000129 int8_t fSectorStart; // in 32nds of a circle
130 int8_t fSectorEnd;
caryclark54359292015-03-26 07:52:43 -0700131 bool fUnorderable;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000132 bool fComputeSector;
133 bool fComputedSector;
caryclark54359292015-03-26 07:52:43 -0700134 bool fCheckCoincidence;
caryclarkb36a3cd2016-10-18 07:59:44 -0700135 bool fTangentsAmbiguous;
caryclark1049f122015-04-20 08:31:59 -0700136 SkDEBUGCODE(int fID);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000137
caryclark55888e42016-07-18 10:01:36 -0700138 friend class PathOpsAngleTester;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000139};
140
caryclark54359292015-03-26 07:52:43 -0700141
caryclarkdac1d172014-06-17 05:15:38 -0700142
caryclark@google.com07393ca2013-04-08 11:47:37 +0000143#endif