blob: cbdadf10398cedc64836f0619415203c731fc14a [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
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000067 void 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
caryclark@google.comcffbcc32013-06-04 17:59:42 +000090 bool unorderable() const {
91 return fUnorderable;
92 }
93
caryclark55888e42016-07-18 10:01:36 -070094private:
95 bool after(SkOpAngle* test);
96 int allOnOneSide(const SkOpAngle* test);
97 bool checkCrossesZero() const;
98 bool checkParallel(SkOpAngle* );
99 bool computeSector();
100 int convexHullOverlaps(const SkOpAngle* ) const;
101 bool endToSide(const SkOpAngle* rh, bool* inside) const;
102 bool endsIntersect(SkOpAngle* );
103 int findSector(SkPath::Verb verb, double x, double y) const;
104 SkOpGlobalState* globalState() const;
105 bool merge(SkOpAngle* );
106 double midT() const;
107 bool midToSide(const SkOpAngle* rh, bool* inside) const;
108 bool oppositePlanes(const SkOpAngle* rh) const;
109 bool orderable(SkOpAngle* rh); // false == this < rh ; true == this > rh
caryclark55888e42016-07-18 10:01:36 -0700110 void setSector();
111 void setSpans();
112 bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const;
113
114 SkDCurve fOriginalCurvePart; // the curve from start to end
caryclarkeed356d2016-09-14 07:18:20 -0700115 SkDCurveSweep fPart; // the curve from start to end offset as needed
caryclark@google.com07393ca2013-04-08 11:47:37 +0000116 double fSide;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000117 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000118 SkOpAngle* fNext;
caryclark54359292015-03-26 07:52:43 -0700119 SkOpSpanBase* fLastMarked;
caryclark54359292015-03-26 07:52:43 -0700120 SkOpSpanBase* fStart;
121 SkOpSpanBase* fEnd;
122 SkOpSpanBase* fComputedEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000123 int fSectorMask;
commit-bot@chromium.org86084632014-04-14 18:33:03 +0000124 int8_t fSectorStart; // in 32nds of a circle
125 int8_t fSectorEnd;
caryclark54359292015-03-26 07:52:43 -0700126 bool fUnorderable;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000127 bool fComputeSector;
128 bool fComputedSector;
caryclark54359292015-03-26 07:52:43 -0700129 bool fCheckCoincidence;
caryclark1049f122015-04-20 08:31:59 -0700130 SkDEBUGCODE(int fID);
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000131
caryclark55888e42016-07-18 10:01:36 -0700132 friend class PathOpsAngleTester;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000133};
134
caryclark54359292015-03-26 07:52:43 -0700135
caryclarkdac1d172014-06-17 05:15:38 -0700136
caryclark@google.com07393ca2013-04-08 11:47:37 +0000137#endif