| 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 | 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 |
| 21 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 22 | bool operator<(const SkOpAngle& rh) const; |
| caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 23 | |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 24 | bool calcSlop(double x, double y, double rx, double ry, bool* result) const; |
| 25 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 26 | double dx() const { |
| 27 | return fTangent1.dx(); |
| 28 | } |
| 29 | |
| 30 | double dy() const { |
| 31 | return fTangent1.dy(); |
| 32 | } |
| 33 | |
| 34 | int end() const { |
| 35 | return fEnd; |
| 36 | } |
| 37 | |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 38 | bool isHorizontal() const; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 39 | |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 40 | void set(const SkOpSegment* segment, int start, int end); |
| caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 41 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 42 | SkOpSegment* segment() const { |
| 43 | return const_cast<SkOpSegment*>(fSegment); |
| 44 | } |
| 45 | |
| 46 | int sign() const { |
| 47 | return SkSign32(fStart - fEnd); |
| 48 | } |
| 49 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 50 | int start() const { |
| 51 | return fStart; |
| 52 | } |
| 53 | |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 54 | bool unorderable() const { |
| 55 | return fUnorderable; |
| 56 | } |
| 57 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 58 | bool unsortable() const { |
| 59 | return fUnsortable; |
| 60 | } |
| 61 | |
| 62 | #if DEBUG_ANGLE |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 63 | void debugShow(const SkPoint& a) const { |
| 64 | SkDebugf(" d=(%1.9g,%1.9g) side=%1.9g\n", dx(), dy(), fSide); |
| 65 | } |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 66 | |
| 67 | void setID(int id) { |
| 68 | fID = id; |
| 69 | } |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | private: |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 73 | bool lengthen(const SkOpAngle& ); |
| 74 | void setSpans(); |
| 75 | |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 76 | SkDCubic fCurvePart; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 77 | double fSide; |
| 78 | SkLineParameters fTangent1; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 79 | const SkOpSegment* fSegment; |
| 80 | int fStart; |
| 81 | int fEnd; |
| caryclark@google.com | cffbcc3 | 2013-06-04 17:59:42 +0000 | [diff] [blame] | 82 | bool fComputed; // tangent is computed, may contain some error |
| 83 | // if subdividing a quad or cubic causes the tangent to go from the maximum angle to the |
| 84 | // minimum, mark it unorderable. It still can be sorted, which is good enough for find-top |
| 85 | // 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] | 86 | bool fUnorderable; |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 87 | 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] | 88 | #if DEBUG_ANGLE |
| 89 | int fID; |
| 90 | #endif |
| caryclark@google.com | 07393ca | 2013-04-08 11:47:37 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | #endif |