module Numeric.Interpolation.Piece (
   Piece.T,
   Piece.linear,
   hermite1,
   ) where

import qualified Numeric.Interpolation.Private.Piece as Piece


{- |
Hermite interpolation with one derivative per node.
That is, the interpolating polynomial is cubic.
-}
hermite1 :: (Fractional a) => Piece.T a a (a, a)
hermite1 (x0,(y0,dy0)) (x1,(y1,dy1)) x =
   let d = (y1-y0) / dx10
       dx0 = x-x0
       dx1 = x1-x
       dx10 = x1-x0
   in  (y0*dx1 + y1*dx0 +
        ((dy0-d) * dx1 - (dy1-d) * dx0) * dx0 * dx1 / dx10)
          / dx10