File: SkPathIter.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 (90 lines) | stat: -rw-r--r-- 2,447 bytes parent folder | download | duplicates (9)
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
/*
 * Copyright 2025 Google LLC.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkPathIter_DEFINED
#define SkPathIter_DEFINED

#include "include/core/SkPathTypes.h"
#include "include/core/SkPoint.h"
#include "include/core/SkSpan.h"

#include <array>
#include <cstddef>
#include <optional>

class SK_API SkPathIter {
public:
    struct Rec {
        SkSpan<const SkPoint> fPoints;
        float                 fConicWeight;
        SkPathVerb            fVerb;

        float conicWeight() const {
            SkASSERT(fVerb == SkPathVerb::kConic);
            return fConicWeight;
        }
    };

    SkPathIter(SkSpan<const SkPoint> pts, SkSpan<const SkPathVerb> vbs, SkSpan<const float> cns)
        : pIndex(0), vIndex(0), cIndex(0)
        , fPoints(pts), fVerbs(vbs), fConics(cns)
    {
        // For compat older iterators, we trim off a trailing Move.
        // SkPathData is defined to never create this pattern, so perhaps in the future
        // this check can be removed (or replaced by an assert)
        if (!vbs.empty() && vbs.back() == SkPathVerb::kMove) {
            fVerbs = vbs.first(vbs.size() - 1);
        }
    }

    /*  Holds the current verb, and its associated points
     *  move:  pts[0]
     *  line:  pts[0..1]
     *  quad:  pts[0..2]
     *  conic: pts[0..2] fConicWeight
     *  cubic: pts[0..3]
     *  close: pts[0..1] ... as if close were a line from pts[0] to pts[1]
     */
    std::optional<Rec> next();

    std::optional<SkPathVerb> peekNextVerb() const {
        if (vIndex < fVerbs.size()) {
            return fVerbs[vIndex];
        }
        return {};
    }

private:
    size_t                   pIndex, vIndex, cIndex;
    SkSpan<const SkPoint>    fPoints;
    SkSpan<const SkPathVerb> fVerbs;
    SkSpan<const float>      fConics;
    std::array<SkPoint, 2>   fClosePointStorage;
};

class SkPathContourIter {
public:
    struct Rec {
        SkSpan<const SkPoint>    fPoints;
        SkSpan<const SkPathVerb> fVerbs;
        SkSpan<const float>      fConics;
    };

    SkPathContourIter(SkSpan<const SkPoint> pts, SkSpan<const SkPathVerb> vbs,
                      SkSpan<const float> cns)
        : fPoints(pts), fVerbs(vbs), fConics(cns)
    {}

    std::optional<Rec> next();

private:
    SkSpan<const SkPoint>    fPoints;
    SkSpan<const SkPathVerb> fVerbs;
    SkSpan<const float>      fConics;
};

#endif