Skip to content

Commit

Permalink
move V and Transformable instances for Measure to -core; Measure now …
Browse files Browse the repository at this point in the history
…takes a vector type
  • Loading branch information
byorgey committed Mar 29, 2014
1 parent 1c7ea11 commit 337dfba
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 27 deletions.
12 changes: 6 additions & 6 deletions src/Diagrams/TwoD/Arrow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ tailSty opts = fc black (opts^.tailStyle)


-- | Radius of a circumcircle around the head.
newtype HeadSize = HeadSize (Last (Measure Double))
newtype HeadSize = HeadSize (Last (Measure R2))
deriving (Typeable, Data, Semigroup)
instance AttributeClass HeadSize

Expand All @@ -299,16 +299,16 @@ instance Default HeadSize where
def = HeadSize (Last (Output 20))

-- | Set the radius of the circumcircle around the head.
headSize :: (HasStyle a, V a ~ R2) => Measure Double -> a -> a
headSize :: (HasStyle a, V a ~ R2) => Measure R2 -> a -> a
headSize = applyGTAttr . HeadSize . Last

headSizeA :: (HasStyle a, V a ~ R2) => HeadSize -> a -> a
headSizeA = applyGTAttr

getHeadSize :: HeadSize -> Measure Double
getHeadSize :: HeadSize -> Measure R2
getHeadSize (HeadSize (Last s)) = s

newtype TailSize = TailSize (Last (Measure Double))
newtype TailSize = TailSize (Last (Measure R2))
deriving (Typeable, Data, Semigroup)
instance AttributeClass TailSize

Expand All @@ -323,13 +323,13 @@ instance Default TailSize where
def = TailSize (Last (Output 20))

-- | Set the radius of a circumcircle around the arrow tail.
tailSize :: (HasStyle a, V a ~ R2) => Measure Double -> a -> a
tailSize :: (HasStyle a, V a ~ R2) => Measure R2 -> a -> a
tailSize = applyGTAttr . TailSize . Last

tailSizeA :: (HasStyle a, V a ~ R2) => TailSize -> a -> a
tailSizeA = applyGTAttr

getTailSize :: TailSize -> Measure Double
getTailSize :: TailSize -> Measure R2
getTailSize (TailSize (Last s)) = s

-- | Calculate the length of the portion of the horizontal line that passes
Expand Down
18 changes: 9 additions & 9 deletions src/Diagrams/TwoD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import Diagrams.TwoD.Types

-- | Line widths specified on child nodes always override line widths
-- specified at parent nodes.
newtype LineWidth = LineWidth (Last (Measure Double))
newtype LineWidth = LineWidth (Last (Measure R2))
deriving (Typeable, Data, Semigroup)
instance AttributeClass LineWidth

Expand All @@ -59,11 +59,11 @@ instance Transformable LineWidth where
instance Default LineWidth where
def = LineWidth (Last (Output 1))

getLineWidth :: LineWidth -> Measure Double
getLineWidth :: LineWidth -> Measure R2
getLineWidth (LineWidth (Last w)) = w

-- | Set the line (stroke) width.
lineWidth :: (HasStyle a, V a ~ R2) => (Measure Double) -> a -> a
lineWidth :: (HasStyle a, V a ~ R2) => Measure R2 -> a -> a
lineWidth = applyGTAttr . LineWidth . Last

-- | Apply a 'LineWidth' attribute.
Expand Down Expand Up @@ -101,7 +101,7 @@ veryThick = lwO 5
-----------------------------------------------------------------

-- | Create lines that are dashing... er, dashed.
data Dashing = Dashing [Measure Double] (Measure Double)
data Dashing = Dashing [Measure R2] (Measure R2)
deriving (Typeable, Data, Eq)

newtype DashingA = DashingA (Last Dashing)
Expand All @@ -122,11 +122,11 @@ getDashing (DashingA (Last d)) = d

-- | Set the line dashing style.
setDashing :: (HasStyle a, V a ~ R2) =>
[Measure Double] -- ^ A list specifying alternate lengths of on
-- and off portions of the stroke. The empty
-- list indicates no dashing.
-> Measure Double -- ^ An offset into the dash pattern at which the
-- stroke should start.
[Measure R2] -- ^ A list specifying alternate lengths of on
-- and off portions of the stroke. The empty
-- list indicates no dashing.
-> Measure R2 -- ^ An offset into the dash pattern at which the
-- stroke should start.
-> a -> a
setDashing ds offs = applyGTAttr (DashingA (Last (Dashing ds offs)))

Expand Down
8 changes: 4 additions & 4 deletions src/Diagrams/TwoD/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ import Diagrams.Core.Envelope (pointEnvelope)
import Diagrams.TwoD.Types

import Data.AffineSpace ((.-.))
import Data.Semigroup
import Data.Colour
import Data.Data
import Data.Default.Class
import Data.Semigroup

------------------------------------------------------------
-- Text diagrams
Expand Down Expand Up @@ -162,7 +162,7 @@ font = applyAttr . Font . Last

-- | The @FontSize@ attribute specifies the size of a font's
-- em-square. Inner @FontSize@ attributes override outer ones.
newtype FontSize = FontSize (Last (Measure Double))
newtype FontSize = FontSize (Last (Measure R2))
deriving (Typeable, Data, Semigroup)
instance AttributeClass FontSize

Expand All @@ -176,13 +176,13 @@ instance Transformable FontSize where
FontSize (Last (transform t s))

-- | Extract the size from a @FontSize@ attribute.
getFontSize :: FontSize -> Measure Double
getFontSize :: FontSize -> Measure R2
getFontSize (FontSize (Last s)) = s

-- | Set the font size, that is, the size of the font's em-square as
-- measured within the current local vector space. The default size
-- is @1@.
setFontSize :: (HasStyle a, V a ~ R2) => Measure Double -> a -> a
setFontSize :: (HasStyle a, V a ~ R2) => Measure R2 -> a -> a
setFontSize = applyGTAttr . FontSize . Last

-- | A convenient synonym for 'setFontSize (Global w)'.
Expand Down
8 changes: 0 additions & 8 deletions src/Diagrams/TwoD/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,3 @@ instance HasR P2 where

instance HasTheta P2 where
_theta = _relative origin . _theta

-----------------------------------------------------------------

type instance V (Measure Double) = R2

instance Transformable (Measure Double) where
transform tr (Local x) = Local (avgScale tr * x)
transform _ y = y

0 comments on commit 337dfba

Please sign in to comment.