aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pathops/SkIntersectionHelper.h
blob: 9a8a582af64e7d2e537c5d2096ae5455adaaf8c0 (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
113
/*
 * 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 SkIntersectionHelper_DEFINED
#define SkIntersectionHelper_DEFINED

#include "SkOpContour.h"
#include "SkOpSegment.h"
#include "SkPath.h"

#ifdef SK_DEBUG
#include "SkPathOpsPoint.h"
#endif

class SkIntersectionHelper {
public:
    enum SegmentType {
        kHorizontalLine_Segment = -1,
        kVerticalLine_Segment = 0,
        kLine_Segment = SkPath::kLine_Verb,
        kQuad_Segment = SkPath::kQuad_Verb,
        kConic_Segment = SkPath::kConic_Verb,
        kCubic_Segment = SkPath::kCubic_Verb,
    };

    bool advance() {
        fSegment = fSegment->next();
        return fSegment != nullptr;
    }

    SkScalar bottom() const {
        return bounds().fBottom;
    }

    const SkPathOpsBounds& bounds() const {
        return fSegment->bounds();
    }

    SkOpContour* contour() const {
        return fSegment->contour();
    }

    void init(SkOpContour* contour) {
        fSegment = contour->first();
    }

    SkScalar left() const {
        return bounds().fLeft;
    }

    const SkPoint* pts() const {
        return fSegment->pts();
    }

    SkScalar right() const {
        return bounds().fRight;
    }

    SkOpSegment* segment() const {
        return fSegment;
    }

    SegmentType segmentType() const {
        SegmentType type = (SegmentType) fSegment->verb();
        if (type != kLine_Segment) {
            return type;
        }
        if (fSegment->isHorizontal()) {
            return kHorizontalLine_Segment;
        }
        if (fSegment->isVertical()) {
            return kVerticalLine_Segment;
        }
        return kLine_Segment;
    }

    bool startAfter(const SkIntersectionHelper& after) {
        fSegment = after.fSegment->next();
        return fSegment != nullptr;
    }

    SkScalar top() const {
        return bounds().fTop;
    }

    SkScalar weight() const {
        return fSegment->weight();
    }

    SkScalar x() const {
        return bounds().fLeft;
    }

    bool xFlipped() const {
        return x() != pts()[0].fX;
    }

    SkScalar y() const {
        return bounds().fTop;
    }

    bool yFlipped() const {
        return y() != pts()[0].fY;
    }

private:
    SkOpSegment* fSegment;
};

#endif