Coverage Report

Created: 2021-08-22 09:07

/src/skia/include/core/SkPoint3.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2015 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 SkPoint3_DEFINED
9
#define SkPoint3_DEFINED
10
11
#include "include/core/SkPoint.h"
12
13
struct SK_API SkPoint3 {
14
    SkScalar fX, fY, fZ;
15
16
19.1M
    static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z) {
17
19.1M
        SkPoint3 pt;
18
19.1M
        pt.set(x, y, z);
19
19.1M
        return pt;
20
19.1M
    }
21
22
9.12M
    SkScalar x() const { return fX; }
23
18.2M
    SkScalar y() const { return fY; }
24
18.2M
    SkScalar z() const { return fZ; }
25
26
869M
    void set(SkScalar x, SkScalar y, SkScalar z) { fX = x; fY = y; fZ = z; }
27
28
1.47k
    friend bool operator==(const SkPoint3& a, const SkPoint3& b) {
29
1.47k
        return a.fX == b.fX && a.fY == b.fY && a.fZ == b.fZ;
30
1.47k
    }
31
32
0
    friend bool operator!=(const SkPoint3& a, const SkPoint3& b) {
33
0
        return !(a == b);
34
0
    }
35
36
    /** Returns the Euclidian distance from (0,0,0) to (x,y,z)
37
    */
38
    static SkScalar Length(SkScalar x, SkScalar y, SkScalar z);
39
40
    /** Return the Euclidian distance from (0,0,0) to the point
41
    */
42
0
    SkScalar length() const { return SkPoint3::Length(fX, fY, fZ); }
43
44
    /** Set the point (vector) to be unit-length in the same direction as it
45
        already points.  If the point has a degenerate length (i.e., nearly 0)
46
        then set it to (0,0,0) and return false; otherwise return true.
47
    */
48
    bool normalize();
49
50
    /** Return a new point whose X, Y and Z coordinates are scaled.
51
    */
52
19.1M
    SkPoint3 makeScale(SkScalar scale) const {
53
19.1M
        SkPoint3 p;
54
19.1M
        p.set(scale * fX, scale * fY, scale * fZ);
55
19.1M
        return p;
56
19.1M
    }
57
58
    /** Scale the point's coordinates by scale.
59
    */
60
0
    void scale(SkScalar value) {
61
0
        fX *= value;
62
0
        fY *= value;
63
0
        fZ *= value;
64
0
    }
65
66
    /** Return a new point whose X, Y and Z coordinates are the negative of the
67
        original point's
68
    */
69
0
    SkPoint3 operator-() const {
70
0
        SkPoint3 neg;
71
0
        neg.fX = -fX;
72
0
        neg.fY = -fY;
73
0
        neg.fZ = -fZ;
74
0
        return neg;
75
0
    }
76
77
    /** Returns a new point whose coordinates are the difference between
78
        a and b (i.e., a - b)
79
    */
80
11.7k
    friend SkPoint3 operator-(const SkPoint3& a, const SkPoint3& b) {
81
11.7k
        return { a.fX - b.fX, a.fY - b.fY, a.fZ - b.fZ };
82
11.7k
    }
83
84
    /** Returns a new point whose coordinates are the sum of a and b (a + b)
85
    */
86
5.74k
    friend SkPoint3 operator+(const SkPoint3& a, const SkPoint3& b) {
87
5.74k
        return { a.fX + b.fX, a.fY + b.fY, a.fZ + b.fZ };
88
5.74k
    }
89
90
    /** Add v's coordinates to the point's
91
    */
92
0
    void operator+=(const SkPoint3& v) {
93
0
        fX += v.fX;
94
0
        fY += v.fY;
95
0
        fZ += v.fZ;
96
0
    }
97
98
    /** Subtract v's coordinates from the point's
99
    */
100
0
    void operator-=(const SkPoint3& v) {
101
0
        fX -= v.fX;
102
0
        fY -= v.fY;
103
0
        fZ -= v.fZ;
104
0
    }
105
106
5.74k
    friend SkPoint3 operator*(SkScalar t, SkPoint3 p) {
107
5.74k
        return { t * p.fX, t * p.fY, t * p.fZ };
108
5.74k
    }
109
110
    /** Returns true if fX, fY, and fZ are measurable values.
111
112
     @return  true for values other than infinities and NaN
113
     */
114
0
    bool isFinite() const {
115
0
        SkScalar accum = 0;
116
0
        accum *= fX;
117
0
        accum *= fY;
118
0
        accum *= fZ;
119
120
        // accum is either NaN or it is finite (zero).
121
0
        SkASSERT(0 == accum || SkScalarIsNaN(accum));
122
123
        // value==value will be true iff value is not NaN
124
        // TODO: is it faster to say !accum or accum==accum?
125
0
        return !SkScalarIsNaN(accum);
126
0
    }
Unexecuted instantiation: SkPoint3::isFinite() const
Unexecuted instantiation: SkPoint3::isFinite() const
127
128
    /** Returns the dot product of a and b, treating them as 3D vectors
129
    */
130
47.4M
    static SkScalar DotProduct(const SkPoint3& a, const SkPoint3& b) {
131
47.4M
        return a.fX * b.fX + a.fY * b.fY + a.fZ * b.fZ;
132
47.4M
    }
133
134
47.4M
    SkScalar dot(const SkPoint3& vec) const {
135
47.4M
        return DotProduct(*this, vec);
136
47.4M
    }
137
138
    /** Returns the cross product of a and b, treating them as 3D vectors
139
    */
140
0
    static SkPoint3 CrossProduct(const SkPoint3& a, const SkPoint3& b) {
141
0
        SkPoint3 result;
142
0
        result.fX = a.fY*b.fZ - a.fZ*b.fY;
143
0
        result.fY = a.fZ*b.fX - a.fX*b.fZ;
144
0
        result.fZ = a.fX*b.fY - a.fY*b.fX;
145
146
0
        return result;
147
0
    }
148
149
0
    SkPoint3 cross(const SkPoint3& vec) const {
150
0
        return CrossProduct(*this, vec);
151
0
    }
152
};
153
154
typedef SkPoint3 SkVector3;
155
typedef SkPoint3 SkColor3f;
156
157
#endif