Vuo  2.3.2
VuoReal.h
Go to the documentation of this file.
1 
10 #pragma once
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 #include "VuoInteger.h"
17 #include <math.h>
18 #include <stdbool.h>
19 struct json_object;
20 
22 typedef const struct VuoList_VuoReal_struct { void *l; } * VuoList_VuoReal;
23 #define VuoList_VuoReal_TYPE_DEFINED
25 
37 typedef double VuoReal;
38 
40 struct json_object * VuoReal_getJson(const VuoReal value);
41 char * VuoReal_getSummary(const VuoReal value);
42 
43 VuoReal VuoReal_minList(VuoList_VuoReal values, VuoInteger *outputPosition);
44 VuoReal VuoReal_maxList(VuoList_VuoReal values, VuoInteger *outputPosition);
46 
47 VuoReal VuoReal_wrap(VuoReal value, VuoReal minimum, VuoReal maximum);
48 
49 VuoReal VuoReal_random(const VuoReal minimum, const VuoReal maximum);
50 VuoReal VuoReal_randomWithState(unsigned short state[3], const VuoReal minimum, const VuoReal maximum);
51 
53 
57 char * VuoReal_getString(const VuoReal value);
58 void VuoReal_retain(VuoReal value);
61 
67 static inline VuoReal VuoReal_add(VuoReal a, VuoReal b) __attribute__((const));
68 static inline VuoReal VuoReal_add(VuoReal a, VuoReal b)
69 {
70  return a+b;
71 }
72 
78 static inline VuoReal VuoReal_subtract(VuoReal a, VuoReal b) __attribute__((const));
80 {
81  return a-b;
82 }
83 
89 static inline VuoReal VuoReal_multiply(VuoReal a, VuoReal b) __attribute__((const));
91 {
92  return a*b;
93 }
94 
100 static inline VuoReal VuoReal_scale(VuoReal a, VuoReal b) __attribute__((const));
102 {
103  return a*b;
104 }
105 
111 static inline VuoReal VuoReal_divide(VuoReal a, VuoReal b) __attribute__((const));
113 {
114  return a/b;
115 }
116 
120 static inline VuoReal VuoReal_makeNonzero(VuoReal a) __attribute__((const));
122 {
123  if (fabs(a) < 0.000001)
124  return copysign(0.000001, a);
125  return a;
126 }
127 
131 static inline VuoReal VuoReal_distance(VuoReal a, VuoReal b) __attribute__((const));
133 {
134  return sqrtf((a-b)*(a-b));
135 }
136 
140 static inline VuoReal VuoReal_lerp(VuoReal a, VuoReal b, float t) __attribute__((const));
141 static inline VuoReal VuoReal_lerp(VuoReal a, VuoReal b, float t)
142 {
143  return a*(1-t) + b*t;
144 }
145 
149 static inline VuoReal VuoReal_spring(VuoReal timeSinceDrop, VuoReal dropPosition, VuoReal restingPosition, VuoReal period, VuoReal damping)
150 {
151  // Based on https://en.wikibooks.org/wiki/Control_Systems/Examples/Second_Order_Systems#Task_2
152  double t = 2*M_PI*timeSinceDrop/period;
153  double d = sqrt(1-pow(damping,2));
154  double p = exp(-damping * t) * sin(d * t + asin(d)) / d;
155  return VuoReal_lerp(restingPosition, dropPosition, p);
156 }
157 
158 #ifndef MIN
162 #define MIN(a,b) (((a)<(b))?(a):(b))
163 #endif
164 
165 #ifndef MAX
169 #define MAX(a,b) (((a)>(b))?(a):(b))
170 #endif
171 
176 static inline VuoReal VuoReal_clamp(VuoReal value, VuoReal limitA, VuoReal limitB)
177 {
178  return MIN(MAX(value, MIN(limitA, limitB)), MAX(limitA,limitB));
179 }
180 
185 static inline VuoReal VuoReal_clampn(VuoReal value, VuoReal limitA, VuoReal limitB)
186 {
187  return VuoReal_clamp(value, limitA, limitB);
188 }
189 
199 static inline VuoReal VuoReal_bezier3(VuoReal p0, VuoReal p1, VuoReal p2, VuoReal p3, VuoReal time)
200 {
201  return p0*pow(1-time,3) + 3.*p1*pow(1-time,2)*time + 3.*p2*(1-time)*pow(time,2) + p3*pow(time,3);
202 }
203 
207 static inline VuoReal VuoReal_snap(VuoReal a, VuoReal center, VuoReal snap)
208 {
209  VuoReal nonzeroSnap = VuoReal_makeNonzero(snap);
210  return center + nonzeroSnap * (int)round( (a-center) / nonzeroSnap );
211 }
212 
214 #define VuoReal_SUPPORTS_COMPARISON
215 bool VuoReal_areEqual(const VuoReal value1, const VuoReal value2);
217 bool VuoReal_isLessThan(const VuoReal a, const VuoReal b);
218 bool VuoReal_isWithinRange(VuoReal value, VuoReal minimum, VuoReal maximum);
219 
224 #ifdef __cplusplus
225 }
226 #endif