Vuo 2.4.4
Loading...
Searching...
No Matches
VuoReal.h
Go to the documentation of this file.
1
10#ifndef VuoReal_h
11#define VuoReal_h
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17#include "VuoInteger.h"
18#include <math.h>
19
31typedef double VuoReal;
32
33#define VuoReal_SUPPORTS_COMPARISON
34#include "VuoList_VuoReal.h"
35
36VuoReal VuoReal_makeFromJson(struct json_object *js);
37struct json_object * VuoReal_getJson(const VuoReal value);
38char * VuoReal_getSummary(const VuoReal value);
39
41
42VuoReal VuoReal_minList(VuoList_VuoReal values, VuoInteger *outputPosition);
43VuoReal VuoReal_maxList(VuoList_VuoReal values, VuoInteger *outputPosition);
45
46VuoReal VuoReal_wrap(VuoReal value, VuoReal minimum, VuoReal maximum);
47
48VuoReal VuoReal_random(const VuoReal minimum, const VuoReal maximum);
49VuoReal VuoReal_randomWithState(unsigned short state[3], const VuoReal minimum, const VuoReal maximum);
50
52
55char * VuoReal_getString(const VuoReal value);
59
65static inline VuoReal VuoReal_add(VuoReal a, VuoReal b) __attribute__((const));
67{
68 return a+b;
69}
70
76static inline VuoReal VuoReal_subtract(VuoReal a, VuoReal b) __attribute__((const));
78{
79 return a-b;
80}
81
87static inline VuoReal VuoReal_multiply(VuoReal a, VuoReal b) __attribute__((const));
89{
90 return a*b;
91}
92
98static inline VuoReal VuoReal_scale(VuoReal a, VuoReal b) __attribute__((const));
100{
101 return a*b;
102}
103
109static inline VuoReal VuoReal_divide(VuoReal a, VuoReal b) __attribute__((const));
111{
112 return a/b;
113}
114
118static inline VuoReal VuoReal_makeNonzero(VuoReal a) __attribute__((const));
120{
121 if (fabs(a) < 0.000001)
122 return copysign(0.000001, a);
123 return a;
124}
125
129static inline VuoReal VuoReal_distance(VuoReal a, VuoReal b) __attribute__((const));
131{
132 return sqrtf((a-b)*(a-b));
133}
134
138static inline VuoReal VuoReal_lerp(VuoReal a, VuoReal b, float t) __attribute__((const));
139static inline VuoReal VuoReal_lerp(VuoReal a, VuoReal b, float t)
140{
141 return a*(1-t) + b*t;
142}
143
147static inline VuoReal VuoReal_spring(VuoReal timeSinceDrop, VuoReal dropPosition, VuoReal restingPosition, VuoReal period, VuoReal damping)
148{
149 // Based on https://en.wikibooks.org/wiki/Control_Systems/Examples/Second_Order_Systems#Task_2
150 double t = 2*M_PI*timeSinceDrop/period;
151 double d = sqrt(1-pow(damping,2));
152 double p = exp(-damping * t) * sin(d * t + asin(d)) / d;
153 return VuoReal_lerp(restingPosition, dropPosition, p);
154}
155
156#ifndef MIN
160#define MIN(a,b) (((a)<(b))?(a):(b))
161#endif
162
163#ifndef MAX
167#define MAX(a,b) (((a)>(b))?(a):(b))
168#endif
169
174static inline VuoReal VuoReal_clamp(VuoReal value, VuoReal limitA, VuoReal limitB)
175{
176 return MIN(MAX(value, MIN(limitA, limitB)), MAX(limitA,limitB));
177}
178
183static inline VuoReal VuoReal_clampn(VuoReal value, VuoReal limitA, VuoReal limitB)
184{
185 return VuoReal_clamp(value, limitA, limitB);
186}
187
197static inline VuoReal VuoReal_bezier3(VuoReal p0, VuoReal p1, VuoReal p2, VuoReal p3, VuoReal time)
198{
199 return p0*pow(1-time,3) + 3.*p1*pow(1-time,2)*time + 3.*p2*(1-time)*pow(time,2) + p3*pow(time,3);
200}
201
205static inline VuoReal VuoReal_snap(VuoReal a, VuoReal center, VuoReal snap)
206{
207 VuoReal nonzeroSnap = VuoReal_makeNonzero(snap);
208 return center + nonzeroSnap * (int)round( (a-center) / nonzeroSnap );
209}
210
211bool VuoReal_areEqual(const VuoReal value1, const VuoReal value2);
213bool VuoReal_isLessThan(const VuoReal a, const VuoReal b);
214bool VuoReal_isWithinRange(VuoReal value, VuoReal minimum, VuoReal maximum);
215
220#ifdef __cplusplus
221}
222#endif
223
224#endif