Vuo
2.0.2
type
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
24
37
typedef
double
VuoReal
;
38
39
VuoReal
VuoReal_makeFromJson
(
struct
json_object
*js);
40
struct
json_object
*
VuoReal_getJson
(
const
VuoReal
value);
41
char
*
VuoReal_getSummary
(
const
VuoReal
value);
42
43
VuoReal
VuoReal_min
(
VuoReal
*terms,
unsigned
long
termsCount,
VuoInteger
*outputPosition);
44
VuoReal
VuoReal_max
(
VuoReal
*terms,
unsigned
long
termsCount,
VuoInteger
*outputPosition);
45
VuoReal
VuoReal_average
(
VuoList_VuoReal
values);
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
56
VuoReal
VuoReal_makeFromString
(
const
char
*str);
57
char
*
VuoReal_getString
(
const
VuoReal
value);
58
void
VuoReal_retain
(
VuoReal
value);
59
void
VuoReal_release
(
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
));
79
static
inline
VuoReal
VuoReal_subtract
(
VuoReal
a,
VuoReal
b)
80
{
81
return
a-b;
82
}
83
89
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b)
__attribute__
((
const
));
90
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b)
91
{
92
return
a*b;
93
}
94
100
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b)
__attribute__
((
const
));
101
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b)
102
{
103
return
a*b;
104
}
105
111
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b)
__attribute__
((
const
));
112
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b)
113
{
114
return
a/b;
115
}
116
120
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a)
__attribute__
((
const
));
121
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a)
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
));
132
static
inline
VuoReal
VuoReal_distance
(
VuoReal
a,
VuoReal
b)
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
159
162
#define MIN(a,b) (((a)<(b))?(a):(b))
163
#endif
164
165
#ifndef MAX
166
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);
216
bool
VuoReal_isLessThan
(
const
VuoReal
a,
const
VuoReal
b);
217
222
#ifdef __cplusplus
223
}
224
#endif
Generated on Thu Mar 19 2020 23:16:04 for Vuo by
1.8.17