module Wumpus.Basic.Kernel.Base.Units
(
Centimeter
, cm
, dcm
, Pica
, pica
, dpica
, Em
, En
) where
import Wumpus.Basic.Kernel.Base.BaseDefs
import Wumpus.Core
newtype Centimeter = Centimeter { getCentimeter :: Double }
deriving (Eq,Ord,Num,Floating,Fractional,Real,RealFrac,RealFloat)
instance Show Centimeter where
showsPrec p d = showsPrec p (getCentimeter d)
cm :: Fractional u => Centimeter -> u
cm = realToFrac . (28.45275619 *) . getCentimeter
dcm :: Double -> Centimeter
dcm = Centimeter . (0.03514598 *)
instance ScalarUnit Centimeter where
fromPsPoint = dcm
toPsPoint = cm
instance InterpretUnit Centimeter where
normalize _ = cm
dinterp _ = dcm
newtype Pica = Pica { getPica :: Double }
deriving (Eq,Ord,Num,Floating,Fractional,Real,RealFrac,RealFloat)
instance Show Pica where
showsPrec p d = showsPrec p (getPica d)
pica :: Fractional u => Pica -> u
pica = realToFrac . (* 12.0) . getPica
dpica :: Double -> Pica
dpica = Pica . (\x -> x / 12.0)
instance Tolerance Pica where
eq_tolerance = 0.001
length_tolerance = 0.01
instance ScalarUnit Pica where
fromPsPoint = dpica
toPsPoint = pica
instance InterpretUnit Pica where
normalize _ = pica
dinterp _ = dpica
newtype Em = Em { getEm :: Double }
deriving (Eq,Ord,Num,Floating,Fractional,Real,RealFrac,RealFloat)
instance Show Em where
showsPrec p d = showsPrec p (getEm d)
instance InterpretUnit Em where
normalize sz a = fromIntegral sz * realToFrac a
dinterp sz d = realToFrac d / fromIntegral sz
instance Tolerance Centimeter where
eq_tolerance = 0.001
length_tolerance = 0.01
newtype En = En { getEn :: Double }
deriving (Eq,Ord,Num,Floating,Fractional,Real,RealFrac,RealFloat)
instance Show En where
showsPrec p d = showsPrec p (getEn d)
instance InterpretUnit En where
normalize sz a = (realToFrac a) * 0.5 * fromIntegral sz
dinterp sz d = 2 * (realToFrac d) / (fromIntegral sz)
instance Tolerance Em where
eq_tolerance = 0.001
length_tolerance = 0.01
instance Tolerance En where
eq_tolerance = 0.001
length_tolerance = 0.01