Vuo  2.0.2
VuoPoint4d.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #include <math.h>
13 #include "VuoPoint3d.h"
14 #include "VuoReal.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
31 typedef float __attribute__((ext_vector_type(4))) VuoPoint4d;
32 
33 VuoPoint4d VuoPoint4d_makeFromJson(struct json_object * js);
34 struct json_object * VuoPoint4d_getJson(const VuoPoint4d value);
35 char * VuoPoint4d_getSummary(const VuoPoint4d value);
36 
37 #define VuoPoint4d_SUPPORTS_COMPARISON
38 bool VuoPoint4d_areEqual(const VuoPoint4d value1, const VuoPoint4d value2);
39 bool VuoPoint4d_isLessThan(const VuoPoint4d a, const VuoPoint4d b);
40 
41 VuoPoint4d VuoPoint4d_random(const VuoPoint4d minimum, const VuoPoint4d maximum);
42 VuoPoint4d VuoPoint4d_randomWithState(unsigned short state[3], const VuoPoint4d minimum, const VuoPoint4d maximum);
43 
45 
48 VuoPoint4d VuoPoint4d_makeFromString(const char *str);
49 char * VuoPoint4d_getString(const VuoPoint4d value);
50 void VuoPoint4d_retain(VuoPoint4d value);
51 void VuoPoint4d_release(VuoPoint4d value);
53 
57 static inline VuoPoint4d VuoPoint4d_make(float x, float y, float z, float w) __attribute__((const));
58 static inline VuoPoint4d VuoPoint4d_make(float x, float y, float z, float w)
59 {
60  return (VuoPoint4d){x, y, z, w};
61 }
62 
68 static inline VuoPoint4d VuoPoint4d_makeFromArray(float *f)
69 {
70  return (VuoPoint4d){ f[0], f[1], f[2], f[3] };
71 }
72 
78 static inline void VuoPoint4d_setArray(float *f, VuoPoint4d p)
79 {
80  f[0] = p.x;
81  f[1] = p.y;
82  f[2] = p.z;
83  f[3] = p.w;
84 }
85 
91 static inline VuoPoint3d VuoPoint4d_to3d(VuoPoint4d p) __attribute__((const));
92 static inline VuoPoint3d VuoPoint4d_to3d(VuoPoint4d p)
93 {
94  return (VuoPoint3d){p.x, p.y, p.z};
95 }
96 
102 static inline VuoPoint4d VuoPoint3d_to4d1(VuoPoint3d p) __attribute__((const));
103 static inline VuoPoint4d VuoPoint3d_to4d1(VuoPoint3d p)
104 {
105  return (VuoPoint4d){p.x, p.y, p.z, 1};
106 }
107 
111 static inline VuoPoint4d VuoPoint4d_crossProduct(VuoPoint4d u, VuoPoint4d v) __attribute__((const));
112 static inline VuoPoint4d VuoPoint4d_crossProduct(VuoPoint4d u, VuoPoint4d v)
113 {
114  return (VuoPoint4d){
115  u.y*v.z - u.z*v.y,
116  u.z*v.x - u.x*v.z,
117  u.x*v.y - u.y*v.x,
118  1.
119  };
120 }
121 
125 static inline float VuoPoint4d_dotProduct(VuoPoint4d u, VuoPoint4d v) __attribute__((const));
126 static inline float VuoPoint4d_dotProduct(VuoPoint4d u, VuoPoint4d v)
127 {
128  return u.x*v.x + u.y*v.y + u.z*v.z + u.w*v.w;
129 }
130 
131 
135 static inline float VuoPoint4d_magnitude(VuoPoint4d a) __attribute__((const));
136 static inline float VuoPoint4d_magnitude(VuoPoint4d a)
137 {
138  return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z + a.w*a.w);
139 }
140 
144 static inline VuoPoint4d VuoPoint4d_normalize3d(VuoPoint4d a) __attribute__((const));
145 static inline VuoPoint4d VuoPoint4d_normalize3d(VuoPoint4d a)
146 {
147  VuoPoint3d p = a.xyz / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
148  return (VuoPoint4d){p.x, p.y, p.z, a.w};
149 }
150 
154 static inline VuoPoint4d VuoPoint4d_normalize(VuoPoint4d a) __attribute__((const));
155 static inline VuoPoint4d VuoPoint4d_normalize(VuoPoint4d a)
156 {
157  return a / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
158 }
159 
163 static inline VuoPoint4d VuoPoint4d_add(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
164 static inline VuoPoint4d VuoPoint4d_add(VuoPoint4d a, VuoPoint4d b)
165 {
166  return a + b;
167 }
168 
172 static inline VuoPoint4d VuoPoint4d_subtract(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
173 static inline VuoPoint4d VuoPoint4d_subtract(VuoPoint4d a, VuoPoint4d b)
174 {
175  return a - b;
176 }
177 
181 static inline float VuoPoint4d_squaredMagnitude(VuoPoint4d a) __attribute__((const));
182 static inline float VuoPoint4d_squaredMagnitude(VuoPoint4d a)
183 {
184  return (a.x*a.x + a.y*a.y + a.z*a.z + a.w*a.w);
185 }
186 
187 
191 static inline VuoPoint4d VuoPoint4d_divide(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
192 static inline VuoPoint4d VuoPoint4d_divide(VuoPoint4d a, VuoPoint4d b)
193 {
194  return a / b;
195 }
196 
200 static inline VuoPoint4d VuoPoint4d_multiply(VuoPoint4d a, float b) __attribute__((const));
201 static inline VuoPoint4d VuoPoint4d_multiply(VuoPoint4d a, float b)
202 {
203  return a * b;
204 }
205 
209 static inline VuoPoint4d VuoPoint4d_scale(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
210 static inline VuoPoint4d VuoPoint4d_scale(VuoPoint4d a, VuoPoint4d b)
211 {
212  return a * b;
213 }
214 
218 static inline VuoPoint4d VuoPoint4d_makeNonzero(VuoPoint4d a) __attribute__((const));
219 static inline VuoPoint4d VuoPoint4d_makeNonzero(VuoPoint4d a)
220 {
221  if (fabs(a.x) < 0.000001)
222  a.x = copysign(0.000001, a.x);
223  if (fabs(a.y) < 0.000001)
224  a.y = copysign(0.000001, a.y);
225  if (fabs(a.z) < 0.000001)
226  a.z = copysign(0.000001, a.z);
227  if (fabs(a.w) < 0.000001)
228  a.w = copysign(0.000001, a.w);
229  return a;
230 }
231 
235 static inline float VuoPoint4d_distance(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
236 static inline float VuoPoint4d_distance(VuoPoint4d a, VuoPoint4d b)
237 {
238  return sqrtf((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z) + (a.w-b.w)*(a.w-b.w));
239 }
240 
244 static inline VuoPoint4d VuoPoint4d_snap(VuoPoint4d a, VuoPoint4d center, VuoPoint4d snap) __attribute__((const));
245 static inline VuoPoint4d VuoPoint4d_snap(VuoPoint4d a, VuoPoint4d center, VuoPoint4d snap)
246 {
247  VuoPoint4d nonzeroSnap = VuoPoint4d_makeNonzero(snap);
248  return (VuoPoint4d) {
249  center.x + nonzeroSnap.x * (int)round((a.x-center.x) / nonzeroSnap.x),
250  center.y + nonzeroSnap.y * (int)round((a.y-center.y) / nonzeroSnap.y),
251  center.z + nonzeroSnap.z * (int)round((a.z-center.z) / nonzeroSnap.z),
252  center.w + nonzeroSnap.w * (int)round((a.w-center.w) / nonzeroSnap.w)
253  };
254 }
255 
256 
260 static inline VuoPoint4d VuoPoint4d_clampn(VuoPoint4d point, VuoPoint4d limitA, VuoPoint4d limitB)
261 {
262  return (VuoPoint4d){
263  (float)VuoReal_clamp(point.x, limitA.x, limitB.x),
264  (float)VuoReal_clamp(point.y, limitA.y, limitB.y),
265  (float)VuoReal_clamp(point.z, limitA.z, limitB.z),
266  (float)VuoReal_clamp(point.w, limitA.w, limitB.w)
267  };
268 }
269 
274 #ifdef __cplusplus
275 }
276 #endif