blob: e5669133e45486df9ab4deea0df39c58b26d6e97 [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"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000011
12class SkOpSegment;
caryclark@google.com570863f2013-09-16 15:55:01 +000013struct SkOpSpan;
caryclark@google.com07393ca2013-04-08 11:47:37 +000014
15// sorting angles
16// given angles of {dx dy ddx ddy dddx dddy} sort them
17class SkOpAngle {
18public:
caryclark@google.comd892bd82013-06-17 14:10:36 +000019 enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
caryclark@google.com570863f2013-09-16 15:55:01 +000020 enum IncludeType {
21 kUnaryWinding,
22 kUnaryXor,
23 kBinarySingle,
24 kBinaryOpp,
25 };
caryclark@google.comd892bd82013-06-17 14:10:36 +000026
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000027
caryclark@google.com07393ca2013-04-08 11:47:37 +000028 int end() const {
29 return fEnd;
30 }
31
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000032 const SkOpAngle* findFirst() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000033
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000034 bool inLoop() const {
35 return !!fNext;
caryclark@google.com570863f2013-09-16 15:55:01 +000036 }
37
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000038 void insert(SkOpAngle* );
39 bool isHorizontal() const;
40 SkOpSpan* lastMarked() const;
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +000041 bool loopContains(const SkOpAngle& ) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000042 int loopCount() const;
43 void markStops();
44 bool merge(SkOpAngle* );
45
46 SkOpAngle* next() const {
47 return fNext;
48 }
49
50 SkOpAngle* previous() const;
51
caryclark@google.comcffbcc32013-06-04 17:59:42 +000052 void set(const SkOpSegment* segment, int start, int end);
caryclark@google.comad65a3e2013-04-15 19:13:59 +000053
caryclark@google.com570863f2013-09-16 15:55:01 +000054 void setLastMarked(SkOpSpan* marked) {
55 fLastMarked = marked;
56 }
57
caryclark@google.com07393ca2013-04-08 11:47:37 +000058 SkOpSegment* segment() const {
59 return const_cast<SkOpSegment*>(fSegment);
60 }
61
62 int sign() const {
63 return SkSign32(fStart - fEnd);
64 }
65
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000066 bool small() const;
67
caryclark@google.com07393ca2013-04-08 11:47:37 +000068 int start() const {
69 return fStart;
70 }
71
caryclark@google.comcffbcc32013-06-04 17:59:42 +000072 bool unorderable() const {
73 return fUnorderable;
74 }
75
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000076 // available to testing only
77#if DEBUG_SORT
78 void debugLoop() const; // called by code during run
caryclark@google.com570863f2013-09-16 15:55:01 +000079#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000080#if DEBUG_ANGLE
81 void debugSameAs(const SkOpAngle* compare) const;
82#endif
83 void dump() const;
84 void dumpFromTo(const SkOpSegment* fromSeg, int from, int to) const;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000085
caryclark@google.com570863f2013-09-16 15:55:01 +000086#if DEBUG_ANGLE
caryclark@google.comcffbcc32013-06-04 17:59:42 +000087 void setID(int id) {
88 fID = id;
89 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000090#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000091#if DEBUG_VALIDATE
92 void debugValidateLoop() const;
93#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +000094
95private:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000096 bool after(const SkOpAngle* test) const;
97 int allOnOneSide(const SkOpAngle& test) const;
98 bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
99 bool checkCrossesZero() const;
100 bool checkParallel(const SkOpAngle& ) const;
101 bool computeSector();
102 int convexHullOverlaps(const SkOpAngle& ) const;
103 double distEndRatio(double dist) const;
104 int findSector(SkPath::Verb verb, double x, double y) const;
105 bool endsIntersect(const SkOpAngle& ) const;
106 double midT() const;
107 bool oppositePlanes(const SkOpAngle& rh) const;
108 bool orderable(const SkOpAngle& rh) const; // false == this < rh ; true == this > rh
commit-bot@chromium.org8cb1daa2014-04-25 12:59:11 +0000109 bool overlap(const SkOpAngle& test) const;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000110 void setCurveHullSweep();
111 void setSector();
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000112 void setSpans();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000113 bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000114
caryclark@google.com570863f2013-09-16 15:55:01 +0000115 SkDCubic fCurvePart; // the curve from start to end
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
caryclark@google.com07393ca2013-04-08 11:47:37 +0000118 const SkOpSegment* fSegment;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000119 SkOpAngle* fNext;
caryclark@google.com570863f2013-09-16 15:55:01 +0000120 SkOpSpan* fLastMarked;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000121 SkDVector fSweep[2];
caryclark@google.com07393ca2013-04-08 11:47:37 +0000122 int fStart;
123 int fEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000124 int fSectorMask;
commit-bot@chromium.org86084632014-04-14 18:33:03 +0000125 int8_t fSectorStart; // in 32nds of a circle
126 int8_t fSectorEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000127 bool fIsCurve;
128 bool fStop; // set if ordered angle is greater than the previous
129 mutable bool fUnorderable; // this is editable by orderable()
130 bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors
131 bool fComputeSector;
132 bool fComputedSector;
133
134#if DEBUG_SORT
135 void debugOne(bool showFunc) const; // available to testing only
136#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000137#if DEBUG_ANGLE
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000138 int debugID() const { return fID; }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000139 int fID;
140#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000141#if DEBUG_VALIDATE
142 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted
143#else
144 void debugValidateNext() const {}
145#endif
146 void dumpLoop() const; // utility to be called by user from debugger
147 void dumpPartials() const; // utility to be called by user from debugger
148 friend class PathOpsAngleTester;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000149};
150
151#endif