Skip to content

Commit

Permalink
convert dashing to Measure, Local not scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyrosenbluth committed Mar 25, 2014
1 parent 3092b71 commit e625a48
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 25 deletions.
25 changes: 0 additions & 25 deletions src/Diagrams/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ module Diagrams.Attributes (
-- ** Miter limit
, LineMiterLimit(..), getLineMiterLimit, lineMiterLimit, lineMiterLimitA

-- ** Dashing
, Dashing(..), DashingA, getDashing, dashing

-- * Compilation utilities
, splitFills

Expand Down Expand Up @@ -342,28 +339,6 @@ lineMiterLimit = applyAttr . LineMiterLimit . Last
-- | Apply a 'LineMiterLimit' attribute.
lineMiterLimitA :: HasStyle a => LineMiterLimit -> a -> a
lineMiterLimitA = applyAttr

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

newtype DashingA = DashingA (Last Dashing)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass DashingA

getDashing :: DashingA -> Dashing
getDashing (DashingA (Last d)) = d

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

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

data FillLoops v = FillLoops
Expand Down
3 changes: 3 additions & 0 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ module Diagrams.TwoD
, LineWidth, getLineWidth, lineWidth, lineWidthA, lw, lwN, lwO, lwL
, ultraThin, veryThin, thin, medium, thick, veryThick

-- ** Dashing
, Dashing(..), DashingA, getDashing, dashing

-- * Visual aids for understanding the internal model
, showOrigin
, showOrigin'
Expand Down
36 changes: 36 additions & 0 deletions src/Diagrams/TwoD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ module Diagrams.TwoD.Attributes (
, lw, lwN, lwO, lwL
, ultraThin, veryThin, thin, medium, thick, veryThick

-- ** Dashing
, Dashing(..), DashingA, getDashing, dashing

) where

import Data.Data
Expand Down Expand Up @@ -90,3 +93,36 @@ thin = lwO 1
medium = lwO 2
thick = lwO 4
veryThick = lwO 5

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

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

newtype DashingA = DashingA (Last Dashing)
deriving (Typeable, Data, Semigroup, Eq)
instance AttributeClass DashingA

type instance V DashingA = R2

instance Transformable DashingA where
transform t (DashingA (Last (Dashing [Local w] (Local v)))) =
DashingA (Last (Dashing [Local r] (Local s)))

This comment has been minimized.

Copy link
@byorgey

byorgey Mar 25, 2014

Member

This only applies to Dashing values containing a singleton list [Local r].

This comment has been minimized.

Copy link
@jeffreyrosenbluth

jeffreyrosenbluth Mar 25, 2014

Author Member

Oops, thanks

where
r = avgScale t * w
s = avgScale t * v
transform _ l = l

getDashing :: DashingA -> Dashing
getDashing (DashingA (Last d)) = d

-- | Set the line dashing style.
dashing :: (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.
-> a -> a
dashing ds offs = applyGTAttr (DashingA (Last (Dashing ds offs)))

2 comments on commit e625a48

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Local not effected by transformation ?

@jeffreyrosenbluth
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need to add convenience functions for setting dashing in various units.

Please sign in to comment.