Debian Codegraph @

src/Diagrams/TwoD/Size.hs

raw symbols SCIP
1 {-# LANGUAGE ConstraintKinds #-}
2 {-# LANGUAGE FlexibleContexts #-}
3 {-# LANGUAGE TypeFamilies #-}
4
5 -----------------------------------------------------------------------------
6 -- |
7 -- Module : Diagrams.TwoD.Size
8 -- Copyright : (c) 2011 diagrams-lib team (see LICENSE)
9 -- License : BSD-style (see LICENSE)
10 -- Maintainer : [email protected]
11 --
12 -- Utilities for working with sizes of two-dimensional objects.
13 --
14 -----------------------------------------------------------------------------
15 module Diagrams.TwoD.Size
16 (
17 -- ** Computing sizes
18 width, height
19 , extentX, extentY
20
21 -- ** Specifying sizes
22 , mkSizeSpec2D
23 , mkWidth
24 , mkHeight
25 , dims2D
26
27 ) where
28
29 import Diagrams.Core
30 import Diagrams.Core.Envelope
31 import Diagrams.Size
32 import Diagrams.TwoD.Types
33 import Diagrams.TwoD.Vector
34
35 ------------------------------------------------------------
36 -- Computing diagram sizes
37 ------------------------------------------------------------
38
39 -- | Compute the width of an enveloped object.
40 --
41 -- Note this is just @diameter unitX@.
42 width :: (InSpace V2 n a, Enveloped a) => a -> n
43 width = diameter unitX
44
45 -- | Compute the height of an enveloped object.
46 height :: (InSpace V2 n a, Enveloped a) => a -> n
47 height = diameter unitY
48
49 -- | Compute the absolute x-coordinate range of an enveloped object in
50 -- the form @(lo,hi)@. Return @Nothing@ for objects with an empty
51 -- envelope.
52 --
53 -- Note this is just @extent unitX@.
54 extentX :: (InSpace v n a, R1 v, Enveloped a) => a -> Maybe (n, n)
55 extentX = extent unitX
56
57 -- | Compute the absolute y-coordinate range of an enveloped object in
58 -- the form @(lo,hi)@. Return @Nothing@ for objects with an empty
59 -- envelope.
60 extentY :: (InSpace v n a, R2 v, Enveloped a) => a -> Maybe (n, n)
61 extentY = extent unitY
62
63 -- | Make a 'SizeSpec' from possibly-specified width and height.
64 mkSizeSpec2D :: Num n => Maybe n -> Maybe n -> SizeSpec V2 n
65 mkSizeSpec2D x y = mkSizeSpec (V2 x y)
66
67 -- | Make a 'SizeSpec' from a width and height.
68 dims2D :: n -> n -> SizeSpec V2 n
69 dims2D x y = dims (V2 x y)
70
71 -- | Make a 'SizeSpec' with only width defined.
72 mkWidth :: Num n => n -> SizeSpec V2 n
73 mkWidth w = dims (V2 w 0)
74
75 -- | Make a 'SizeSpec' with only height defined.
76 mkHeight :: Num n => n -> SizeSpec V2 n
77 mkHeight h = dims (V2 0 h)
78