smoothie 0.3.1 → 0.3.2
raw patch · 4 files changed
+37/−1 lines, 4 filesdep +aeson
Dependencies added: aeson
Files
- CHANGELOG.md +5/−0
- smoothie.cabal +6/−1
- src/Data/Spline/Curve.hs +8/−0
- src/Data/Spline/Key.hs +18/−0
CHANGELOG.md view
@@ -1,3 +1,8 @@+## 0.3.2++- FromJSON instances for Spline.+- FromJSON instances for Key.+ ## 0.3.1 - Fixed sampling implementation.
smoothie.cabal view
@@ -1,5 +1,5 @@ name: smoothie -version: 0.3.1 +version: 0.3.2 synopsis: Smooth curves via several splines and polynomials. description: This package exports several splines and curves you can use to interpolate points in between. @@ -23,6 +23,10 @@ default-extensions: DeriveFoldable , DeriveFunctor , DeriveTraversable + , FlexibleContexts + , FlexibleInstances + , MultiWayIf + , ScopedTypeVariables exposed-modules: Data.Spline , Data.Spline.Curve @@ -32,6 +36,7 @@ build-depends: base >= 4.7 && < 5.0 , linear >= 1.16 && < 1.19 , vector >= 0.10 && < 0.11 + , aeson >= 0.9 && < 0.10 hs-source-dirs: src
src/Data/Spline/Curve.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2015 Dimitri Sabadie@@ -22,6 +24,7 @@ ) where import Control.Monad ( guard )+import Data.Aeson import Data.List ( sortBy ) import Data.Ord ( comparing ) import Data.Spline.Key as X@@ -39,6 +42,11 @@ -- |Extract the sampler. , splineSampler :: a s -> s }++instance (FromJSON (a s), Ord s) => FromJSON ((a s -> s) -> Spline a s) where+ parseJSON = withObject "spline" $ \o -> do+ keys <- o .: "keys"+ pure $ \sampler -> spline sampler keys -- |Build a 'Spline a s'. --
src/Data/Spline/Key.hs view
@@ -1,3 +1,5 @@+{-# LANGUAGE OverloadedStrings #-}+ ----------------------------------------------------------------------------- -- | -- Copyright : (C) 2015 Dimitri Sabadie@@ -17,6 +19,7 @@ , normalizeSampling ) where +import Data.Aeson import Linear -- |A 'Key' is a point on the spline with extra information added. It can be,@@ -51,6 +54,21 @@ Cosine a -> Cosine (f a) CubicHermite a -> CubicHermite (f a) Bezier l a r -> Bezier (f l) (f a) (f r)++instance (FromJSON a) => FromJSON (Key a) where+ parseJSON = withObject "key" $ \o -> do+ interpolation :: String <- o .: "interpolation"+ value <- o .: "value"+ if+ | interpolation == "hold" -> pure (Hold value)+ | interpolation == "linear" -> pure (Linear value)+ | interpolation == "cosine" -> pure (Cosine value)+ | interpolation == "cubic-hermite" -> pure (CubicHermite value)+ | interpolation == "bezier" -> do+ left <- o .: "left"+ right <- o .: "right"+ pure $ Bezier left value right+ | otherwise -> fail "unknown interpolation mode" -- |Extract the value out of a 'Key'. keyValue :: Key a -> a