diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2013-01-08 15:48:23 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-01-09 16:17:57 -0800 |
commit | 88313f10778f22c77e9a8615f886da7b798ef023 (patch) | |
tree | 5eb46f459516182cf93ba13a8dbb47ebd309b15f /divelist.c | |
parent | c0ce218df494a527111ce9180aef84ea0d34e333 (diff) | |
download | subsurface-88313f10778f22c77e9a8615f886da7b798ef023.tar.gz |
Clean up duplicated depth interpolation
We have several places where we interpolate the depth based on two
samples and the time between them. Some of them use floating point, some
of them don't, some of them meant to do it but didn't.
Just use a common helper function for it. I seriously doubt the floating
point here really matters, since doing it in integers is not going to
overflow unless we're interpolating between two samples that are hours
apart at hundreds of meters of depth, but hey, it gives that rounding to
the nearest millimeter. Which I'm sure matters.
Anyway, we can probably just get rid of the rounding and the floating
point math, but it won't really hurt either, so at least do it
consistently.
The interpolation could be for other things than just depth, but we
probably don't have anything else we'd want to interpolate. But make the
function naming generic just in case.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'divelist.c')
-rw-r--r-- | divelist.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/divelist.c b/divelist.c index aaf7d2fcb..024d9bfb3 100644 --- a/divelist.c +++ b/divelist.c @@ -834,8 +834,7 @@ static void add_dive_to_deco(struct dive *dive) int j; for (j = t0; j < t1; j++) { - int depth = 0.5 + psample->depth.mm + (j - t0) * - (sample->depth.mm - psample->depth.mm) / (t1 - t0); + int depth = interpolate(psample->depth.mm, sample->depth.mm, j - t0, t1 - t0); (void) add_segment(depth_to_mbar(depth, dive) / 1000.0, &dive->cylinder[sample->sensor].gasmix, 1, sample->po2 / 1000.0, dive); } |