blob: 01150e6ff74d88363b1ee81cb3bef2a68d887685 [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
caryclark@google.com07393ca2013-04-08 11:47:37 +000027 int end() const {
28 return fEnd;
29 }
30
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000031 const SkOpAngle* findFirst() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000032
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000033 bool inLoop() const {
34 return !!fNext;
caryclark@google.com570863f2013-09-16 15:55:01 +000035 }
36
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000037 void insert(SkOpAngle* );
38 bool isHorizontal() const;
39 SkOpSpan* lastMarked() const;
40 int loopCount() const;
41 void markStops();
42 bool merge(SkOpAngle* );
43
44 SkOpAngle* next() const {
45 return fNext;
46 }
47
48 SkOpAngle* previous() const;
49
caryclark@google.comcffbcc32013-06-04 17:59:42 +000050 void set(const SkOpSegment* segment, int start, int end);
caryclark@google.comad65a3e2013-04-15 19:13:59 +000051
caryclark@google.com570863f2013-09-16 15:55:01 +000052 void setLastMarked(SkOpSpan* marked) {
53 fLastMarked = marked;
54 }
55
caryclark@google.com07393ca2013-04-08 11:47:37 +000056 SkOpSegment* segment() const {
57 return const_cast<SkOpSegment*>(fSegment);
58 }
59
60 int sign() const {
61 return SkSign32(fStart - fEnd);
62 }
63
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000064 bool small() const;
65
caryclark@google.com07393ca2013-04-08 11:47:37 +000066 int start() const {
67 return fStart;
68 }
69
caryclark@google.comcffbcc32013-06-04 17:59:42 +000070 bool unorderable() const {
71 return fUnorderable;
72 }
73
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000074 // available to testing only
75#if DEBUG_SORT
76 void debugLoop() const; // called by code during run
caryclark@google.com570863f2013-09-16 15:55:01 +000077#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000078#if DEBUG_ANGLE
79 void debugSameAs(const SkOpAngle* compare) const;
80#endif
81 void dump() const;
82 void dumpFromTo(const SkOpSegment* fromSeg, int from, int to) const;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000083
caryclark@google.com570863f2013-09-16 15:55:01 +000084#if DEBUG_ANGLE
caryclark@google.comcffbcc32013-06-04 17:59:42 +000085 void setID(int id) {
86 fID = id;
87 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000088#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000089#if DEBUG_VALIDATE
90 void debugValidateLoop() const;
91#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +000092
93private:
commit-bot@chromium.org4431e772014-04-14 17:08:59 +000094 bool after(const SkOpAngle* test) const;
95 int allOnOneSide(const SkOpAngle& test) const;
96 bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
97 bool checkCrossesZero() const;
98 bool checkParallel(const SkOpAngle& ) const;
99 bool computeSector();
100 int convexHullOverlaps(const SkOpAngle& ) const;
101 double distEndRatio(double dist) const;
102 int findSector(SkPath::Verb verb, double x, double y) const;
103 bool endsIntersect(const SkOpAngle& ) const;
104 double midT() const;
105 bool oppositePlanes(const SkOpAngle& rh) const;
106 bool orderable(const SkOpAngle& rh) const; // false == this < rh ; true == this > rh
107 void setCurveHullSweep();
108 void setSector();
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000109 void setSpans();
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000110 bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000111
caryclark@google.com570863f2013-09-16 15:55:01 +0000112 SkDCubic fCurvePart; // the curve from start to end
caryclark@google.com07393ca2013-04-08 11:47:37 +0000113 double fSide;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000114 SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections
caryclark@google.com07393ca2013-04-08 11:47:37 +0000115 const SkOpSegment* fSegment;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000116 SkOpAngle* fNext;
caryclark@google.com570863f2013-09-16 15:55:01 +0000117 SkOpSpan* fLastMarked;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000118 SkDVector fSweep[2];
caryclark@google.com07393ca2013-04-08 11:47:37 +0000119 int fStart;
120 int fEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000121 int fSectorMask;
commit-bot@chromium.org86084632014-04-14 18:33:03 +0000122 int8_t fSectorStart; // in 32nds of a circle
123 int8_t fSectorEnd;
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000124 bool fIsCurve;
125 bool fStop; // set if ordered angle is greater than the previous
126 mutable bool fUnorderable; // this is editable by orderable()
127 bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors
128 bool fComputeSector;
129 bool fComputedSector;
130
131#if DEBUG_SORT
132 void debugOne(bool showFunc) const; // available to testing only
133#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000134#if DEBUG_ANGLE
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000135 int debugID() const { return fID; }
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000136 int fID;
137#endif
commit-bot@chromium.org4431e772014-04-14 17:08:59 +0000138#if DEBUG_VALIDATE
139 void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted
140#else
141 void debugValidateNext() const {}
142#endif
143 void dumpLoop() const; // utility to be called by user from debugger
144 void dumpPartials() const; // utility to be called by user from debugger
145 friend class PathOpsAngleTester;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000146};
147
148#endif