mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-05 00:21:29 +00:00
f728923c79
This is not really related to struct dive, so let's move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
16 lines
474 B
C
16 lines
474 B
C
// SPDX-License-Identifier: GPL-2.0
|
|
#ifndef INTERPOLATE_H
|
|
#define INTERPOLATE_H
|
|
|
|
/* Linear interpolation between 'a' and 'b', when we are 'part'way into the 'whole' distance from a to b */
|
|
static inline int interpolate(int a, int b, int part, int whole)
|
|
{
|
|
/* It is doubtful that we actually need floating point for this, but whatever */
|
|
if (whole) {
|
|
double x = (double)a * (whole - part) + (double)b * part;
|
|
return (int)lrint(x / whole);
|
|
}
|
|
return (a+b)/2;
|
|
}
|
|
|
|
#endif
|