File: SkPathOps.h

package info (click to toggle)
webkit2gtk 2.51.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 455,340 kB
  • sloc: cpp: 3,865,253; javascript: 197,710; ansic: 165,177; python: 49,241; asm: 21,868; ruby: 18,095; perl: 16,926; xml: 4,623; sh: 2,409; yacc: 2,356; java: 2,019; lex: 1,330; pascal: 372; makefile: 210
file content (150 lines) | stat: -rw-r--r-- 4,707 bytes parent folder | download | duplicates (7)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
 * 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 SkPathOps_DEFINED
#define SkPathOps_DEFINED

#include "include/core/SkPath.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"

#include <optional>

struct SkRect;

// FIXME: move everything below into the SkPath class
/**
  *  The logical operations that can be performed when combining two paths.
  */
enum SkPathOp {
    kDifference_SkPathOp,         //!< subtract the op path from the first path
    kIntersect_SkPathOp,          //!< intersect the two paths
    kUnion_SkPathOp,              //!< union (inclusive-or) the two paths
    kXOR_SkPathOp,                //!< exclusive-or the two paths
    kReverseDifference_SkPathOp,  //!< subtract the first path from the op path
};

/** Set this path to the result of applying the Op to this path and the
    specified path: this = (this op operand).
    The resulting path will be constructed from non-overlapping contours.
    The curve order is reduced where possible so that cubics may be turned
    into quadratics, and quadratics maybe turned into lines.

    Returns true if operation was able to produce a result;
    otherwise, result is unmodified.

    @param one The first operand (for difference, the minuend)
    @param two The second operand (for difference, the subtrahend)
    @param op The operator to apply.
    @param result The product of the operands. The result may be one of the
                  inputs.
    @return True if the operation succeeded.
  */
std::optional<SkPath> SK_API Op(const SkPath& one, const SkPath& two, SkPathOp op);

// DEPRECATED
static inline bool Op(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result) {
    if (auto res = Op(one, two, op)) {
        *result = *res;
        return true;
    }
    return false;
}

/** Return a path with a set of non-overlapping contours that describe the
    same area as the original path.
    The curve order is reduced where possible so that cubics may
    be turned into quadratics, and quadratics maybe turned into lines.

    @param path The path to simplify.
    @return The simplified path, or {} on failure.
  */
std::optional<SkPath> SK_API Simplify(const SkPath& path);

// DEPRECATED
static inline bool Simplify(const SkPath& path, SkPath* result) {
    if (auto res = Simplify(path)) {
        *result = *res;
        return true;
    }
    return false;
}

/** Set the resulting rectangle to the tight bounds of the path.

    @param path The path measured.
    @param result The tight bounds of the path.
    @return True if the bounds could be computed.
  */
[[deprecated]]
static inline bool TightBounds(const SkPath& path, SkRect* result) {
    auto rect = path.computeTightBounds();
    if (rect.isFinite()) {
        *result = rect;
        return true;
    }
    return false;
}

/** Returns a path with fill type winding to area equivalent to the input.
    Does not detect if path contains contours which
    contain self-crossings or cross other contours; in these cases, may return
    a result even though it does not fill same area as the input.

    If it fails to compute a result, returns {}.

    @param path The path typically with fill type set to even odd.
  */
std::optional<SkPath> SK_API AsWinding(const SkPath& path);

// DEPRECATED
static inline bool AsWinding(const SkPath& path, SkPath* result) {
    if (auto res = AsWinding(path)) {
        *result = *res;
        return true;
    }
    return false;
}

/** Perform a series of path operations, optimized for unioning many paths together.
  */
class SK_API SkOpBuilder {
public:
    /** Add one or more paths and their operand. The builder is empty before the first
        path is added, so the result of a single add is (emptyPath OP path).

        @param path The second operand.
        @param _operator The operator to apply to the existing and supplied paths.
     */
    void add(const SkPath& path, SkPathOp _operator);

    /** Computes the sum of all paths and operands, and resets the builder to its
        initial state.

        @return result The product of the operands, {} on failure.
      */
    std::optional<SkPath> resolve();

    // DEPRECATED
    bool resolve(SkPath* result) {
        if (auto res = this->resolve()) {
            *result = *res;
            return true;
        }
        return false;
    }

private:
    skia_private::TArray<SkPath> fPathRefs;
    SkTDArray<SkPathOp> fOps;

    static bool FixWinding(SkPath* path);
    static void ReversePath(SkPath* path);
    void reset();
};

#endif