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@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
| 12 | #include "SkPathOpsCubic.h" |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 13 | |
| 14 | class SkOpSegment; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 15 | struct SkOpSpan; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 16 | |
| 17 | // sorting angles |
| 18 | // given angles of {dx dy ddx ddy dddx dddy} sort them |
| 19 | class SkOpAngle { |
| 20 | public: |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 21 | enum { kStackBasedCount = 8 }; // FIXME: determine what this should be |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 22 | enum IncludeType { |
| 23 | kUnaryWinding, |
| 24 | kUnaryXor, |
| 25 | kBinarySingle, |
| 26 | kBinaryOpp, |
| 27 | }; |
caryclark@google.com | d892bd8 | 2013-06-17 14:10:36 +0000 | [diff] [blame] | 28 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 29 | bool operator<(const SkOpAngle& rh) const; |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 30 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 31 | bool calcSlop(double x, double y, double rx, double ry, bool* result) const; |
| 32 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 33 | double dx() const { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 34 | return fTangentPart.dx(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | double dy() const { |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 38 | return fTangentPart.dy(); |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | int end() const { |
| 42 | return fEnd; |
| 43 | } |
| 44 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 45 | bool isHorizontal() const; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 46 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 47 | SkOpSpan* lastMarked() const { |
| 48 | return fLastMarked; |
| 49 | } |
| 50 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 51 | void set(const SkOpSegment* segment, int start, int end); |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 52 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 53 | void setLastMarked(SkOpSpan* marked) { |
| 54 | fLastMarked = marked; |
| 55 | } |
| 56 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 57 | SkOpSegment* segment() const { |
| 58 | return const_cast<SkOpSegment*>(fSegment); |
| 59 | } |
| 60 | |
| 61 | int sign() const { |
| 62 | return SkSign32(fStart - fEnd); |
| 63 | } |
| 64 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 65 | int start() const { |
| 66 | return fStart; |
| 67 | } |
| 68 | |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 69 | bool unorderable() const { |
| 70 | return fUnorderable; |
| 71 | } |
| 72 | |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 73 | bool unsortable() const { |
| 74 | return fUnsortable; |
| 75 | } |
| 76 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 77 | #ifdef SK_DEBUG |
| 78 | void dump() const; |
| 79 | #endif |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 80 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 81 | #if DEBUG_ANGLE |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 82 | void setID(int id) { |
| 83 | fID = id; |
| 84 | } |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 85 | #endif |
| 86 | |
| 87 | private: |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 88 | bool lengthen(const SkOpAngle& ); |
| 89 | void setSpans(); |
| 90 | |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 91 | SkDCubic fCurvePart; // the curve from start to end |
| 92 | SkDCubic fCurveHalf; // the curve from start to 1 or 0 |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 93 | double fSide; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 94 | double fSide2; |
| 95 | SkLineParameters fTangentPart; |
| 96 | SkLineParameters fTangentHalf; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 97 | const SkOpSegment* fSegment; |
caryclark@google.com | 570863f | 2013-09-16 15:55:01 +0000 | [diff] [blame] | 98 | SkOpSpan* fLastMarked; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 99 | int fStart; |
| 100 | int fEnd; |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 101 | bool fComputed; // tangent is computed, may contain some error |
| 102 | // if subdividing a quad or cubic causes the tangent to go from the maximum angle to the |
| 103 | // minimum, mark it unorderable. It still can be sorted, which is good enough for find-top |
| 104 | // but can't be ordered, and therefore can't be used to compute winding |
skia.committer@gmail.com | 8f6ef40 | 2013-06-05 07:01:06 +0000 | [diff] [blame] | 105 | bool fUnorderable; |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 106 | mutable bool fUnsortable; // this alone is editable by the less than operator |
caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 107 | #if DEBUG_ANGLE |
| 108 | int fID; |
| 109 | #endif |
caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | #endif |