libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
|
Go to the source code of this file.
Data Structures | |
struct | pn_interp_t |
Macros | |
#define | POW4(x) ((x) * (x) * (x) * (x)) |
#define | POW3(x) ((x) * (x) * (x)) |
#define | POW2(x) ((x) * (x)) |
#define | ABS(x) ((x) > 0 ? (x) : -(x)) |
#define | wavg(x, y, w) wavg_impl((x), (y), (w), __FILE__, __LINE__) |
#define | MAX_PN_INTERP_ORDER 64 |
#define | HROUND2(oldval, newval, step, hyst_rng) |
#define | HROUND(oldval, newval, step) HROUND2((oldval), (newval), (step), 0.35) |
Functions | |
unsigned | quadratic_solve (double a, double b, double c, double x[2]) |
double | fx_lin (double x, double x1, double y1, double x2, double y2) |
double | fx_lin_multi (double x, const struct vect2_s *points, bool_t extrapolate) |
double | fx_lin_multi2 (double x, const struct vect2_s *points, size_t n_points, bool_t extrapolate) |
double * | fx_lin_multi_inv (double y, const struct vect2_s *points, size_t *num_out) |
double * | fx_lin_multi_inv2 (double y, const struct vect2_s *points, bool_t extrapolate, size_t *num_out) |
double * | fx_lin_multi_inv3 (double y, const struct vect2_s *points, size_t n_points, bool_t extrapolate, size_t *num_out) |
static double | wavg_impl (double x, double y, double w, const char *file, int line) |
static double | wavg2 (double x, double y, double w) |
static double | iter_fract (double x, double min_val, double max_val, bool_t clamp_output) |
void | pn_interp_init (pn_interp_t *interp, const vect2_t *points, unsigned npts) |
static double | pn_interp_run (double x, const pn_interp_t *interp) |
static double | smoothstep (double x, double edge0, double edge1) |
static double | smoothstep_inv (double x) |
#define ABS | ( | x | ) | ((x) > 0 ? (x) : -(x)) |
#define HROUND | ( | oldval, | |
newval, | |||
step | |||
) | HROUND2((oldval), (newval), (step), 0.35) |
#define HROUND2 | ( | oldval, | |
newval, | |||
step, | |||
hyst_rng | |||
) |
Hysterhesis-rounding macro. Given an old value, new value, rounding step and hysterhesis range, performs the following:
newval
to the nearest multiple of step
oldval
is NAN, it simply adops the new rounded valueoldval
by at least half step plus the hysterhesis range fraction, then oldval
is set to the new rounded value, otherwise it stays put.The purpose of this macro is to make oldval
change in fixed steps, but avoid oscillation if the new value is right in the middle between two step sizes:
The HROUND2() macro provides an additional "buffer" zone around the midpoint of the step, to avoid this oscillation:
#define POW3 | ( | x | ) | ((x) * (x) * (x)) |
#define POW4 | ( | x | ) | ((x) * (x) * (x) * (x)) |
#define wavg | ( | x, | |
y, | |||
w | |||
) | wavg_impl((x), (y), (w), __FILE__, __LINE__) |
double fx_lin | ( | double | x, |
double | x1, | ||
double | y1, | ||
double | x2, | ||
double | y2 | ||
) |
Interpolates a linear function defined by two points.
x | Point who's 'y' value we're looking for on the function. |
x1 | First reference point's x coordinate. |
y1 | First reference point's y coordinate. |
x2 | Second reference point's x coordinate. |
y2 | Second reference point's y coordinate. |
double fx_lin_multi | ( | double | x, |
const struct vect2_s * | points, | ||
bool_t | extrapolate | ||
) |
Multi-segment version of fx_lin. The segments are defined as a series of x-y coordinate points (list terminated with a NULL_VECT2). The list must contain AT LEAST 2 points. The value of 'x' is then computed using the fx_lin function from the appropriate segment. If 'x' falls outside of the curve range, the ‘extrapolate’ argument controls behavior. If extrapolate is B_TRUE, the nearest segment is extrapolated to the value of 'x'. Otherwise the function returns NAN.
double fx_lin_multi2 | ( | double | x, |
const struct vect2_s * | points, | ||
size_t | n_points, | ||
bool_t | extrapolate | ||
) |
Multi-segment version of fx_lin. The segments are defined as a series of x-y coordinate points. The list must contain AT LEAST 2 points. The value of 'x' is then computed using the fx_lin function from the appropriate segment. If 'x' falls outside of the curve range, the extrapolate
argument controls behavior. If extrapolate is B_TRUE
, the nearest segment is extrapolated to the value of 'x'. Otherwise the function returns NAN
.
double * fx_lin_multi_inv | ( | double | y, |
const struct vect2_s * | points, | ||
size_t * | num_out | ||
) |
The inverse of fx_lin_multi(). This attempts to invert the output of a function defined by points
(terminated by a NULL_VECT2 element) into the possible input x
elements. If the function isn't monotonic, this function may need to return multiple points. If the output Y value isn't found anywhere on the input function, this function returns NULL and num_out
is set to zero. Use fx_lin_multi_inv2() for explicit extrapolation control.
y | The output Y value of the original function for which to perform the inverse lookup. |
points | Sequence of at least 2 points, which define the function. The list must be terminated by a NULL_VECT2 point. |
num_out | Return argument, which will be filled with the number of returned points. |
num_out
. You MUST free this list when you're done with it by calling lacf_free(). double * fx_lin_multi_inv2 | ( | double | y, |
const struct vect2_s * | points, | ||
bool_t | extrapolate, | ||
size_t * | num_out | ||
) |
Same as fx_lin_multi_inv(), but allows you to control extrapolation of the function. If extrapolate=B_TRUE
, then the edges of the function definition in points
are extrapolated, to see if they might intersect the Y value. Please note that this doesn't guarantee that you'll get a non-zero number of X points out of the function (e.g. if the function lies entirely on one side of a boundary value and reverses away from the boundary condition on both sides, solving for a Y past the boundary value will still return no results).
double * fx_lin_multi_inv3 | ( | double | y, |
const struct vect2_s * | points, | ||
size_t | n_points, | ||
bool_t | extrapolate, | ||
size_t * | num_out | ||
) |
|
static |
Given two values min_val and max_val, returns how far between min_val and max_val a third value 'x' lies. If ‘clamp_output’ is true, 'x' is clamped such that it always lies between min_val and max_val. In essence, this function computes:
void pn_interp_init | ( | pn_interp_t * | interp, |
const vect2_t * | points, | ||
unsigned | numpts | ||
) |
Given a series of X-Y coordinates, this function initializes a polynomial interpolator that smoothly passes through all the input points. When you are done with the interpolator, you DON'T have to free it. The pn_interp_t structure is entirely self-contained.
Algorithm credit: https://en.wikibooks.org/wiki/\ Algorithm_Implementation/Mathematics/Polynomial_interpolation
interp | Interpolator that needs to be initialized. |
points | Input points that the interpolator needs to pass through. |
npts | Number points in ‘points’. This must be GREATER than 0. |
|
static |
Given an initialized pn_interp_t, calculates the Y value at a given point.
x | The X point for which to calculate the interpolated Y value. |
interp | An initialized interpolator (see pn_interp_init()). |
unsigned quadratic_solve | ( | double | a, |
double | b, | ||
double | c, | ||
double | x[2] | ||
) |
|
static |
Implements the smoothstep function from GLSL. See Wikipedia for more info: https://en.wikipedia.org/wiki/Smoothstep
|
static |
Inverse of smoothstep(). The returned value is always in the range of 0-1.
|
static |