Vuo
2.4.4
Loading...
Searching...
No Matches
type
VuoReal.h
Go to the documentation of this file.
1
10
#ifndef VuoReal_h
11
#define VuoReal_h
12
13
#ifdef __cplusplus
14
extern
"C"
{
15
#endif
16
17
#include "
VuoInteger.h
"
18
#include <math.h>
19
31
typedef
double
VuoReal
;
32
33
#define VuoReal_SUPPORTS_COMPARISON
34
#include "
VuoList_VuoReal.h
"
35
36
VuoReal
VuoReal_makeFromJson
(
struct
json_object *js);
37
struct
json_object *
VuoReal_getJson
(
const
VuoReal
value);
38
char
*
VuoReal_getSummary
(
const
VuoReal
value);
39
40
VuoReal
VuoReal_makeFromLocalizedText
(
const
char
*text);
41
42
VuoReal
VuoReal_minList
(
VuoList_VuoReal
values,
VuoInteger
*outputPosition);
43
VuoReal
VuoReal_maxList
(
VuoList_VuoReal
values,
VuoInteger
*outputPosition);
44
VuoReal
VuoReal_average
(
VuoList_VuoReal
values);
45
46
VuoReal
VuoReal_wrap
(
VuoReal
value,
VuoReal
minimum,
VuoReal
maximum);
47
48
VuoReal
VuoReal_random
(
const
VuoReal
minimum,
const
VuoReal
maximum);
49
VuoReal
VuoReal_randomWithState
(
unsigned
short
state[3],
const
VuoReal
minimum,
const
VuoReal
maximum);
50
52
55
char
*
VuoReal_getString
(
const
VuoReal
value);
56
void
VuoReal_retain
(
VuoReal
value);
57
void
VuoReal_release
(
VuoReal
value);
59
65
static
inline
VuoReal
VuoReal_add
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
66
static
inline
VuoReal
VuoReal_add
(
VuoReal
a,
VuoReal
b)
67
{
68
return
a+b;
69
}
70
76
static
inline
VuoReal
VuoReal_subtract
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
77
static
inline
VuoReal
VuoReal_subtract
(
VuoReal
a,
VuoReal
b)
78
{
79
return
a-b;
80
}
81
87
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
88
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b)
89
{
90
return
a*b;
91
}
92
98
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
99
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b)
100
{
101
return
a*b;
102
}
103
109
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
110
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b)
111
{
112
return
a/b;
113
}
114
118
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a) __attribute__((
const
));
119
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a)
120
{
121
if
(fabs(a) < 0.000001)
122
return
copysign(0.000001, a);
123
return
a;
124
}
125
129
static
inline
VuoReal
VuoReal_distance
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
130
static
inline
VuoReal
VuoReal_distance
(
VuoReal
a,
VuoReal
b)
131
{
132
return
sqrtf((a-b)*(a-b));
133
}
134
138
static
inline
VuoReal
VuoReal_lerp
(
VuoReal
a,
VuoReal
b,
float
t) __attribute__((
const
));
139
static
inline
VuoReal
VuoReal_lerp
(
VuoReal
a,
VuoReal
b,
float
t)
140
{
141
return
a*(1-t) + b*t;
142
}
143
147
static
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
174
static
inline
VuoReal
VuoReal_clamp
(
VuoReal
value,
VuoReal
limitA,
VuoReal
limitB)
175
{
176
return
MIN
(
MAX
(value,
MIN
(limitA, limitB)),
MAX
(limitA,limitB));
177
}
178
183
static
inline
VuoReal
VuoReal_clampn
(
VuoReal
value,
VuoReal
limitA,
VuoReal
limitB)
184
{
185
return
VuoReal_clamp
(value, limitA, limitB);
186
}
187
197
static
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
205
static
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
211
bool
VuoReal_areEqual
(
const
VuoReal
value1,
const
VuoReal
value2);
212
bool
VuoReal_areEqualListWithinTolerance
(
VuoList_VuoReal
values,
VuoReal
tolerance);
213
bool
VuoReal_isLessThan
(
const
VuoReal
a,
const
VuoReal
b);
214
bool
VuoReal_isWithinRange
(
VuoReal
value,
VuoReal
minimum,
VuoReal
maximum);
215
220
#ifdef __cplusplus
221
}
222
#endif
223
224
#endif
Generated on Thu Nov 9 2023 16:59:30 for Vuo by
1.9.8