blob: e7e5e1f597e1ddd77ba2b1f7f805188c9d87dd67 [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.com07393ca2013-04-08 11:47:37 +000015
16// sorting angles
17// given angles of {dx dy ddx ddy dddx dddy} sort them
18class SkOpAngle {
19public:
caryclark@google.comd892bd82013-06-17 14:10:36 +000020 enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
21
caryclark@google.com07393ca2013-04-08 11:47:37 +000022 bool operator<(const SkOpAngle& rh) const;
caryclark@google.comad65a3e2013-04-15 19:13:59 +000023
caryclark@google.comcffbcc32013-06-04 17:59:42 +000024 bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
25
caryclark@google.com07393ca2013-04-08 11:47:37 +000026 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.comcffbcc32013-06-04 17:59:42 +000038 bool isHorizontal() const;
caryclark@google.com07393ca2013-04-08 11:47:37 +000039
caryclark@google.comcffbcc32013-06-04 17:59:42 +000040 void set(const SkOpSegment* segment, int start, int end);
caryclark@google.comad65a3e2013-04-15 19:13:59 +000041
caryclark@google.com07393ca2013-04-08 11:47:37 +000042 SkOpSegment* segment() const {
43 return const_cast<SkOpSegment*>(fSegment);
44 }
45
46 int sign() const {
47 return SkSign32(fStart - fEnd);
48 }
49
caryclark@google.com07393ca2013-04-08 11:47:37 +000050 int start() const {
51 return fStart;
52 }
53
caryclark@google.comcffbcc32013-06-04 17:59:42 +000054 bool unorderable() const {
55 return fUnorderable;
56 }
57
caryclark@google.com07393ca2013-04-08 11:47:37 +000058 bool unsortable() const {
59 return fUnsortable;
60 }
61
62#if DEBUG_ANGLE
caryclark@google.com07393ca2013-04-08 11:47:37 +000063 void debugShow(const SkPoint& a) const {
64 SkDebugf(" d=(%1.9g,%1.9g) side=%1.9g\n", dx(), dy(), fSide);
65 }
caryclark@google.comcffbcc32013-06-04 17:59:42 +000066
67 void setID(int id) {
68 fID = id;
69 }
caryclark@google.com07393ca2013-04-08 11:47:37 +000070#endif
71
72private:
caryclark@google.comcffbcc32013-06-04 17:59:42 +000073 bool lengthen(const SkOpAngle& );
74 void setSpans();
75
caryclark@google.com07393ca2013-04-08 11:47:37 +000076 SkDCubic fCurvePart;
caryclark@google.com07393ca2013-04-08 11:47:37 +000077 double fSide;
78 SkLineParameters fTangent1;
caryclark@google.com07393ca2013-04-08 11:47:37 +000079 const SkOpSegment* fSegment;
80 int fStart;
81 int fEnd;
caryclark@google.comcffbcc32013-06-04 17:59:42 +000082 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.com8f6ef402013-06-05 07:01:06 +000086 bool fUnorderable;
caryclark@google.com07393ca2013-04-08 11:47:37 +000087 mutable bool fUnsortable; // this alone is editable by the less than operator
caryclark@google.comcffbcc32013-06-04 17:59:42 +000088#if DEBUG_ANGLE
89 int fID;
90#endif
caryclark@google.com07393ca2013-04-08 11:47:37 +000091};
92
93#endif