From 88313f10778f22c77e9a8615f886da7b798ef023 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 8 Jan 2013 15:48:23 -0800 Subject: 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 Signed-off-by: Dirk Hohndel --- planner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'planner.c') diff --git a/planner.c b/planner.c index b05980648..28c8e34a2 100644 --- a/planner.c +++ b/planner.c @@ -99,7 +99,7 @@ double tissue_at_end(struct dive *dive, char **cached_datap) if (i > 0) lastdepth = psample->depth.mm; for (j = t0; j < t1; j++) { - int depth = lastdepth + (j - t0) * (sample->depth.mm - lastdepth) / (t1 - t0); + int depth = interpolate(lastdepth, sample->depth.mm, j - t0, t1 - t0); tissue_tolerance = add_segment(depth_to_mbar(depth, dive) / 1000.0, &dive->cylinder[gasidx].gasmix, 1, sample->po2, dive); } -- cgit v1.2.3-70-g09d2