Blender  V2.93
BLI_double3.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
23 #include <iostream>
24 
25 #include "BLI_math_vector.h"
26 #include "BLI_span.hh"
27 
28 namespace blender {
29 
30 struct double3 {
31  double x, y, z;
32 
33  double3() = default;
34 
35  double3(const double *ptr) : x{ptr[0]}, y{ptr[1]}, z{ptr[2]}
36  {
37  }
38 
39  double3(const double (*ptr)[3]) : double3((const double *)ptr)
40  {
41  }
42 
43  explicit double3(double value) : x(value), y(value), z(value)
44  {
45  }
46 
47  explicit double3(int value) : x(value), y(value), z(value)
48  {
49  }
50 
51  double3(double x, double y, double z) : x{x}, y{y}, z{z}
52  {
53  }
54 
55  operator const double *() const
56  {
57  return &x;
58  }
59 
60  operator double *()
61  {
62  return &x;
63  }
64 
66  {
67  return normalize_v3_db(*this);
68  }
69 
71  {
73  normalize_v3_v3_db(result, *this);
74  return result;
75  }
76 
77  double length() const
78  {
79  return len_v3_db(*this);
80  }
81 
82  double length_squared() const
83  {
84  return len_squared_v3_db(*this);
85  }
86 
87  void reflect(const double3 &normal)
88  {
89  *this = this->reflected(normal);
90  }
91 
93  {
96  return result;
97  }
98 
99  static double3 safe_divide(const double3 &a, const double3 &b)
100  {
101  double3 result;
102  result.x = (b.x == 0.0) ? 0.0 : a.x / b.x;
103  result.y = (b.y == 0.0) ? 0.0 : a.y / b.y;
104  result.z = (b.z == 0.0) ? 0.0 : a.z / b.z;
105  return result;
106  }
107 
108  void invert()
109  {
110  x = -x;
111  y = -y;
112  z = -z;
113  }
114 
115  friend double3 operator+(const double3 &a, const double3 &b)
116  {
117  return {a.x + b.x, a.y + b.y, a.z + b.z};
118  }
119 
120  void operator+=(const double3 &b)
121  {
122  this->x += b.x;
123  this->y += b.y;
124  this->z += b.z;
125  }
126 
127  friend double3 operator-(const double3 &a, const double3 &b)
128  {
129  return {a.x - b.x, a.y - b.y, a.z - b.z};
130  }
131 
132  friend double3 operator-(const double3 &a)
133  {
134  return {-a.x, -a.y, -a.z};
135  }
136 
137  void operator-=(const double3 &b)
138  {
139  this->x -= b.x;
140  this->y -= b.y;
141  this->z -= b.z;
142  }
143 
144  void operator*=(const double &scalar)
145  {
146  this->x *= scalar;
147  this->y *= scalar;
148  this->z *= scalar;
149  }
150 
151  void operator*=(const double3 &other)
152  {
153  this->x *= other.x;
154  this->y *= other.y;
155  this->z *= other.z;
156  }
157 
158  friend double3 operator*(const double3 &a, const double3 &b)
159  {
160  return {a.x * b.x, a.y * b.y, a.z * b.z};
161  }
162 
163  friend double3 operator*(const double3 &a, const double &b)
164  {
165  return {a.x * b, a.y * b, a.z * b};
166  }
167 
168  friend double3 operator*(const double &a, const double3 &b)
169  {
170  return b * a;
171  }
172 
173  friend double3 operator/(const double3 &a, const double &b)
174  {
175  BLI_assert(b != 0.0);
176  return {a.x / b, a.y / b, a.z / b};
177  }
178 
179  friend bool operator==(const double3 &a, const double3 &b)
180  {
181  return a.x == b.x && a.y == b.y && a.z == b.z;
182  }
183 
184  friend bool operator!=(const double3 &a, const double3 &b)
185  {
186  return a.x != b.x || a.y != b.y || a.z != b.z;
187  }
188 
189  friend std::ostream &operator<<(std::ostream &stream, const double3 &v)
190  {
191  stream << "(" << v.x << ", " << v.y << ", " << v.z << ")";
192  return stream;
193  }
194 
195  static double dot(const double3 &a, const double3 &b)
196  {
197  return a.x * b.x + a.y * b.y + a.z * b.z;
198  }
199 
200  static double3 cross_high_precision(const double3 &a, const double3 &b)
201  {
202  double3 result;
204  return result;
205  }
206 
207  static double3 project(const double3 &a, const double3 &b)
208  {
209  double3 result;
211  return result;
212  }
213 
214  static double distance(const double3 &a, const double3 &b)
215  {
216  return (a - b).length();
217  }
218 
219  static double distance_squared(const double3 &a, const double3 &b)
220  {
221  double3 diff = a - b;
222  return double3::dot(diff, diff);
223  }
224 
225  static double3 interpolate(const double3 &a, const double3 &b, double t)
226  {
227  return a * (1 - t) + b * t;
228  }
229 
230  static double3 abs(const double3 &a)
231  {
232  return double3(fabs(a.x), fabs(a.y), fabs(a.z));
233  }
234 
235  static int dominant_axis(const double3 &a)
236  {
237  double x = (a.x >= 0) ? a.x : -a.x;
238  double y = (a.y >= 0) ? a.y : -a.y;
239  double z = (a.z >= 0) ? a.z : -a.z;
240  return ((x > y) ? ((x > z) ? 0 : 2) : ((y > z) ? 1 : 2));
241  }
242 
243  static double3 cross_poly(Span<double3> poly);
244 };
245 
246 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:58
MINLINE double normalize_v3_db(double n[3])
MINLINE double normalize_v3_v3_db(double r[3], const double a[3])
MINLINE double len_squared_v3_db(const double v[3]) ATTR_WARN_UNUSED_RESULT
MINLINE double len_v3_db(const double a[3]) ATTR_WARN_UNUSED_RESULT
MINLINE void cross_v3_v3v3_db(double r[3], const double a[3], const double b[3])
void reflect_v3_v3v3_db(double out[3], const double vec[3], const double normal[3])
Definition: math_vector.c:829
void project_v3_v3v3_db(double out[3], const double p[3], const double v_proj[3])
Definition: math_vector.c:688
typedef double(DMatrix)[4][4]
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
return(oflags[bm->toolflag_index].f &oflag) !=0
ATTR_WARN_UNUSED_RESULT const BMVert * v
IconTextureDrawCall normal
static unsigned a[3]
Definition: RandGen.cpp:92
IMETHOD Vector diff(const Vector &a, const Vector &b, double dt=1)
static double3 interpolate(const double3 &a, const double3 &b, double t)
Definition: BLI_double3.hh:225
double3(double x, double y, double z)
Definition: BLI_double3.hh:51
double3 normalized() const
Definition: BLI_double3.hh:70
friend double3 operator*(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:158
static double3 cross_poly(Span< double3 > poly)
Definition: math_vec.cc:126
void operator-=(const double3 &b)
Definition: BLI_double3.hh:137
friend double3 operator-(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:127
static int dominant_axis(const double3 &a)
Definition: BLI_double3.hh:235
friend double3 operator*(const double &a, const double3 &b)
Definition: BLI_double3.hh:168
double3(const double *ptr)
Definition: BLI_double3.hh:35
void operator+=(const double3 &b)
Definition: BLI_double3.hh:120
double3 reflected(const double3 &normal) const
Definition: BLI_double3.hh:92
friend bool operator==(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:179
double normalize_and_get_length()
Definition: BLI_double3.hh:65
double3()=default
friend std::ostream & operator<<(std::ostream &stream, const double3 &v)
Definition: BLI_double3.hh:189
double3(int value)
Definition: BLI_double3.hh:47
friend double3 operator*(const double3 &a, const double &b)
Definition: BLI_double3.hh:163
friend double3 operator+(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:115
static double3 safe_divide(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:99
static double distance(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:214
void operator*=(const double &scalar)
Definition: BLI_double3.hh:144
friend double3 operator-(const double3 &a)
Definition: BLI_double3.hh:132
static double distance_squared(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:219
static double3 project(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:207
double3(double value)
Definition: BLI_double3.hh:43
friend bool operator!=(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:184
static double3 cross_high_precision(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:200
static double3 abs(const double3 &a)
Definition: BLI_double3.hh:230
void operator*=(const double3 &other)
Definition: BLI_double3.hh:151
friend double3 operator/(const double3 &a, const double &b)
Definition: BLI_double3.hh:173
static double dot(const double3 &a, const double3 &b)
Definition: BLI_double3.hh:195
void reflect(const double3 &normal)
Definition: BLI_double3.hh:87
double length_squared() const
Definition: BLI_double3.hh:82
double3(const double(*ptr)[3])
Definition: BLI_double3.hh:39
double length() const
Definition: BLI_double3.hh:77
ccl_device_inline float2 fabs(const float2 &a)
PointerRNA * ptr
Definition: wm_files.c:3157