packages feed

diagrams-lib-1.4.0.1 / src / Diagrams / TwoD / Ellipse.hs

{-# LANGUAGE FlexibleContexts      #-}{-# LANGUAGE MultiParamTypeClasses #-}{-# LANGUAGE TypeFamilies          #-}{-# LANGUAGE TypeSynonymInstances  #-}------------------------------------------------------------------------------- |-- 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           Diagrams.Coreimport           Diagrams.Angleimport           Diagrams.Located        (at)import           Diagrams.Trail          (glueTrail)import           Diagrams.TrailLikeimport           Diagrams.TwoD.Arcimport           Diagrams.TwoD.Transformimport           Diagrams.TwoD.Typesimport           Diagrams.TwoD.Vector    (xDir)import           Diagrams.Util-- | A circle of radius 1, with center at the origin.unitCircle :: (TrailLike t, V t ~ V2, N t ~ n) => tunitCircle = trailLike $ glueTrail (arcT xDir fullTurn) `at` p2 (1,0)-- | A circle of the given radius, centered at the origin.  As a path,--   it begins at (r,0).circle :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> tcircle 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 :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> tellipse 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 :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> n -> tellipseXY x y = unitCircle # scaleX x # scaleY y