{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeSynonymInstances #-}
module Diagrams.TwoD.Ellipse
(
unitCircle
, circle
, ellipse
, ellipseXY
) where
import Diagrams.Core
import Diagrams.Angle
import Diagrams.Located (at)
import Diagrams.Trail (glueTrail)
import Diagrams.TrailLike
import Diagrams.TwoD.Arc
import Diagrams.TwoD.Transform
import Diagrams.TwoD.Types
import Diagrams.TwoD.Vector (xDir)
import Diagrams.Util
unitCircle :: (TrailLike t, V t ~ V2, N t ~ n) => t
unitCircle = trailLike $ glueTrail (arcT xDir fullTurn) `at` p2 (1,0)
circle :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> t
circle d = unitCircle # scale d
ellipse :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> t
ellipse e
| e >= 0 && e < 1 = scaleX (sqrt (1 - e*e)) unitCircle
| otherwise = error "Eccentricity of ellipse must be >= 0 and < 1."
ellipseXY :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> n -> t
ellipseXY x y = unitCircle # scaleX x # scaleY y