-- | Geometric functions concerning angles. If not otherwise specified, all angles are in radians.
module Graphics.Gloss.Geometry.Angle
        ( degToRad
        , radToDeg
        , normalizeAngle )
where

-- | Convert degrees to radians
degToRad :: Float -> Float
degToRad :: Float -> Float
degToRad Float
d      = Float
d Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
forall a. Floating a => a
pi Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
180
{-# INLINE degToRad #-}


-- | Convert radians to degrees
radToDeg :: Float -> Float
radToDeg :: Float -> Float
radToDeg Float
r      = Float
r Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
180 Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ Float
forall a. Floating a => a
pi
{-# INLINE radToDeg #-}


-- | Normalize an angle to be between 0 and 2*pi radians
normalizeAngle :: Float -> Float
normalizeAngle :: Float -> Float
normalizeAngle Float
f = Float
f Float -> Float -> Float
forall a. Num a => a -> a -> a
- Float
2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
forall a. Floating a => a
pi Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float -> Float
floor' (Float
f Float -> Float -> Float
forall a. Fractional a => a -> a -> a
/ (Float
2 Float -> Float -> Float
forall a. Num a => a -> a -> a
* Float
forall a. Floating a => a
pi))
 where  floor' :: Float -> Float
        floor' :: Float -> Float
floor' Float
x = Int -> Float
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Float -> Int
forall a b. (RealFrac a, Integral b) => a -> b
floor Float
x :: Int)
{-# INLINE normalizeAngle #-}