blob: 583f5ec8b39df3bbb47e8411b054d2209b796e17 [file] [log] [blame]
caryclark@google.com07393ca2013-04-08 11:47:37 +00001/*
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.com07393ca2013-04-08 11:47:37 +000011#include "SkPath.h"
12#include "SkPathOpsCubic.h"
caryclark@google.comcffbcc32013-06-04 17:59:42 +000013
14class SkOpSegment;
caryclark@google.com570863f2013-09-16 15:55:01 +000015struct SkOpSpan;
caryclark@google.com07393ca2013-04-08 11:47:37 +000016
17// sorting angles
18// given angles of {dx dy ddx ddy dddx dddy} sort them
19class SkOpAngle {
20public:
caryclark@google.comd892bd82013-06-17 14:10:36 +000021 enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
caryclark@google.com570863f2013-09-16 15:55:01 +000022 enum IncludeType {
23 kUnaryWinding,
24 kUnaryXor,
25 kBinarySingle,
26 kBinaryOpp,
27 };
caryclark@google.comd892bd82013-06-17 14:10:36 +000028
caryclark@google.com07393ca2013-04-08 11:47:37 +000029 bool operator<(const SkOpAngle& rh) const;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000030
caryclark@google.comcffbcc32013-06-04 17:59:42 +000031 bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
32
caryclark@google.com07393ca2013-04-08 11:47:37 +000033 double dx() const {
caryclark@google.com570863f2013-09-16 15:55:01 +000034 return fTangentPart.dx();
caryclark@google.com07393ca2013-04-08 11:47:37 +000035 }
36
37 double dy() const {
caryclark@google.com570863f2013-09-16 15:55:01 +000038 return fTangentPart.dy();
caryclark@google.com07393ca2013-04-08 11:47:37 +000039 }
40
41 int end() const {
42 return fEnd;
43 }
44
caryclark@google.comcffbcc32013-06-04 17:59:42 +000045 bool isHorizontal() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000046
caryclark@google.com570863f2013-09-16 15:55:01 +000047 SkOpSpan* lastMarked() const {
48 return fLastMarked;
49 }
50
caryclark@google.comcffbcc32013-06-04 17:59:42 +000051 void set(const SkOpSegment* segment, int start, int end);
caryclark@google.comad65a3e2013-04-15 19:13:59 +000052
caryclark@google.com570863f2013-09-16 15:55:01 +000053 void setLastMarked(SkOpSpan* marked) {
54 fLastMarked = marked;
55 }
56
caryclark@google.com07393ca2013-04-08 11:47:37 +000057 SkOpSegment* segment() const {
58 return const_cast<SkOpSegment*>(fSegment);
59 }
60
61 int sign() const {
62 return SkSign32(fStart - fEnd);
63 }
64
caryclark@google.com07393ca2013-04-08 11:47:37 +000065 int start() const {
66 return fStart;
67 }
68
caryclark@google.comcffbcc32013-06-04 17:59:42 +000069 bool unorderable() const {
70 return fUnorderable;
71 }
72
caryclark@google.com07393ca2013-04-08 11:47:37 +000073 bool unsortable() const {
74 return fUnsortable;
75 }
76
caryclark@google.com570863f2013-09-16 15:55:01 +000077#ifdef SK_DEBUG
78 void dump() const;
79#endif
caryclark@google.comcffbcc32013-06-04 17:59:42 +000080
caryclark@google.com570863f2013-09-16 15:55:01 +000081#if DEBUG_ANGLE
caryclark@google.comcffbcc32013-06-04 17:59:42 +000082 void setID(int id) {
83 fID = id;
84 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000085#endif
86
87private:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000088 bool lengthen(const SkOpAngle& );
89 void setSpans();
90
caryclark@google.com570863f2013-09-16 15:55:01 +000091 SkDCubic fCurvePart; // the curve from start to end
92 SkDCubic fCurveHalf; // the curve from start to 1 or 0
caryclark@google.com07393ca2013-04-08 11:47:37 +000093 double fSide;
caryclark@google.com570863f2013-09-16 15:55:01 +000094 double fSide2;
95 SkLineParameters fTangentPart;
96 SkLineParameters fTangentHalf;
caryclark@google.com07393ca2013-04-08 11:47:37 +000097 const SkOpSegment* fSegment;
caryclark@google.com570863f2013-09-16 15:55:01 +000098 SkOpSpan* fLastMarked;
caryclark@google.com07393ca2013-04-08 11:47:37 +000099 int fStart;
100 int fEnd;
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000101 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.com8f6ef402013-06-05 07:01:06 +0000105 bool fUnorderable;
caryclark@google.com07393ca2013-04-08 11:47:37 +0000106 mutable bool fUnsortable; // this alone is editable by the less than operator
caryclark@google.comcffbcc32013-06-04 17:59:42 +0000107#if DEBUG_ANGLE
108 int fID;
109#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +0000110};
111
112#endif