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 | |
| 10 | #include "SkLineParameters.h" |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 11 | #include "SkPathOpsCurve.h" |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 12 | #if DEBUG_ANGLE |
| 13 | #include "SkString.h" |
| 14 | #endif |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 15 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 16 | class SkOpContour; |
| 17 | class SkOpPtT; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 18 | class SkOpSegment; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 19 | class SkOpSpanBase; |
| 20 | class SkOpSpan; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 21 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 22 | class SkOpAngle { |
| 23 | public: |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 24 | enum IncludeType { |
| 25 | kUnaryWinding, |
| 26 | kUnaryXor, |
| 27 | kBinarySingle, |
| 28 | kBinaryOpp, |
| 29 | }; |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 30 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 31 | const SkOpAngle* debugAngle(int id) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 32 | const SkOpCoincidence* debugCoincidence() const; |
caryclark | 30b9fdd | 2016-08-31 14:36:29 -0700 | [diff] [blame] | 33 | SkOpContour* debugContour(int id) const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 34 | |
| 35 | int debugID() const { |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 36 | return SkDEBUGRELEASE(fID, -1); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 37 | } |
| 38 | |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 39 | #if DEBUG_SORT |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 40 | void debugLoop() const; |
| 41 | #endif |
| 42 | |
| 43 | #if DEBUG_ANGLE |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 44 | bool debugCheckCoincidence() const { return fCheckCoincidence; } |
caryclark | 26ad22a | 2015-10-16 09:03:38 -0700 | [diff] [blame] | 45 | void debugCheckNearCoincidence() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 46 | SkString debugPart() const; |
| 47 | #endif |
| 48 | const SkOpPtT* debugPtT(int id) const; |
| 49 | const SkOpSegment* debugSegment(int id) const; |
caryclark | 624637c | 2015-05-11 07:21:27 -0700 | [diff] [blame] | 50 | int debugSign() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 51 | const SkOpSpanBase* debugSpan(int id) const; |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 52 | void debugValidate() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 53 | 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.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 64 | return fEnd; |
| 65 | } |
| 66 | |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 67 | void insert(SkOpAngle* ); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 68 | SkOpSpanBase* lastMarked() const; |
| 69 | bool loopContains(const SkOpAngle* ) const; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 70 | int loopCount() const; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 71 | |
| 72 | SkOpAngle* next() const { |
| 73 | return fNext; |
| 74 | } |
| 75 | |
| 76 | SkOpAngle* previous() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 77 | SkOpSegment* segment() const; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 78 | void set(SkOpSpanBase* start, SkOpSpanBase* end); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 79 | |
| 80 | void setLastMarked(SkOpSpanBase* marked) { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 81 | fLastMarked = marked; |
| 82 | } |
| 83 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 84 | SkOpSpanBase* start() const { |
reed | 0dc4dd6 | 2015-03-24 13:55:33 -0700 | [diff] [blame] | 85 | return fStart; |
| 86 | } |
caryclark | ccec0f9 | 2015-03-24 07:28:17 -0700 | [diff] [blame] | 87 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 88 | SkOpSpan* starter(); |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 89 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 90 | bool unorderable() const { |
| 91 | return fUnorderable; |
| 92 | } |
| 93 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 94 | private: |
| 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 |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 110 | void setSector(); |
| 111 | void setSpans(); |
| 112 | bool tangentsDiverge(const SkOpAngle* rh, double s0xt0) const; |
| 113 | |
| 114 | SkDCurve fOriginalCurvePart; // the curve from start to end |
caryclark | eed356d | 2016-09-14 07:18:20 -0700 | [diff] [blame] | 115 | SkDCurveSweep fPart; // the curve from start to end offset as needed |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 116 | double fSide; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 117 | SkLineParameters fTangentHalf; // used only to sort a pair of lines or line-like sections |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 118 | SkOpAngle* fNext; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 119 | SkOpSpanBase* fLastMarked; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 120 | SkOpSpanBase* fStart; |
| 121 | SkOpSpanBase* fEnd; |
| 122 | SkOpSpanBase* fComputedEnd; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 123 | int fSectorMask; |
commit-bot@chromium.org | 8608463 | 2014-04-14 18:33:03 +0000 | [diff] [blame] | 124 | int8_t fSectorStart; // in 32nds of a circle |
| 125 | int8_t fSectorEnd; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 126 | bool fUnorderable; |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 127 | bool fComputeSector; |
| 128 | bool fComputedSector; |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 129 | bool fCheckCoincidence; |
caryclark | 1049f12 | 2015-04-20 08:31:59 -0700 | [diff] [blame] | 130 | SkDEBUGCODE(int fID); |
commit-bot@chromium.org | 4431e77 | 2014-04-14 17:08:59 +0000 | [diff] [blame] | 131 | |
caryclark | 55888e4 | 2016-07-18 10:01:36 -0700 | [diff] [blame] | 132 | friend class PathOpsAngleTester; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 133 | }; |
| 134 | |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 135 | |
caryclark | dac1d17 | 2014-06-17 05:15:38 -0700 | [diff] [blame] | 136 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 137 | #endif |