module Helpers
( roundToStr
, fta
, applyAttrs
, degToRad
, radToDeg
, vectorToFloats ) where
import Numeric.LinearAlgebra.Data (Vector, R, toList)
import qualified Text.Blaze.Svg11 as S
import Text.Printf
roundToStr :: (PrintfArg a, Floating a) => Int -> a -> String
roundToStr = printf "%0.*f"
fta :: Float -> S.AttributeValue
fta f = S.stringValue (roundToStr 6 f)
applyAttrs :: [S.Attribute] -> S.Svg -> S.Svg
applyAttrs attributes element = foldr (flip (S.!)) element attributes
radToDeg :: Float -> Float
radToDeg radians = radians * 180 / pi
degToRad :: Float -> Float
degToRad degrees = degrees * pi / 180
vectorToFloats :: Vector R -> [Float]
vectorToFloats = map realToFrac . toList