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"
11#include "SkPath.h"
12#include "SkPathOpsCubic.h"
13
14class SkOpSegment;
15
16// sorting angles
17// given angles of {dx dy ddx ddy dddx dddy} sort them
18class SkOpAngle {
19public:
20    enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
21
22    bool operator<(const SkOpAngle& rh) const;
23
24    bool calcSlop(double x, double y, double rx, double ry, bool* result) const;
25
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
38    bool isHorizontal() const;
39
40    void set(const SkOpSegment* segment, int start, int end);
41
42    SkOpSegment* segment() const {
43        return const_cast<SkOpSegment*>(fSegment);
44    }
45
46    int sign() const {
47        return SkSign32(fStart - fEnd);
48    }
49
50    int start() const {
51        return fStart;
52    }
53
54    bool unorderable() const {
55        return fUnorderable;
56    }
57
58    bool unsortable() const {
59        return fUnsortable;
60    }
61
62#if DEBUG_ANGLE
63    void debugShow(const SkPoint& a) const {
64        SkDebugf("    d=(%1.9g,%1.9g) side=%1.9g\n", dx(), dy(), fSide);
65    }
66
67    void setID(int id) {
68        fID = id;
69    }
70#endif
71
72private:
73    bool lengthen(const SkOpAngle& );
74    void setSpans();
75
76    SkDCubic fCurvePart;
77    double fSide;
78    SkLineParameters fTangent1;
79    const SkOpSegment* fSegment;
80    int fStart;
81    int fEnd;
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
86    bool fUnorderable;
87    mutable bool fUnsortable;  // this alone is editable by the less than operator
88#if DEBUG_ANGLE
89    int fID;
90#endif
91};
92
93#endif
94