Blender  V3.3
math_float2.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #ifndef __UTIL_MATH_FLOAT2_H__
5 #define __UTIL_MATH_FLOAT2_H__
6 
7 #ifndef __UTIL_MATH_H__
8 # error "Do not include this file directly, include util/types.h instead."
9 #endif
10 
12 
13 /*******************************************************************************
14  * Declaration.
15  */
16 
17 #if !defined(__KERNEL_METAL__)
20 ccl_device_inline float2 operator*(const float2 &a, float f);
21 ccl_device_inline float2 operator*(float f, const float2 &a);
22 ccl_device_inline float2 operator/(float f, const float2 &a);
23 ccl_device_inline float2 operator/(const float2 &a, float f);
25 ccl_device_inline float2 operator+(const float2 &a, const float f);
27 ccl_device_inline float2 operator-(const float2 &a, const float f);
34 
35 ccl_device_inline bool operator==(const float2 &a, const float2 &b);
36 ccl_device_inline bool operator!=(const float2 &a, const float2 &b);
37 
38 ccl_device_inline bool is_zero(const float2 &a);
39 ccl_device_inline float average(const float2 &a);
40 ccl_device_inline float distance(const float2 &a, const float2 &b);
41 ccl_device_inline float dot(const float2 &a, const float2 &b);
42 ccl_device_inline float cross(const float2 &a, const float2 &b);
43 ccl_device_inline float len(const float2 a);
47 ccl_device_inline float2 min(const float2 &a, const float2 &b);
48 ccl_device_inline float2 max(const float2 &a, const float2 &b);
49 ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx);
52 ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t);
54 #endif /* !__KERNEL_METAL__ */
55 
57 
58 /*******************************************************************************
59  * Definition.
60  */
61 
63 {
64  return make_float2(0.0f, 0.0f);
65 }
66 
68 {
69  return make_float2(1.0f, 1.0f);
70 }
71 
72 #if !defined(__KERNEL_METAL__)
74 {
75  return make_float2(-a.x, -a.y);
76 }
77 
79 {
80  return make_float2(a.x * b.x, a.y * b.y);
81 }
82 
84 {
85  return make_float2(a.x * f, a.y * f);
86 }
87 
89 {
90  return make_float2(a.x * f, a.y * f);
91 }
92 
94 {
95  return make_float2(f / a.x, f / a.y);
96 }
97 
99 {
100  float invf = 1.0f / f;
101  return make_float2(a.x * invf, a.y * invf);
102 }
103 
105 {
106  return make_float2(a.x / b.x, a.y / b.y);
107 }
108 
109 ccl_device_inline float2 operator+(const float2 &a, const float f)
110 {
111  return a + make_float2(f, f);
112 }
113 
115 {
116  return make_float2(a.x + b.x, a.y + b.y);
117 }
118 
119 ccl_device_inline float2 operator-(const float2 &a, const float f)
120 {
121  return a - make_float2(f, f);
122 }
123 
125 {
126  return make_float2(a.x - b.x, a.y - b.y);
127 }
128 
130 {
131  return a = a + b;
132 }
133 
135 {
136  return a = a * b;
137 }
138 
140 {
141  return a = a * f;
142 }
143 
145 {
146  return a = a / b;
147 }
148 
150 {
151  float invf = 1.0f / f;
152  return a = a * invf;
153 }
154 
156 {
157  return (a.x == b.x && a.y == b.y);
158 }
159 
161 {
162  return !(a == b);
163 }
164 
166 {
167  return (a.x == 0.0f && a.y == 0.0f);
168 }
169 
171 {
172  return (a.x + a.y) * (1.0f / 2.0f);
173 }
174 
175 ccl_device_inline float distance(const float2 &a, const float2 &b)
176 {
177  return len(a - b);
178 }
179 
180 ccl_device_inline float dot(const float2 &a, const float2 &b)
181 {
182  return a.x * b.x + a.y * b.y;
183 }
184 
185 ccl_device_inline float cross(const float2 &a, const float2 &b)
186 {
187  return (a.x * b.y - a.y * b.x);
188 }
189 
191 {
192  return a / len(a);
193 }
194 
196 {
197  *t = len(a);
198  return a / (*t);
199 }
200 
202 {
203  float t = len(a);
204  return (t != 0.0f) ? a / t : a;
205 }
206 
208 {
209  return make_float2(min(a.x, b.x), min(a.y, b.y));
210 }
211 
213 {
214  return make_float2(max(a.x, b.x), max(a.y, b.y));
215 }
216 
217 ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx)
218 {
219  return min(max(a, mn), mx);
220 }
221 
223 {
224  return make_float2(fabsf(a.x), fabsf(a.y));
225 }
226 
228 {
229  return make_float2(a.x, a.y);
230 }
231 
232 ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
233 {
234  return a + t * (b - a);
235 }
236 
237 ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t)
238 {
239  return a + t * (b - a);
240 }
241 
243 {
244  return make_float2(floorf(a.x), floorf(a.y));
245 }
246 
247 #endif /* !__KERNEL_METAL__ */
248 
250 {
251  return sqrtf(dot(a, a));
252 }
253 
255 {
256  return (b != 0.0f) ? a / b : zero_float2();
257 }
258 
260 
261 #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
float float4[4]
#define ccl_private
Definition: cuda/compat.h:48
#define ccl_device_inline
Definition: cuda/compat.h:34
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
ccl_device_inline float2 as_float2(const float4 &a)
Definition: math_float2.h:227
CCL_NAMESPACE_BEGIN ccl_device_inline float2 operator-(const float2 &a)
Definition: math_float2.h:73
ccl_device_inline float distance(const float2 &a, const float2 &b)
Definition: math_float2.h:175
ccl_device_inline float2 operator/(float f, const float2 &a)
Definition: math_float2.h:93
ccl_device_inline float2 one_float2()
Definition: math_float2.h:67
ccl_device_inline float2 operator+=(float2 &a, const float2 &b)
Definition: math_float2.h:129
ccl_device_inline float2 normalize(const float2 &a)
Definition: math_float2.h:190
ccl_device_inline float dot(const float2 &a, const float2 &b)
Definition: math_float2.h:180
ccl_device_inline float2 operator/=(float2 &a, const float2 &b)
Definition: math_float2.h:144
ccl_device_inline float2 operator*(const float2 &a, const float2 &b)
Definition: math_float2.h:78
ccl_device_inline bool operator==(const float2 &a, const float2 &b)
Definition: math_float2.h:155
ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx)
Definition: math_float2.h:217
ccl_device_inline float2 floor(const float2 &a)
Definition: math_float2.h:242
ccl_device_inline bool operator!=(const float2 &a, const float2 &b)
Definition: math_float2.h:160
ccl_device_inline float2 safe_normalize(const float2 &a)
Definition: math_float2.h:201
ccl_device_inline float2 zero_float2()
Definition: math_float2.h:62
ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t)
Definition: math_float2.h:237
ccl_device_inline float2 normalize_len(const float2 &a, float *t)
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
Definition: math_float2.h:232
ccl_device_inline float2 operator*=(float2 &a, const float2 &b)
Definition: math_float2.h:134
ccl_device_inline bool is_zero(const float2 &a)
Definition: math_float2.h:165
ccl_device_inline float2 max(const float2 &a, const float2 &b)
Definition: math_float2.h:212
ccl_device_inline float2 min(const float2 &a, const float2 &b)
Definition: math_float2.h:207
ccl_device_inline float average(const float2 &a)
Definition: math_float2.h:170
ccl_device_inline float len(const float2 a)
Definition: math_float2.h:249
ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
Definition: math_float2.h:254
ccl_device_inline float2 operator+(const float2 &a, const float f)
Definition: math_float2.h:109
ccl_device_inline float cross(const float2 &a, const float2 &b)
Definition: math_float2.h:185
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
#define make_float2(x, y)
Definition: metal/compat.h:203
#define floorf(x)
Definition: metal/compat.h:224
#define fabsf(x)
Definition: metal/compat.h:219
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned a[3]
Definition: RandGen.cpp:78
static const pxr::TfToken b("b", pxr::TfToken::Immortal)