Vuo
2.4.1
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
25
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_minList
(
VuoList_VuoReal
values,
VuoInteger
*outputPosition);
44
VuoReal
VuoReal_maxList
(
VuoList_VuoReal
values,
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
char
*
VuoReal_getString
(
const
VuoReal
value);
57
void
VuoReal_retain
(
VuoReal
value);
58
void
VuoReal_release
(
VuoReal
value);
60
66
static
inline
VuoReal
VuoReal_add
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
67
static
inline
VuoReal
VuoReal_add
(
VuoReal
a,
VuoReal
b)
68
{
69
return
a+b;
70
}
71
77
static
inline
VuoReal
VuoReal_subtract
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
78
static
inline
VuoReal
VuoReal_subtract
(
VuoReal
a,
VuoReal
b)
79
{
80
return
a-b;
81
}
82
88
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
89
static
inline
VuoReal
VuoReal_multiply
(
VuoReal
a,
VuoReal
b)
90
{
91
return
a*b;
92
}
93
99
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
100
static
inline
VuoReal
VuoReal_scale
(
VuoReal
a,
VuoReal
b)
101
{
102
return
a*b;
103
}
104
110
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
111
static
inline
VuoReal
VuoReal_divide
(
VuoReal
a,
VuoReal
b)
112
{
113
return
a/b;
114
}
115
119
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a) __attribute__((
const
));
120
static
inline
VuoReal
VuoReal_makeNonzero
(
VuoReal
a)
121
{
122
if
(fabs(a) < 0.000001)
123
return
copysign(0.000001, a);
124
return
a;
125
}
126
130
static
inline
VuoReal
VuoReal_distance
(
VuoReal
a,
VuoReal
b) __attribute__((
const
));
131
static
inline
VuoReal
VuoReal_distance
(
VuoReal
a,
VuoReal
b)
132
{
133
return
sqrtf((a-b)*(a-b));
134
}
135
139
static
inline
VuoReal
VuoReal_lerp
(
VuoReal
a,
VuoReal
b,
float
t) __attribute__((
const
));
140
static
inline
VuoReal
VuoReal_lerp
(
VuoReal
a,
VuoReal
b,
float
t)
141
{
142
return
a*(1-t) + b*t;
143
}
144
148
static
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
175
static
inline
VuoReal
VuoReal_clamp
(
VuoReal
value,
VuoReal
limitA,
VuoReal
limitB)
176
{
177
return
MIN
(
MAX
(value,
MIN
(limitA, limitB)),
MAX
(limitA,limitB));
178
}
179
184
static
inline
VuoReal
VuoReal_clampn
(
VuoReal
value,
VuoReal
limitA,
VuoReal
limitB)
185
{
186
return
VuoReal_clamp
(value, limitA, limitB);
187
}
188
198
static
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
206
static
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
214
bool
VuoReal_areEqual
(
const
VuoReal
value1,
const
VuoReal
value2);
215
bool
VuoReal_areEqualListWithinTolerance
(
VuoList_VuoReal
values,
VuoReal
tolerance);
216
bool
VuoReal_isLessThan
(
const
VuoReal
a,
const
VuoReal
b);
217
bool
VuoReal_isWithinRange
(
VuoReal
value,
VuoReal
minimum,
VuoReal
maximum);
218
223
#ifdef __cplusplus
224
}
225
#endif
Generated on Mon Feb 7 2022 18:55:37 for Vuo by
1.9.3