"""Linear interpolation between six nominal 12-second sample centres."""
from itertools import product

def half_max_width(values):
    _, e, q, u, j, last = values
    half = u / 2
    rising = 12 + 12 * (half - e) / (q - e)
    falling = 48 + 12 * (j - half) / (j - last)
    return falling - rising

lower = (6, 14, 26, 30, 19, 5)
print("midpoint width (seconds):", half_max_width([n + 0.5 for n in lower]))
# Each crossing is monotone in its endpoint heights and in the half-height.
# Upper bin edges are limits because the original values were truncated.
widths = [
    half_max_width([n + offset for n, offset in zip(lower, offsets)])
    for offsets in product((0, 1), repeat=len(lower))
]
print("limiting widths (seconds):", min(widths), max(widths))
