Welcome to mirror list, hosted at ThFree Co, Russian Federation.

math_float2.h « util « cycles « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 542dad9346754973376feeb7329f352dd861c740 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/* SPDX-License-Identifier: Apache-2.0
 * Copyright 2011-2022 Blender Foundation */

#ifndef __UTIL_MATH_FLOAT2_H__
#define __UTIL_MATH_FLOAT2_H__

#ifndef __UTIL_MATH_H__
#  error "Do not include this file directly, include util/types.h instead."
#endif

CCL_NAMESPACE_BEGIN

/*******************************************************************************
 * Declaration.
 */

#if !defined(__KERNEL_METAL__)
ccl_device_inline float2 operator-(const float2 &a);
ccl_device_inline float2 operator*(const float2 &a, const float2 &b);
ccl_device_inline float2 operator*(const float2 &a, float f);
ccl_device_inline float2 operator*(float f, const float2 &a);
ccl_device_inline float2 operator/(float f, const float2 &a);
ccl_device_inline float2 operator/(const float2 &a, float f);
ccl_device_inline float2 operator/(const float2 &a, const float2 &b);
ccl_device_inline float2 operator+(const float2 &a, const float f);
ccl_device_inline float2 operator+(const float2 &a, const float2 &b);
ccl_device_inline float2 operator-(const float2 &a, const float f);
ccl_device_inline float2 operator-(const float2 &a, const float2 &b);
ccl_device_inline float2 operator+=(float2 &a, const float2 &b);
ccl_device_inline float2 operator*=(float2 &a, const float2 &b);
ccl_device_inline float2 operator*=(float2 &a, float f);
ccl_device_inline float2 operator/=(float2 &a, const float2 &b);
ccl_device_inline float2 operator/=(float2 &a, float f);

ccl_device_inline bool operator==(const float2 &a, const float2 &b);
ccl_device_inline bool operator!=(const float2 &a, const float2 &b);

ccl_device_inline bool is_zero(const float2 &a);
ccl_device_inline float average(const float2 &a);
ccl_device_inline float distance(const float2 &a, const float2 &b);
ccl_device_inline float dot(const float2 &a, const float2 &b);
ccl_device_inline float cross(const float2 &a, const float2 &b);
ccl_device_inline float len(const float2 a);
ccl_device_inline float2 normalize(const float2 &a);
ccl_device_inline float2 normalize_len(const float2 &a, float *t);
ccl_device_inline float2 safe_normalize(const float2 &a);
ccl_device_inline float2 min(const float2 &a, const float2 &b);
ccl_device_inline float2 max(const float2 &a, const float2 &b);
ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx);
ccl_device_inline float2 fabs(const float2 &a);
ccl_device_inline float2 as_float2(const float4 &a);
ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t);
ccl_device_inline float2 floor(const float2 &a);
#endif /* !__KERNEL_METAL__ */

ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b);

/*******************************************************************************
 * Definition.
 */

ccl_device_inline float2 zero_float2()
{
  return make_float2(0.0f, 0.0f);
}

ccl_device_inline float2 one_float2()
{
  return make_float2(1.0f, 1.0f);
}

#if !defined(__KERNEL_METAL__)
ccl_device_inline float2 operator-(const float2 &a)
{
  return make_float2(-a.x, -a.y);
}

ccl_device_inline float2 operator*(const float2 &a, const float2 &b)
{
  return make_float2(a.x * b.x, a.y * b.y);
}

ccl_device_inline float2 operator*(const float2 &a, float f)
{
  return make_float2(a.x * f, a.y * f);
}

ccl_device_inline float2 operator*(float f, const float2 &a)
{
  return make_float2(a.x * f, a.y * f);
}

ccl_device_inline float2 operator/(float f, const float2 &a)
{
  return make_float2(f / a.x, f / a.y);
}

ccl_device_inline float2 operator/(const float2 &a, float f)
{
  float invf = 1.0f / f;
  return make_float2(a.x * invf, a.y * invf);
}

ccl_device_inline float2 operator/(const float2 &a, const float2 &b)
{
  return make_float2(a.x / b.x, a.y / b.y);
}

ccl_device_inline float2 operator+(const float2 &a, const float f)
{
  return a + make_float2(f, f);
}

ccl_device_inline float2 operator+(const float2 &a, const float2 &b)
{
  return make_float2(a.x + b.x, a.y + b.y);
}

ccl_device_inline float2 operator-(const float2 &a, const float f)
{
  return a - make_float2(f, f);
}

ccl_device_inline float2 operator-(const float2 &a, const float2 &b)
{
  return make_float2(a.x - b.x, a.y - b.y);
}

ccl_device_inline float2 operator+=(float2 &a, const float2 &b)
{
  return a = a + b;
}

ccl_device_inline float2 operator*=(float2 &a, const float2 &b)
{
  return a = a * b;
}

ccl_device_inline float2 operator*=(float2 &a, float f)
{
  return a = a * f;
}

ccl_device_inline float2 operator/=(float2 &a, const float2 &b)
{
  return a = a / b;
}

ccl_device_inline float2 operator/=(float2 &a, float f)
{
  float invf = 1.0f / f;
  return a = a * invf;
}

ccl_device_inline bool operator==(const float2 &a, const float2 &b)
{
  return (a.x == b.x && a.y == b.y);
}

ccl_device_inline bool operator!=(const float2 &a, const float2 &b)
{
  return !(a == b);
}

ccl_device_inline bool is_zero(const float2 &a)
{
  return (a.x == 0.0f && a.y == 0.0f);
}

ccl_device_inline float average(const float2 &a)
{
  return (a.x + a.y) * (1.0f / 2.0f);
}

ccl_device_inline float distance(const float2 &a, const float2 &b)
{
  return len(a - b);
}

ccl_device_inline float dot(const float2 &a, const float2 &b)
{
  return a.x * b.x + a.y * b.y;
}

ccl_device_inline float cross(const float2 &a, const float2 &b)
{
  return (a.x * b.y - a.y * b.x);
}

ccl_device_inline float2 normalize(const float2 &a)
{
  return a / len(a);
}

ccl_device_inline float2 normalize_len(const float2 &a, ccl_private float *t)
{
  *t = len(a);
  return a / (*t);
}

ccl_device_inline float2 safe_normalize(const float2 &a)
{
  float t = len(a);
  return (t != 0.0f) ? a / t : a;
}

ccl_device_inline float2 min(const float2 &a, const float2 &b)
{
  return make_float2(min(a.x, b.x), min(a.y, b.y));
}

ccl_device_inline float2 max(const float2 &a, const float2 &b)
{
  return make_float2(max(a.x, b.x), max(a.y, b.y));
}

ccl_device_inline float2 clamp(const float2 &a, const float2 &mn, const float2 &mx)
{
  return min(max(a, mn), mx);
}

ccl_device_inline float2 fabs(const float2 &a)
{
  return make_float2(fabsf(a.x), fabsf(a.y));
}

ccl_device_inline float2 as_float2(const float4 &a)
{
  return make_float2(a.x, a.y);
}

ccl_device_inline float2 interp(const float2 &a, const float2 &b, float t)
{
  return a + t * (b - a);
}

ccl_device_inline float2 mix(const float2 &a, const float2 &b, float t)
{
  return a + t * (b - a);
}

ccl_device_inline float2 floor(const float2 &a)
{
  return make_float2(floorf(a.x), floorf(a.y));
}

#endif /* !__KERNEL_METAL__ */

ccl_device_inline float len(const float2 a)
{
  return sqrtf(dot(a, a));
}

ccl_device_inline float2 safe_divide_float2_float(const float2 a, const float b)
{
  return (b != 0.0f) ? a / b : zero_float2();
}

CCL_NAMESPACE_END

#endif /* __UTIL_MATH_FLOAT2_H__ */