Coverage Report

Created: 2024-05-20 07:14

/src/skia/src/core/SkPathMakers.h
Line
Count
Source
1
/*
2
 * Copyright 2019 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
8
#ifndef SkPathMakers_DEFINED
9
#define SkPathMakers_DEFINED
10
11
#include "include/core/SkPathTypes.h"
12
#include "include/core/SkPoint.h"
13
#include "include/core/SkRRect.h"
14
15
template <unsigned N> class SkPath_PointIterator {
16
public:
17
    SkPath_PointIterator(SkPathDirection dir, unsigned startIndex)
18
    : fCurrent(startIndex % N)
19
313k
    , fAdvance(dir == SkPathDirection::kCW ? 1 : N - 1) { }
SkPath_PointIterator<4u>::SkPath_PointIterator(SkPathDirection, unsigned int)
Line
Count
Source
19
294k
    , fAdvance(dir == SkPathDirection::kCW ? 1 : N - 1) { }
SkPath_PointIterator<8u>::SkPath_PointIterator(SkPathDirection, unsigned int)
Line
Count
Source
19
19.8k
    , fAdvance(dir == SkPathDirection::kCW ? 1 : N - 1) { }
20
21
1.43M
    const SkPoint& current() const {
22
1.43M
        SkASSERT(fCurrent < N);
23
1.43M
        return fPts[fCurrent];
24
1.43M
    }
SkPath_PointIterator<4u>::current() const
Line
Count
Source
21
1.26M
    const SkPoint& current() const {
22
1.26M
        SkASSERT(fCurrent < N);
23
1.26M
        return fPts[fCurrent];
24
1.26M
    }
SkPath_PointIterator<8u>::current() const
Line
Count
Source
21
177k
    const SkPoint& current() const {
22
177k
        SkASSERT(fCurrent < N);
23
177k
        return fPts[fCurrent];
24
177k
    }
25
26
1.23M
    const SkPoint& next() {
27
1.23M
        fCurrent = (fCurrent + fAdvance) % N;
28
1.23M
        return this->current();
29
1.23M
    }
SkPath_PointIterator<4u>::next()
Line
Count
Source
26
1.07M
    const SkPoint& next() {
27
1.07M
        fCurrent = (fCurrent + fAdvance) % N;
28
1.07M
        return this->current();
29
1.07M
    }
SkPath_PointIterator<8u>::next()
Line
Count
Source
26
157k
    const SkPoint& next() {
27
157k
        fCurrent = (fCurrent + fAdvance) % N;
28
157k
        return this->current();
29
157k
    }
30
31
    protected:
32
    SkPoint fPts[N];
33
34
    private:
35
    unsigned fCurrent;
36
    unsigned fAdvance;
37
};
38
39
class SkPath_RectPointIterator : public SkPath_PointIterator<4> {
40
public:
41
    SkPath_RectPointIterator(const SkRect& rect, SkPathDirection dir, unsigned startIndex)
42
208k
        : SkPath_PointIterator(dir, startIndex) {
43
44
208k
        fPts[0] = SkPoint::Make(rect.fLeft, rect.fTop);
45
208k
        fPts[1] = SkPoint::Make(rect.fRight, rect.fTop);
46
208k
        fPts[2] = SkPoint::Make(rect.fRight, rect.fBottom);
47
208k
        fPts[3] = SkPoint::Make(rect.fLeft, rect.fBottom);
48
208k
    }
49
};
50
51
class SkPath_OvalPointIterator : public SkPath_PointIterator<4> {
52
public:
53
    SkPath_OvalPointIterator(const SkRect& oval, SkPathDirection dir, unsigned startIndex)
54
85.3k
        : SkPath_PointIterator(dir, startIndex) {
55
56
85.3k
        const SkScalar cx = oval.centerX();
57
85.3k
        const SkScalar cy = oval.centerY();
58
59
85.3k
        fPts[0] = SkPoint::Make(cx, oval.fTop);
60
85.3k
        fPts[1] = SkPoint::Make(oval.fRight, cy);
61
85.3k
        fPts[2] = SkPoint::Make(cx, oval.fBottom);
62
85.3k
        fPts[3] = SkPoint::Make(oval.fLeft, cy);
63
85.3k
    }
64
};
65
66
class SkPath_RRectPointIterator : public SkPath_PointIterator<8> {
67
public:
68
    SkPath_RRectPointIterator(const SkRRect& rrect, SkPathDirection dir, unsigned startIndex)
69
19.8k
        : SkPath_PointIterator(dir, startIndex) {
70
71
19.8k
        const SkRect& bounds = rrect.getBounds();
72
19.8k
        const SkScalar L = bounds.fLeft;
73
19.8k
        const SkScalar T = bounds.fTop;
74
19.8k
        const SkScalar R = bounds.fRight;
75
19.8k
        const SkScalar B = bounds.fBottom;
76
77
19.8k
        fPts[0] = SkPoint::Make(L + rrect.radii(SkRRect::kUpperLeft_Corner).fX, T);
78
19.8k
        fPts[1] = SkPoint::Make(R - rrect.radii(SkRRect::kUpperRight_Corner).fX, T);
79
19.8k
        fPts[2] = SkPoint::Make(R, T + rrect.radii(SkRRect::kUpperRight_Corner).fY);
80
19.8k
        fPts[3] = SkPoint::Make(R, B - rrect.radii(SkRRect::kLowerRight_Corner).fY);
81
19.8k
        fPts[4] = SkPoint::Make(R - rrect.radii(SkRRect::kLowerRight_Corner).fX, B);
82
19.8k
        fPts[5] = SkPoint::Make(L + rrect.radii(SkRRect::kLowerLeft_Corner).fX, B);
83
19.8k
        fPts[6] = SkPoint::Make(L, B - rrect.radii(SkRRect::kLowerLeft_Corner).fY);
84
19.8k
        fPts[7] = SkPoint::Make(L, T + rrect.radii(SkRRect::kUpperLeft_Corner).fY);
85
19.8k
    }
86
};
87
88
#endif