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