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