Blender  V2.93
util_math_float2.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2017 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __UTIL_MATH_FLOAT2_H__
18 #define __UTIL_MATH_FLOAT2_H__
19 
20 #ifndef __UTIL_MATH_H__
21 # error "Do not include this file directly, include util_types.h instead."
22 #endif
23 
25 
26 /*******************************************************************************
27  * Declaration.
28  */
29 
30 #ifndef __KERNEL_OPENCL__
33 ccl_device_inline float2 operator*(const float2 &a, float f);
34 ccl_device_inline float2 operator*(float f, const float2 &a);
35 ccl_device_inline float2 operator/(float f, const float2 &a);
36 ccl_device_inline float2 operator/(const float2 &a, float f);
38 ccl_device_inline float2 operator+(const float2 &a, const float f);
40 ccl_device_inline float2 operator-(const float2 &a, const float f);
47 
48 ccl_device_inline bool operator==(const float2 &a, const float2 &b);
49 ccl_device_inline bool operator!=(const float2 &a, const float2 &b);
50 
51 ccl_device_inline bool is_zero(const float2 &a);
52 ccl_device_inline float average(const float2 &a);
53 ccl_device_inline float distance(const float2 &a, const float2 &b);
54 ccl_device_inline float dot(const float2 &a, const float2 &b);
55 ccl_device_inline float cross(const float2 &a, const float2 &b);
56 ccl_device_inline float len(const float2 &a);
60 ccl_device_inline float2 min(const float2 &a, const float2 &b);
61 ccl_device_inline float2 max(const float2 &a, const float2 &b);
62 ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx);
64 ccl_device_inline float2 as_float2(const float4 &a);
65 ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t);
67 #endif /* !__KERNEL_OPENCL__ */
68 
70 
71 /*******************************************************************************
72  * Definition.
73  */
74 
76 {
77  return make_float2(0.0f, 0.0f);
78 }
79 
81 {
82  return make_float2(1.0f, 1.0f);
83 }
84 
85 #ifndef __KERNEL_OPENCL__
87 {
88  return make_float2(-a.x, -a.y);
89 }
90 
92 {
93  return make_float2(a.x * b.x, a.y * b.y);
94 }
95 
97 {
98  return make_float2(a.x * f, a.y * f);
99 }
100 
102 {
103  return make_float2(a.x * f, a.y * f);
104 }
105 
107 {
108  return make_float2(f / a.x, f / a.y);
109 }
110 
112 {
113  float invf = 1.0f / f;
114  return make_float2(a.x * invf, a.y * invf);
115 }
116 
118 {
119  return make_float2(a.x / b.x, a.y / b.y);
120 }
121 
122 ccl_device_inline float2 operator+(const float2 &a, const float f)
123 {
124  return a + make_float2(f, f);
125 }
126 
128 {
129  return make_float2(a.x + b.x, a.y + b.y);
130 }
131 
132 ccl_device_inline float2 operator-(const float2 &a, const float f)
133 {
134  return a - make_float2(f, f);
135 }
136 
138 {
139  return make_float2(a.x - b.x, a.y - b.y);
140 }
141 
143 {
144  return a = a + b;
145 }
146 
148 {
149  return a = a * b;
150 }
151 
153 {
154  return a = a * f;
155 }
156 
158 {
159  return a = a / b;
160 }
161 
163 {
164  float invf = 1.0f / f;
165  return a = a * invf;
166 }
167 
169 {
170  return (a.x == b.x && a.y == b.y);
171 }
172 
174 {
175  return !(a == b);
176 }
177 
179 {
180  return (a.x == 0.0f && a.y == 0.0f);
181 }
182 
184 {
185  return (a.x + a.y) * (1.0f / 2.0f);
186 }
187 
188 ccl_device_inline float distance(const float2 &a, const float2 &b)
189 {
190  return len(a - b);
191 }
192 
193 ccl_device_inline float dot(const float2 &a, const float2 &b)
194 {
195  return a.x * b.x + a.y * b.y;
196 }
197 
198 ccl_device_inline float cross(const float2 &a, const float2 &b)
199 {
200  return (a.x * b.y - a.y * b.x);
201 }
202 
204 {
205  return sqrtf(dot(a, a));
206 }
207 
209 {
210  return a / len(a);
211 }
212 
214 {
215  *t = len(a);
216  return a / (*t);
217 }
218 
220 {
221  float t = len(a);
222  return (t != 0.0f) ? a / t : a;
223 }
224 
226 {
227  return make_float2(min(a.x, b.x), min(a.y, b.y));
228 }
229 
231 {
232  return make_float2(max(a.x, b.x), max(a.y, b.y));
233 }
234 
235 ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx)
236 {
237  return min(max(a, mn), mx);
238 }
239 
241 {
242  return make_float2(fabsf(a.x), fabsf(a.y));
243 }
244 
246 {
247  return make_float2(a.x, a.y);
248 }
249 
250 ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
251 {
252  return a + t * (b - a);
253 }
254 
255 ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t)
256 {
257  return a + t * (b - a);
258 }
259 
261 {
262  return make_float2(floorf(a.x), floorf(a.y));
263 }
264 
265 #endif /* !__KERNEL_OPENCL__ */
266 
268 {
269  return (b != 0.0f) ? a / b : zero_float2();
270 }
271 
273 
274 #endif /* __UTIL_MATH_FLOAT2_H__ */
_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
#define ccl_device_inline
#define CCL_NAMESPACE_END
#define make_float2(x, y)
#define floorf(x)
#define fabsf(x)
#define sqrtf(x)
static unsigned a[3]
Definition: RandGen.cpp:92
ccl_device_inline float2 as_float2(const float4 &a)
CCL_NAMESPACE_BEGIN ccl_device_inline float2 operator-(const float2 &a)
ccl_device_inline float distance(const float2 &a, const float2 &b)
ccl_device_inline float2 operator/(float f, const float2 &a)
ccl_device_inline float2 one_float2()
ccl_device_inline float2 operator+=(float2 &a, const float2 &b)
ccl_device_inline float2 normalize(const float2 &a)
ccl_device_inline float dot(const float2 &a, const float2 &b)
ccl_device_inline float2 operator/=(float2 &a, const float2 &b)
ccl_device_inline float2 operator*(const float2 &a, const float2 &b)
ccl_device_inline bool operator==(const float2 &a, const float2 &b)
ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx)
ccl_device_inline float2 floor(const float2 &a)
ccl_device_inline bool operator!=(const float2 &a, const float2 &b)
ccl_device_inline float2 safe_normalize(const float2 &a)
ccl_device_inline float2 zero_float2()
ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t)
ccl_device_inline float2 normalize_len(const float2 &a, float *t)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
ccl_device_inline float2 operator*=(float2 &a, const float2 &b)
ccl_device_inline bool is_zero(const float2 &a)
ccl_device_inline float2 max(const float2 &a, const float2 &b)
ccl_device_inline float2 min(const float2 &a, const float2 &b)
ccl_device_inline float average(const float2 &a)
ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
ccl_device_inline float2 operator+(const float2 &a, const float f)
ccl_device_inline float cross(const float2 &a, const float2 &b)
ccl_device_inline float len(const float2 &a)
ccl_device_inline float2 fabs(const float2 &a)