Debian Codegraph @

src/Diagrams/TwoD/Ellipse.hs

raw symbols SCIP
1 {-# LANGUAGE FlexibleContexts #-}
2 {-# LANGUAGE MultiParamTypeClasses #-}
3 {-# LANGUAGE TypeFamilies #-}
4 {-# LANGUAGE TypeOperators #-}
5 {-# LANGUAGE TypeSynonymInstances #-}
6 -----------------------------------------------------------------------------
7 -- |
8 -- Module : Diagrams.TwoD.Ellipse
9 -- Copyright : (c) 2011 diagrams-lib team (see LICENSE)
10 -- License : BSD-style (see LICENSE)
11 -- Maintainer : [email protected]
12 --
13 -- Two-dimensional ellipses (and, as a special case, circles).
14 --
15 -----------------------------------------------------------------------------
16
17 module Diagrams.TwoD.Ellipse
18 (
19 -- * Ellipse and circle diagrams
20 unitCircle
21 , circle
22 , ellipse
23 , ellipseXY
24 ) where
25
26 import Diagrams.Core
27
28 import Diagrams.Angle
29 import Diagrams.Located (at)
30 import Diagrams.Trail (glueTrail)
31 import Diagrams.TrailLike
32 import Diagrams.TwoD.Arc
33 import Diagrams.TwoD.Transform
34 import Diagrams.TwoD.Types
35 import Diagrams.TwoD.Vector (xDir)
36 import Diagrams.Util
37
38 -- | A circle of radius 1, with center at the origin.
39 unitCircle :: (TrailLike t, V t ~ V2, N t ~ n) => t
40 unitCircle = trailLike $ glueTrail (arcT xDir fullTurn) `at` p2 (1,0)
41
42 -- | A circle of the given radius, centered at the origin. As a path,
43 -- it begins at (r,0).
44 circle :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> t
45 circle d = unitCircle # scale d
46
47 -- | @ellipse e@ constructs an ellipse with eccentricity @e@ by
48 -- scaling the unit circle in the X direction. The eccentricity must
49 -- be within the interval [0,1).
50 ellipse :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> t
51 ellipse e
52 | e >= 0 && e < 1 = scaleX (sqrt (1 - e*e)) unitCircle
53 | otherwise = error "Eccentricity of ellipse must be >= 0 and < 1."
54
55 -- | @ellipseXY x y@ creates an axis-aligned ellipse, centered at the
56 -- origin, with radius @x@ along the x-axis and radius @y@ along the
57 -- y-axis.
58 ellipseXY :: (TrailLike t, V t ~ V2, N t ~ n, Transformable t) => n -> n -> t
59 ellipseXY x y = unitCircle # scaleX x # scaleY y