diff --git a/src/Linear/Vector/Compat.hs b/src/Linear/Vector/Compat.hs new file mode 100644 index 00000000..673853dd --- /dev/null +++ b/src/Linear/Vector/Compat.hs @@ -0,0 +1,24 @@ +{-# LANGUAGE CPP #-} + +-- | +-- Module : Linear.Vector.Compat +-- Copyright : (c) 2024 diagrams-lib team (see LICENSE) +-- License : BSD-style (see LICENSE) +-- Maintainer : diagrams-discuss@googlegroups.com +-- +-- Compatibility layer for working with versions of linear both before +-- (< 1.23) and after (>= 1.23) the interpolation direction of `lerp` +-- was reversed. +module Linear.Vector.Compat (lerp) where + +import qualified Linear.Vector as V + +-- | Linearly interpolate between two vectors, such that @lerp 0 x y = +-- x@ and @lerp 1 x y = 1@. +lerp :: (V.Additive f, Num a) => a -> f a -> f a -> f a +lerp = +#if MIN_VERSION_linear(1,23,0) + V.lerp +#else + V.lerp . (1-) +#endif