{-# LANGUAGE FlexibleContexts , TypeSynonymInstances , MultiParamTypeClasses , TypeFamilies #-}------------------------------------------------------------------------------- |-- Module : Diagrams.TwoD.Ellipse-- Copyright : (c) 2011 diagrams-lib team (see LICENSE)-- License : BSD-style (see LICENSE)-- Maintainer : diagrams-discuss@googlegroups.com---- Two-dimensional ellipses (and, as a special case, circles).-------------------------------------------------------------------------------module Diagrams.TwoD.Ellipse ( -- * Ellipse and circle diagrams unitCircle , circle , ellipse , ellipseXY ) whereimport Graphics.Rendering.Diagramsimport Diagrams.TwoD.Typesimport Diagrams.TwoD.Transformimport Diagrams.TwoD.Arcimport Diagrams.Pathimport Diagrams.Util-- | A circle of radius 1, with center at the origin.unitCircle :: (PathLike p, V p ~ R2) => punitCircle = pathLike (p2 (1,0)) True $ trailSegments (arcT 0 (tau::Rad))-- | A circle of the given radius, centered at the origin. As a path,-- it begins at (r,0).circle :: (PathLike p, V p ~ R2, Transformable p) => Double -> pcircle d = unitCircle # scale d-- | @ellipse e@ constructs an ellipse with eccentricity @e@ by-- scaling the unit circle in the X direction. The eccentricity must-- be within the interval [0,1).ellipse :: (PathLike p, V p ~ R2, Transformable p) => Double -> pellipse e | e >= 0 && e < 1 = scaleX (sqrt (1 - e*e)) unitCircle | otherwise = error "Eccentricity of ellipse must be >= 0 and < 1."-- | @ellipseXY x y@ creates an axis-aligned ellipse, centered at the-- origin, with radius @x@ along the x-axis and radius @y@ along the-- y-axis.ellipseXY :: (PathLike p, V p ~ R2, Transformable p) => Double -> Double -> pellipseXY x y = unitCircle # scaleX x # scaleY y