Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkPoint3.h
Go to the documentation of this file.
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
14
16 SkScalar fX, fY, fZ;
17
19 SkPoint3 pt;
20 pt.set(x, y, z);
21 return pt;
22 }
23
24 SkScalar x() const { return fX; }
25 SkScalar y() const { return fY; }
26 SkScalar z() const { return fZ; }
27
28 void set(SkScalar x, SkScalar y, SkScalar z) { fX = x; fY = y; fZ = z; }
29
30 friend bool operator==(const SkPoint3& a, const SkPoint3& b) {
31 return a.fX == b.fX && a.fY == b.fY && a.fZ == b.fZ;
32 }
33
34 friend bool operator!=(const SkPoint3& a, const SkPoint3& b) {
35 return !(a == b);
36 }
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 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 */
55 SkPoint3 p;
56 p.set(scale * fX, scale * fY, scale * fZ);
57 return p;
58 }
59
60 /** Scale the point's coordinates by scale.
61 */
62 void scale(SkScalar value) {
63 fX *= value;
64 fY *= value;
65 fZ *= value;
66 }
67
68 /** Return a new point whose X, Y and Z coordinates are the negative of the
69 original point's
70 */
72 SkPoint3 neg;
73 neg.fX = -fX;
74 neg.fY = -fY;
75 neg.fZ = -fZ;
76 return neg;
77 }
78
79 /** Returns a new point whose coordinates are the difference between
80 a and b (i.e., a - b)
81 */
82 friend SkPoint3 operator-(const SkPoint3& a, const SkPoint3& b) {
83 return { a.fX - b.fX, a.fY - b.fY, a.fZ - b.fZ };
84 }
85
86 /** Returns a new point whose coordinates are the sum of a and b (a + b)
87 */
88 friend SkPoint3 operator+(const SkPoint3& a, const SkPoint3& b) {
89 return { a.fX + b.fX, a.fY + b.fY, a.fZ + b.fZ };
90 }
91
92 /** Add v's coordinates to the point's
93 */
94 void operator+=(const SkPoint3& v) {
95 fX += v.fX;
96 fY += v.fY;
97 fZ += v.fZ;
98 }
99
100 /** Subtract v's coordinates from the point's
101 */
102 void operator-=(const SkPoint3& v) {
103 fX -= v.fX;
104 fY -= v.fY;
105 fZ -= v.fZ;
106 }
107
109 return { t * p.fX, t * p.fY, t * p.fZ };
110 }
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 bool isFinite() const {
117 return SkIsFinite(fX, fY, fZ);
118 }
119
120 /** Returns the dot product of a and b, treating them as 3D vectors
121 */
122 static SkScalar DotProduct(const SkPoint3& a, const SkPoint3& b) {
123 return a.fX * b.fX + a.fY * b.fY + a.fZ * b.fZ;
124 }
125
126 SkScalar dot(const SkPoint3& vec) const {
127 return DotProduct(*this, vec);
128 }
129
130 /** Returns the cross product of a and b, treating them as 3D vectors
131 */
132 static SkPoint3 CrossProduct(const SkPoint3& a, const SkPoint3& b) {
134 result.fX = a.fY*b.fZ - a.fZ*b.fY;
135 result.fY = a.fZ*b.fX - a.fX*b.fZ;
136 result.fZ = a.fX*b.fY - a.fY*b.fX;
137
138 return result;
139 }
140
141 SkPoint3 cross(const SkPoint3& vec) const {
142 return CrossProduct(*this, vec);
143 }
144};
145
148
149#endif
#define SK_API
Definition SkAPI.h:35
static bool SkIsFinite(T x, Pack... values)
static void normalize(int n, double *gauss)
SkPoint3 SkVector3
Definition SkPoint3.h:146
SkPoint3 SkColor3f
Definition SkPoint3.h:147
float SkScalar
Definition extension.cpp:12
static bool b
struct MyStruct a[10]
uint8_t value
GAsyncResult * result
double y
double x
const Scalar scale
friend SkPoint3 operator+(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:88
void operator+=(const SkPoint3 &v)
Definition SkPoint3.h:94
friend bool operator==(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:30
SkPoint3 cross(const SkPoint3 &vec) const
Definition SkPoint3.h:141
static SkPoint3 CrossProduct(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:132
friend SkPoint3 operator*(SkScalar t, SkPoint3 p)
Definition SkPoint3.h:108
SkScalar fX
Definition SkPoint3.h:16
static SkPoint3 Make(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:18
void operator-=(const SkPoint3 &v)
Definition SkPoint3.h:102
SkScalar x() const
Definition SkPoint3.h:24
friend SkPoint3 operator-(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:82
static SkScalar Length(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.cpp:29
SkScalar length() const
Definition SkPoint3.h:44
SkPoint3 makeScale(SkScalar scale) const
Definition SkPoint3.h:54
SkScalar y() const
Definition SkPoint3.h:25
friend bool operator!=(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:34
SkScalar fZ
Definition SkPoint3.h:16
SkScalar dot(const SkPoint3 &vec) const
Definition SkPoint3.h:126
void set(SkScalar x, SkScalar y, SkScalar z)
Definition SkPoint3.h:28
static SkScalar DotProduct(const SkPoint3 &a, const SkPoint3 &b)
Definition SkPoint3.h:122
bool isFinite() const
Definition SkPoint3.h:116
SkPoint3 operator-() const
Definition SkPoint3.h:71
SkScalar z() const
Definition SkPoint3.h:26
void scale(SkScalar value)
Definition SkPoint3.h:62
SkScalar fY
Definition SkPoint3.h:16