caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 10 | #include "SkChunkAlloc.h" |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 11 | #include "SkLineParameters.h" |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 12 | |
| 13 | class SkOpSegment; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 14 | struct SkOpSpan; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 15 | |
| 16 | // sorting angles |
| 17 | // given angles of {dx dy ddx ddy dddx dddy} sort them |
| 18 | class SkOpAngle { |
| 19 | public: |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 20 | enum { kStackBasedCount = 8 }; // FIXME: determine what this should be |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 21 | enum IncludeType { |
| 22 | kUnaryWinding, |
| 23 | kUnaryXor, |
| 24 | kBinarySingle, |
| 25 | kBinaryOpp, |
| 26 | }; |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 27 | |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 28 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 29 | int end() const { |
| 30 | return fEnd; |
| 31 | } |
| 32 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 33 | const SkOpAngle* findFirst() const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 34 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 35 | bool inLoop() const { |
| 36 | return !!fNext; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 37 | } |
| 38 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 39 | void insert(SkOpAngle* ); |
| 40 | bool isHorizontal() const; |
| 41 | SkOpSpan* lastMarked() const; |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 42 | bool loopContains(const SkOpAngle& ) const; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 43 | int loopCount() const; |
| 44 | void markStops(); |
| 45 | bool merge(SkOpAngle* ); |
| 46 | |
| 47 | SkOpAngle* next() const { |
| 48 | return fNext; |
| 49 | } |
| 50 | |
| 51 | SkOpAngle* previous() const; |
| 52 | |
caryclark | 65f5531 | 2014-11-13 06:58:52 -0800 | [diff] [blame^] | 53 | int sectorEnd() const { |
| 54 | return fSectorEnd; |
| 55 | } |
| 56 | |
| 57 | int sectorStart() const { |
| 58 | return fSectorStart; |
| 59 | } |
| 60 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 61 | void set(const SkOpSegment* segment, int start, int end); |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 62 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 63 | void setLastMarked(SkOpSpan* marked) { |
| 64 | fLastMarked = marked; |
| 65 | } |
| 66 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 67 | SkOpSegment* segment() const { |
| 68 | return const_cast<SkOpSegment*>(fSegment); |
| 69 | } |
| 70 | |
| 71 | int sign() const { |
| 72 | return SkSign32(fStart - fEnd); |
| 73 | } |
| 74 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 75 | bool small() const; |
| 76 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 77 | int start() const { |
| 78 | return fStart; |
| 79 | } |
| 80 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 81 | bool unorderable() const { |
| 82 | return fUnorderable; |
| 83 | } |
| 84 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 85 | // available to testing only |
| 86 | #if DEBUG_SORT |
| 87 | void debugLoop() const; // called by code during run |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 88 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 89 | #if DEBUG_ANGLE |
| 90 | void debugSameAs(const SkOpAngle* compare) const; |
| 91 | #endif |
| 92 | void dump() const; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 93 | void dumpLoop() const; |
| 94 | void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 95 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 96 | #if DEBUG_ANGLE |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 97 | int debugID() const { return fID; } |
| 98 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 99 | void setID(int id) { |
| 100 | fID = id; |
| 101 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 102 | #else |
| 103 | int debugID() const { return 0; } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 104 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 105 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 106 | #if DEBUG_VALIDATE |
| 107 | void debugValidateLoop() const; |
| 108 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 109 | |
| 110 | private: |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 111 | bool after(const SkOpAngle* test) const; |
| 112 | int allOnOneSide(const SkOpAngle& test) const; |
| 113 | bool calcSlop(double x, double y, double rx, double ry, bool* result) const; |
| 114 | bool checkCrossesZero() const; |
| 115 | bool checkParallel(const SkOpAngle& ) const; |
| 116 | bool computeSector(); |
| 117 | int convexHullOverlaps(const SkOpAngle& ) const; |
| 118 | double distEndRatio(double dist) const; |
| 119 | int findSector(SkPath::Verb verb, double x, double y) const; |
| 120 | bool endsIntersect(const SkOpAngle& ) const; |
| 121 | double midT() const; |
| 122 | bool oppositePlanes(const SkOpAngle& rh) const; |
| 123 | bool orderable(const SkOpAngle& rh) const; // false == this < rh ; true == this > rh |
commit-bot@chromium.org | 8cb1daa | 2014-04-25 12:59:11 +0000 | [diff] [blame] | 124 | bool overlap(const SkOpAngle& test) const; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 125 | void setCurveHullSweep(); |
| 126 | void setSector(); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 127 | void setSpans(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 128 | bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 129 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 130 | SkDCubic fCurvePart; // the curve from start to end |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 131 | double fSide; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 132 | SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 133 | const SkOpSegment* fSegment; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 134 | SkOpAngle* fNext; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 135 | SkOpSpan* fLastMarked; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 136 | SkDVector fSweep[2]; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 137 | int fStart; |
| 138 | int fEnd; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 139 | int fComputedEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 140 | int fSectorMask; |
commit-bot@chromium.org | 8608463 | 2014-04-14 18:33:03 +0000 | [diff] [blame] | 141 | int8_t fSectorStart; // in 32nds of a circle |
| 142 | int8_t fSectorEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 143 | bool fIsCurve; |
| 144 | bool fStop; // set if ordered angle is greater than the previous |
| 145 | mutable bool fUnorderable; // this is editable by orderable() |
| 146 | bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors |
| 147 | bool fComputeSector; |
| 148 | bool fComputedSector; |
| 149 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 150 | #if DEBUG_ANGLE |
| 151 | int fID; |
| 152 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 153 | #if DEBUG_VALIDATE |
| 154 | void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted |
| 155 | #else |
| 156 | void debugValidateNext() const {} |
| 157 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 158 | void dumpOne(bool showFunc) const; // available to testing only |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 159 | void dumpPartials() const; // utility to be called by user from debugger |
| 160 | friend class PathOpsAngleTester; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 163 | class SkOpAngleSet { |
| 164 | public: |
| 165 | SkOpAngleSet(); |
| 166 | ~SkOpAngleSet(); |
| 167 | SkOpAngle& push_back(); |
| 168 | void reset(); |
| 169 | private: |
| 170 | void dump() const; // utility to be called by user from debugger |
caryclark | 5e27e0e | 2014-08-12 07:46:33 -0700 | [diff] [blame] | 171 | SkChunkAlloc* fAngles; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 172 | #if DEBUG_ANGLE |
| 173 | int fCount; |
| 174 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 177 | #endif |