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@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 53 | void set(const SkOpSegment* segment, int start, int end); |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 54 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 55 | void setLastMarked(SkOpSpan* marked) { |
| 56 | fLastMarked = marked; |
| 57 | } |
| 58 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 59 | SkOpSegment* segment() const { |
| 60 | return const_cast<SkOpSegment*>(fSegment); |
| 61 | } |
| 62 | |
| 63 | int sign() const { |
| 64 | return SkSign32(fStart - fEnd); |
| 65 | } |
| 66 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 67 | bool small() const; |
| 68 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 69 | int start() const { |
| 70 | return fStart; |
| 71 | } |
| 72 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 73 | bool unorderable() const { |
| 74 | return fUnorderable; |
| 75 | } |
| 76 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 77 | // available to testing only |
| 78 | #if DEBUG_SORT |
| 79 | void debugLoop() const; // called by code during run |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 80 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 81 | #if DEBUG_ANGLE |
| 82 | void debugSameAs(const SkOpAngle* compare) const; |
| 83 | #endif |
| 84 | void dump() const; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 85 | void dumpLoop() const; |
| 86 | void dumpTo(const SkOpSegment* fromSeg, const SkOpAngle* ) const; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 87 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 88 | #if DEBUG_ANGLE |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 89 | int debugID() const { return fID; } |
| 90 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 91 | void setID(int id) { |
| 92 | fID = id; |
| 93 | } |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 94 | #else |
| 95 | int debugID() const { return 0; } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 96 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 97 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 98 | #if DEBUG_VALIDATE |
| 99 | void debugValidateLoop() const; |
| 100 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 101 | |
| 102 | private: |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 103 | bool after(const SkOpAngle* test) const; |
| 104 | int allOnOneSide(const SkOpAngle& test) const; |
| 105 | bool calcSlop(double x, double y, double rx, double ry, bool* result) const; |
| 106 | bool checkCrossesZero() const; |
| 107 | bool checkParallel(const SkOpAngle& ) const; |
| 108 | bool computeSector(); |
| 109 | int convexHullOverlaps(const SkOpAngle& ) const; |
| 110 | double distEndRatio(double dist) const; |
| 111 | int findSector(SkPath::Verb verb, double x, double y) const; |
| 112 | bool endsIntersect(const SkOpAngle& ) const; |
| 113 | double midT() const; |
| 114 | bool oppositePlanes(const SkOpAngle& rh) const; |
| 115 | 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] | 116 | bool overlap(const SkOpAngle& test) const; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 117 | void setCurveHullSweep(); |
| 118 | void setSector(); |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 119 | void setSpans(); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 120 | bool tangentsDiverge(const SkOpAngle& rh, double s0xt0) const; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 121 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 122 | SkDCubic fCurvePart; // the curve from start to end |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 123 | double fSide; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 124 | 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] | 125 | const SkOpSegment* fSegment; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 126 | SkOpAngle* fNext; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 127 | SkOpSpan* fLastMarked; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 128 | SkDVector fSweep[2]; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 129 | int fStart; |
| 130 | int fEnd; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 131 | int fComputedEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 132 | int fSectorMask; |
commit-bot@chromium.org | 8608463 | 2014-04-14 18:33:03 +0000 | [diff] [blame] | 133 | int8_t fSectorStart; // in 32nds of a circle |
| 134 | int8_t fSectorEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 135 | bool fIsCurve; |
| 136 | bool fStop; // set if ordered angle is greater than the previous |
| 137 | mutable bool fUnorderable; // this is editable by orderable() |
| 138 | bool fUnorderedSweep; // set when a cubic's first control point between the sweep vectors |
| 139 | bool fComputeSector; |
| 140 | bool fComputedSector; |
| 141 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 142 | #if DEBUG_ANGLE |
| 143 | int fID; |
| 144 | #endif |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 145 | #if DEBUG_VALIDATE |
| 146 | void debugValidateNext() const; // in debug builds, verify that angle loop is uncorrupted |
| 147 | #else |
| 148 | void debugValidateNext() const {} |
| 149 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 150 | void dumpOne(bool showFunc) const; // available to testing only |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 151 | void dumpPartials() const; // utility to be called by user from debugger |
| 152 | friend class PathOpsAngleTester; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 153 | }; |
| 154 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 155 | class SkOpAngleSet { |
| 156 | public: |
| 157 | SkOpAngleSet(); |
| 158 | ~SkOpAngleSet(); |
| 159 | SkOpAngle& push_back(); |
| 160 | void reset(); |
| 161 | private: |
| 162 | void dump() const; // utility to be called by user from debugger |
caryclark | 5e27e0e | 2014-08-12 07:46:33 -0700 | [diff] [blame^] | 163 | SkChunkAlloc* fAngles; |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 164 | #if DEBUG_ANGLE |
| 165 | int fCount; |
| 166 | #endif |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 169 | #endif |