aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkOpAngle.h
blob: 583f5ec8b39df3bbb47e8411b054d2209b796e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
 * Copyright 2012 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */
#ifndef SkOpAngle_DEFINED
#define SkOpAngle_DEFINED

#include "SkLineParameters.h"
#include "SkPath.h"
#include "SkPathOpsCubic.h"

class SkOpSegment;
struct SkOpSpan;

// sorting angles
// given angles of {dx dy ddx ddy dddx dddy} sort them
class SkOpAngle {
public:
    enum { kStackBasedCount = 8 }; // FIXME: determine what this should be
    enum IncludeType {
        kUnaryWinding,
        kUnaryXor,
        kBinarySingle,
        kBinaryOpp,
    };

    bool operator<(const SkOpAngle& rh) const;

    bool calcSlop(double x, double y, double rx, double ry, bool* result) const;

    double dx() const {
        return fTangentPart.dx();
    }

    double dy() const {
        return fTangentPart.dy();
    }

    int end() const {
        return fEnd;
    }

    bool isHorizontal() const;

    SkOpSpan* lastMarked() const {
        return fLastMarked;
    }

    void set(const SkOpSegment* segment, int start, int end);

    void setLastMarked(SkOpSpan* marked) {
        fLastMarked = marked;
    }

    SkOpSegment* segment() const {
        return const_cast<SkOpSegment*>(fSegment);
    }

    int sign() const {
        return SkSign32(fStart - fEnd);
    }

    int start() const {
        return fStart;
    }

    bool unorderable() const {
        return fUnorderable;
    }

    bool unsortable() const {
        return fUnsortable;
    }

#ifdef SK_DEBUG
    void dump() const;
#endif

#if DEBUG_ANGLE
    void setID(int id) {
        fID = id;
    }
#endif

private:
    bool lengthen(const SkOpAngle& );
    void setSpans();

    SkDCubic fCurvePart; // the curve from start to end
    SkDCubic fCurveHalf; // the curve from start to 1 or 0
    double fSide;
    double fSide2;
    SkLineParameters fTangentPart;
    SkLineParameters fTangentHalf;
    const SkOpSegment* fSegment;
    SkOpSpan* fLastMarked;
    int fStart;
    int fEnd;
    bool fComputed; // tangent is computed, may contain some error
    // if subdividing a quad or cubic causes the tangent to go from the maximum angle to the
    // minimum, mark it unorderable. It still can be sorted, which is good enough for find-top
    // but can't be ordered, and therefore can't be used to compute winding
    bool fUnorderable;
    mutable bool fUnsortable;  // this alone is editable by the less than operator
#if DEBUG_ANGLE
    int fID;
#endif
};

#endif