Vuo  2.0.0
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 VuoPoint3d VuoPoint4d_to3d(VuoPoint4d p) __attribute__((const));
69 static inline VuoPoint3d VuoPoint4d_to3d(VuoPoint4d p)
70 {
71  return (VuoPoint3d){p.x, p.y, p.z};
72 }
73 
79 static inline VuoPoint4d VuoPoint3d_to4d1(VuoPoint3d p) __attribute__((const));
80 static inline VuoPoint4d VuoPoint3d_to4d1(VuoPoint3d p)
81 {
82  return (VuoPoint4d){p.x, p.y, p.z, 1};
83 }
84 
88 static inline VuoPoint4d VuoPoint4d_crossProduct(VuoPoint4d u, VuoPoint4d v) __attribute__((const));
89 static inline VuoPoint4d VuoPoint4d_crossProduct(VuoPoint4d u, VuoPoint4d v)
90 {
91  return (VuoPoint4d){
92  u.y*v.z - u.z*v.y,
93  u.z*v.x - u.x*v.z,
94  u.x*v.y - u.y*v.x,
95  1.
96  };
97 }
98 
102 static inline float VuoPoint4d_dotProduct(VuoPoint4d u, VuoPoint4d v) __attribute__((const));
103 static inline float VuoPoint4d_dotProduct(VuoPoint4d u, VuoPoint4d v)
104 {
105  return u.x*v.x + u.y*v.y + u.z*v.z + u.w*v.w;
106 }
107 
108 
112 static inline float VuoPoint4d_magnitude(VuoPoint4d a) __attribute__((const));
113 static inline float VuoPoint4d_magnitude(VuoPoint4d a)
114 {
115  return sqrtf(a.x*a.x + a.y*a.y + a.z*a.z + a.w*a.w);
116 }
117 
121 static inline VuoPoint4d VuoPoint4d_normalize3d(VuoPoint4d a) __attribute__((const));
122 static inline VuoPoint4d VuoPoint4d_normalize3d(VuoPoint4d a)
123 {
124  VuoPoint3d p = a.xyz / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z);
125  return (VuoPoint4d){p.x, p.y, p.z, a.w};
126 }
127 
131 static inline VuoPoint4d VuoPoint4d_normalize(VuoPoint4d a) __attribute__((const));
132 static inline VuoPoint4d VuoPoint4d_normalize(VuoPoint4d a)
133 {
134  return a / sqrtf(a.x * a.x + a.y * a.y + a.z * a.z + a.w * a.w);
135 }
136 
140 static inline VuoPoint4d VuoPoint4d_add(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
141 static inline VuoPoint4d VuoPoint4d_add(VuoPoint4d a, VuoPoint4d b)
142 {
143  return a + b;
144 }
145 
149 static inline VuoPoint4d VuoPoint4d_subtract(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
150 static inline VuoPoint4d VuoPoint4d_subtract(VuoPoint4d a, VuoPoint4d b)
151 {
152  return a - b;
153 }
154 
158 static inline float VuoPoint4d_squaredMagnitude(VuoPoint4d a) __attribute__((const));
159 static inline float VuoPoint4d_squaredMagnitude(VuoPoint4d a)
160 {
161  return (a.x*a.x + a.y*a.y + a.z*a.z + a.w*a.w);
162 }
163 
164 
168 static inline VuoPoint4d VuoPoint4d_divide(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
169 static inline VuoPoint4d VuoPoint4d_divide(VuoPoint4d a, VuoPoint4d b)
170 {
171  return a / b;
172 }
173 
177 static inline VuoPoint4d VuoPoint4d_multiply(VuoPoint4d a, float b) __attribute__((const));
178 static inline VuoPoint4d VuoPoint4d_multiply(VuoPoint4d a, float b)
179 {
180  return a * b;
181 }
182 
186 static inline VuoPoint4d VuoPoint4d_scale(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
187 static inline VuoPoint4d VuoPoint4d_scale(VuoPoint4d a, VuoPoint4d b)
188 {
189  return a * b;
190 }
191 
195 static inline VuoPoint4d VuoPoint4d_makeNonzero(VuoPoint4d a) __attribute__((const));
196 static inline VuoPoint4d VuoPoint4d_makeNonzero(VuoPoint4d a)
197 {
198  if (fabs(a.x) < 0.000001)
199  a.x = copysign(0.000001, a.x);
200  if (fabs(a.y) < 0.000001)
201  a.y = copysign(0.000001, a.y);
202  if (fabs(a.z) < 0.000001)
203  a.z = copysign(0.000001, a.z);
204  if (fabs(a.w) < 0.000001)
205  a.w = copysign(0.000001, a.w);
206  return a;
207 }
208 
212 static inline float VuoPoint4d_distance(VuoPoint4d a, VuoPoint4d b) __attribute__((const));
213 static inline float VuoPoint4d_distance(VuoPoint4d a, VuoPoint4d b)
214 {
215  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));
216 }
217 
221 static inline VuoPoint4d VuoPoint4d_snap(VuoPoint4d a, VuoPoint4d center, VuoPoint4d snap) __attribute__((const));
222 static inline VuoPoint4d VuoPoint4d_snap(VuoPoint4d a, VuoPoint4d center, VuoPoint4d snap)
223 {
224  VuoPoint4d nonzeroSnap = VuoPoint4d_makeNonzero(snap);
225  return (VuoPoint4d) {
226  center.x + nonzeroSnap.x * (int)round((a.x-center.x) / nonzeroSnap.x),
227  center.y + nonzeroSnap.y * (int)round((a.y-center.y) / nonzeroSnap.y),
228  center.z + nonzeroSnap.z * (int)round((a.z-center.z) / nonzeroSnap.z),
229  center.w + nonzeroSnap.w * (int)round((a.w-center.w) / nonzeroSnap.w)
230  };
231 }
232 
233 
237 static inline VuoPoint4d VuoPoint4d_clampn(VuoPoint4d point, VuoPoint4d limitA, VuoPoint4d limitB)
238 {
239  return (VuoPoint4d){
240  (float)VuoReal_clamp(point.x, limitA.x, limitB.x),
241  (float)VuoReal_clamp(point.y, limitA.y, limitB.y),
242  (float)VuoReal_clamp(point.z, limitA.z, limitB.z),
243  (float)VuoReal_clamp(point.w, limitA.w, limitB.w)
244  };
245 }
246 
251 #ifdef __cplusplus
252 }
253 #endif