Blender V4.3
math_float2.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#ifndef __UTIL_MATH_FLOAT2_H__
6#define __UTIL_MATH_FLOAT2_H__
7
8#ifndef __UTIL_MATH_H__
9# error "Do not include this file directly, include util/types.h instead."
10#endif
11
13
15{
16 return make_float2(0.0f, 0.0f);
17}
18
20{
21 return make_float2(1.0f, 1.0f);
22}
23
24#if !defined(__KERNEL_METAL__)
26{
27 return make_float2(-a.x, -a.y);
28}
29
31{
32 return make_float2(a.x * b.x, a.y * b.y);
33}
34
36{
37 return make_float2(a.x * f, a.y * f);
38}
39
41{
42 return make_float2(a.x * f, a.y * f);
43}
44
46{
47 return make_float2(f / a.x, f / a.y);
48}
49
51{
52 float invf = 1.0f / f;
53 return make_float2(a.x * invf, a.y * invf);
54}
55
57{
58 return make_float2(a.x / b.x, a.y / b.y);
59}
60
62{
63 return make_float2(a.x + b.x, a.y + b.y);
64}
65
67{
68 return a + make_float2(f, f);
69}
70
72{
73 return make_float2(a.x - b.x, a.y - b.y);
74}
75
77{
78 return a - make_float2(f, f);
79}
80
82{
83 return a = a + b;
84}
85
87{
88 return a = a * b;
89}
90
92{
93 return a = a * f;
94}
95
97{
98 return a = a / b;
99}
100
102{
103 float invf = 1.0f / f;
104 return a = a * invf;
105}
106
108{
109 return (a.x == b.x && a.y == b.y);
110}
111
113{
114 return !(a == b);
115}
116
118{
119 return (a.x == 0.0f && a.y == 0.0f);
120}
121
122ccl_device_inline float dot(const float2 a, const float2 b)
123{
124 return a.x * b.x + a.y * b.y;
125}
126#endif
127
129{
130 return (a.x + a.y) * (1.0f / 2.0f);
131}
132
134{
135#if defined(__KERNEL_METAL__)
136 return all(a == b);
137#else
138 return a == b;
139#endif
140}
141
143{
144 return sqrtf(dot(a, a));
145}
146
148{
149 return min(a.x, a.y);
150}
151
153{
154 return max(a.x, a.y);
155}
156
158{
159 return a.x + a.y;
160}
161
163{
164 return dot(a, a);
165}
166
168{
169 float t = len(a);
170 return (t != 0.0f) ? a / t : a;
171}
172
173#if !defined(__KERNEL_METAL__)
175{
176 return len(a - b);
177}
178
179ccl_device_inline float cross(const float2 a, const float2 b)
180{
181 return (a.x * b.y - a.y * b.x);
182}
183
185{
186 return a / len(a);
187}
188
190{
191 *t = len(a);
192 return a / (*t);
193}
194
196{
197 return make_float2(min(a.x, b.x), min(a.y, b.y));
198}
199
201{
202 return make_float2(max(a.x, b.x), max(a.y, b.y));
203}
204
205ccl_device_inline float2 clamp(const float2 a, const float2 mn, const float2 mx)
206{
207 return min(max(a, mn), mx);
208}
209
210ccl_device_inline float2 fmod(const float2 a, const float b)
211{
212 return make_float2(fmodf(a.x, b), fmodf(a.y, b));
213}
214
216{
217 return make_float2(fabsf(a.x), fabsf(a.y));
218}
219
221{
222 return make_float2(a.x, a.y);
223}
224
226{
227 return a + t * (b - a);
228}
229
230ccl_device_inline float2 mix(const float2 a, const float2 b, float t)
231{
232 return a + t * (b - a);
233}
234
236{
237 return make_float2(floorf(a.x), floorf(a.y));
238}
239
240#endif /* !__KERNEL_METAL__ */
241
242/* Consistent name for this would be pow, but HIP compiler crashes in name mangling. */
244{
245 return make_float2(powf(v.x, e), powf(v.y, e));
246}
247
249{
250 return (b != 0.0f) ? a / b : zero_float2();
251}
252
254
255#endif /* __UTIL_MATH_FLOAT2_H__ */
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
SIMD_FORCE_INLINE btVector3 & normalize()
Normalize this vector x^2 + y^2 + z^2 = 1.
Definition btVector3.h:303
local_group_size(16, 16) .push_constant(Type b
#define ccl_private
#define ccl_device_inline
#define powf(x, y)
#define CCL_NAMESPACE_END
#define fmodf(x, y)
#define floorf(x)
ccl_device_forceinline float2 make_float2(const float x, const float y)
#define fabsf(x)
#define sqrtf(x)
int len
#define mix(a, b, c)
Definition hash.h:36
ccl_device_inline float2 as_float2(const float4 &a)
ccl_device_inline float2 operator*(const float2 a, const float2 b)
Definition math_float2.h:30
ccl_device_inline float2 operator-(const float2 &a)
Definition math_float2.h:25
ccl_device_inline float distance(const float2 a, const float2 b)
ccl_device_inline float2 fmod(const float2 a, const float b)
ccl_device_inline float2 one_float2()
Definition math_float2.h:19
CCL_NAMESPACE_BEGIN ccl_device_inline float2 zero_float2()
Definition math_float2.h:14
ccl_device_inline float2 floor(const float2 a)
ccl_device_inline float len_squared(const float2 a)
ccl_device_inline bool is_zero(const float2 a)
ccl_device_inline bool operator!=(const float2 a, const float2 b)
ccl_device_inline float average(const float2 a)
ccl_device_inline float reduce_max(const float2 a)
ccl_device_inline float reduce_add(const float2 a)
ccl_device_inline float dot(const float2 a, const float2 b)
ccl_device_inline float2 safe_normalize(const float2 a)
ccl_device_inline float2 normalize_len(const float2 a, ccl_private float *t)
ccl_device_inline float2 operator/=(float2 &a, const float2 b)
Definition math_float2.h:96
ccl_device_inline float cross(const float2 a, const float2 b)
ccl_device_inline float2 operator/(float f, const float2 a)
Definition math_float2.h:45
ccl_device_inline float reduce_min(const float2 a)
ccl_device_inline float2 power(float2 v, float e)
ccl_device_inline float2 fabs(const float2 a)
ccl_device_inline float2 clamp(const float2 a, const float2 mn, const float2 mx)
ccl_device_inline float2 operator+=(float2 &a, const float2 b)
Definition math_float2.h:81
ccl_device_inline bool isequal(const float2 a, const float2 b)
ccl_device_inline bool operator==(const float2 a, const float2 b)
ccl_device_inline float2 operator+(const float2 a, const float2 b)
Definition math_float2.h:61
ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
ccl_device_inline float2 operator*=(float2 &a, const float2 b)
Definition math_float2.h:86
ccl_device_inline float2 interp(const float2 a, const float2 b, float t)
#define min(a, b)
Definition sort.c:32
float x
float max