Coverage Report

Created: 2024-05-20 07:14

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