Skip to content

Commit

Permalink
Remove Wrapped instances for attributes.
Browse files Browse the repository at this point in the history
They're just added noise, you never really use them because you need to know the types. We can always add them later.
  • Loading branch information
cchalmers committed Feb 24, 2015
1 parent 91c693b commit 5b4cd40
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 102 deletions.
32 changes: 0 additions & 32 deletions src/Diagrams/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,6 @@ huge = normalized 0.10
newtype LineWidth n = LineWidth (Last n)
deriving (Typeable, Semigroup)

instance Rewrapped (LineWidth n) (LineWidth n')
instance Wrapped (LineWidth n) where
type Unwrapped (LineWidth n) = n
_Wrapped' = iso getLineWidth (LineWidth . Last)

_LineWidth :: (Typeable n, OrderedField n) => Iso' (LineWidth n) n
_LineWidth = iso getLineWidth (LineWidth . Last)

Expand Down Expand Up @@ -187,12 +182,6 @@ data Dashing n = Dashing [n] n
newtype DashingA n = DashingA (Last (Dashing n))
deriving (Functor, Typeable, Semigroup)

instance Rewrapped (DashingA n) (DashingA n')
instance Wrapped (DashingA n) where
type Unwrapped (DashingA n) = Dashing n
_Wrapped' = iso getDashing (DashingA . Last)
{-# INLINE _Wrapped' #-}

_Dashing :: Iso' (DashingA n) (Dashing n)
_Dashing = iso getDashing (DashingA . Last)

Expand Down Expand Up @@ -315,11 +304,6 @@ newtype Opacity = Opacity (Product Double)
deriving (Typeable, Semigroup)
instance AttributeClass Opacity

instance Rewrapped Opacity Opacity
instance Wrapped Opacity where
type Unwrapped Opacity = Double
_Wrapped' = _Opacity

_Opacity :: Iso' Opacity Double
_Opacity = iso getOpacity (Opacity . Product)

Expand Down Expand Up @@ -354,12 +338,6 @@ newtype LineCapA = LineCapA (Last LineCap)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass LineCapA

instance Rewrapped LineCapA LineCapA
instance Wrapped LineCapA where
type Unwrapped LineCapA = LineCap
_Wrapped' = _LineCap
{-# INLINE _Wrapped' #-}

_LineCap :: Iso' LineCapA LineCap
_LineCap = iso getLineCap (LineCapA . Last)

Expand Down Expand Up @@ -391,11 +369,6 @@ newtype LineJoinA = LineJoinA (Last LineJoin)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass LineJoinA

instance Rewrapped LineJoinA LineJoinA
instance Wrapped LineJoinA where
type Unwrapped LineJoinA = LineJoin
_Wrapped' = _LineJoin

_LineJoin :: Iso' LineJoinA LineJoin
_LineJoin = iso getLineJoin (LineJoinA . Last)

Expand All @@ -420,11 +393,6 @@ newtype LineMiterLimit = LineMiterLimit (Last Double)
deriving (Typeable, Semigroup)
instance AttributeClass LineMiterLimit

instance Rewrapped LineMiterLimit LineMiterLimit
instance Wrapped LineMiterLimit where
type Unwrapped LineMiterLimit = Double
_Wrapped' = _LineMiterLimit

_LineMiterLimit :: Iso' LineMiterLimit Double
_LineMiterLimit = iso getLineMiterLimit (LineMiterLimit . Last)

Expand Down
18 changes: 1 addition & 17 deletions src/Diagrams/ThreeD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ newtype SurfaceColor = SurfaceColor (Last (Colour Double))

instance AttributeClass SurfaceColor

instance Wrapped SurfaceColor where
type Unwrapped SurfaceColor = Colour Double
_Wrapped' = _SurfaceColor

_SurfaceColor :: Iso' SurfaceColor (Colour Double)
_SurfaceColor = iso (\(SurfaceColor (Last c)) -> c) (SurfaceColor . Last)

Expand All @@ -67,10 +63,6 @@ newtype Diffuse = Diffuse (Last Double)

instance AttributeClass Diffuse

instance Wrapped Diffuse where
type Unwrapped Diffuse = Double
_Wrapped' = _Diffuse

-- | Isomorphism between 'Diffuse' and 'Double'
_Diffuse :: Iso' Diffuse Double
_Diffuse = iso (\(Diffuse (Last d)) -> d) (Diffuse . Last)
Expand All @@ -94,12 +86,8 @@ newtype Ambient = Ambient (Last Double)

instance AttributeClass Ambient

instance Wrapped Ambient where
type Unwrapped Ambient = Double
_Wrapped' = iso (\(Ambient (Last d)) -> d) (Ambient . Last)

_Ambient :: Iso' Ambient Double
_Ambient = _Wrapped'
_Ambient = iso (\(Ambient (Last d)) -> d) (Ambient . Last)

-- | Set the emittance due to ambient light.
ambient :: HasStyle d => Double -> d -> d
Expand Down Expand Up @@ -128,10 +116,6 @@ newtype Highlight = Highlight (Last Specular)

instance AttributeClass Highlight

instance Wrapped Highlight where
type Unwrapped Highlight = Specular
_Wrapped' = _Highlight

_Highlight :: Iso' Highlight Specular
_Highlight = iso (\(Highlight (Last s)) -> s) (Highlight . Last)

Expand Down
32 changes: 10 additions & 22 deletions src/Diagrams/TwoD/Attributes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,9 @@ instance (Typeable n) => AttributeClass (LineTexture n)
type instance V (LineTexture n) = V2
type instance N (LineTexture n) = n

instance Rewrapped (LineTexture n) (LineTexture n')
instance Wrapped (LineTexture n) where
type Unwrapped (LineTexture n) = Texture n
_Wrapped' = iso getLineTexture (LineTexture . Last)
{-# INLINE _Wrapped' #-}

_LineTexture :: Iso (LineTexture n) (LineTexture n')
(Texture n) (Texture n')
_LineTexture = _Wrapped
_LineTexture = iso getLineTexture (LineTexture . Last)

-- Only gradients get transformed. The transform is applied to the gradients
-- transform field. Colors are left unchanged.
Expand Down Expand Up @@ -336,22 +330,17 @@ lineRGradient g = lineTexture (RG g)
newtype FillTexture n = FillTexture (Recommend (Last (Texture n)))
deriving (Typeable, Semigroup)

-- This isn't valid since it ignores Recommend!
instance Rewrapped (FillTexture n) (FillTexture n')
instance Wrapped (FillTexture n) where
type Unwrapped (FillTexture n) = Recommend (Texture n)
_Wrapped' = iso getter setter -- == coerce
where
getter (FillTexture (Recommend (Last t))) = Recommend t
getter (FillTexture (Commit (Last t))) = Commit t
setter (Recommend t) = FillTexture (Recommend (Last t))
setter (Commit t) = FillTexture (Commit (Last t))
{-# INLINE _Wrapped' #-}

instance Typeable n => AttributeClass (FillTexture n)

_FillTexture :: Iso' (FillTexture n) (Recommend (Texture n))
_FillTexture = _Wrapped'
_FillTexture = iso getter setter
where
getter (FillTexture (Recommend (Last t))) = Recommend t
getter (FillTexture (Commit (Last t))) = Commit t
setter (Recommend t) = FillTexture (Recommend (Last t))
setter (Commit t) = FillTexture (Commit (Last t))
-- = iso (\(FillTexture a) -> a) FillTexture . mapping _Wrapped
-- -- once we depend on monoid-extras-0.4

type instance V (FillTexture n) = V2
type instance N (FillTexture n) = n
Expand All @@ -362,8 +351,7 @@ instance Floating n => Transformable (FillTexture n) where
transform = over (_FillTexture . _recommend) . transform

instance Default (FillTexture n) where
def = FillTexture (Recommend (Last (SC
(SomeColor (transparent :: AlphaColour Double)))))
def = review (_FillTexture . _Recommend . _SC . _SomeColor) transparent

getFillTexture :: FillTexture n -> Texture n
getFillTexture (FillTexture tx) = getLast . getRecommend $ tx
Expand Down
41 changes: 10 additions & 31 deletions src/Diagrams/TwoD/Text.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ baselineText = mkText BaselineText
newtype Font = Font (Last String)
deriving (Typeable, Semigroup, Eq)

instance Rewrapped Font Font
instance Wrapped Font where
type Unwrapped Font = String
_Wrapped' = iso getFont (Font . Last)

_Font :: Iso' Font String
_Font = iso getFont (Font . Last)

Expand All @@ -192,7 +187,7 @@ font :: HasStyle a => String -> a -> a
font = applyAttr . Font . Last

_font :: (Typeable n, OrderedField n) => Lens' (Style v n) (Maybe String)
_font = atAttr . mapping (_Wrapping (Font . Last))
_font = atAttr . mapping _Font

--------------------------------------------------
-- Font size
Expand All @@ -207,18 +202,14 @@ instance Functor FontSize where
fmap f (FontSize (Recommend (Last a))) = FontSize (Recommend (Last (f a)))
fmap f (FontSize (Commit (Last a))) = FontSize (Commit (Last (f a)))

instance Rewrapped (FontSize n) (FontSize n')
instance Wrapped (FontSize n) where
type Unwrapped (FontSize n) = Recommend n
_Wrapped' = iso getter setter
where getter (FontSize (Recommend (Last a))) = Recommend a
getter (FontSize (Commit (Last a))) = Commit a
setter (Recommend a) = FontSize $ Recommend (Last a)
setter (Commit a) = FontSize $ Commit (Last a)
{-# INLINE _Wrapped' #-}

_FontSize :: Iso' (FontSize n) (Recommend n)
_FontSize = _Wrapped'
_FontSize = iso getter setter
where getter (FontSize (Recommend (Last a))) = Recommend a
getter (FontSize (Commit (Last a))) = Commit a
setter (Recommend a) = FontSize $ Recommend (Last a)
setter (Commit a) = FontSize $ Commit (Last a)
-- = iso (\(FontSize a) -> a) FontSize . mapping _Wrapped
-- once we depend on monoid-extras-0.4

_FontSizeM :: Iso' (FontSizeM n) (Measured n (Recommend n))
_FontSizeM = mapping _FontSize
Expand Down Expand Up @@ -287,17 +278,11 @@ newtype FontSlantA = FontSlantA (Last FontSlant)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass FontSlantA

instance Rewrapped FontSlantA FontSlantA
instance Wrapped FontSlantA where
type Unwrapped FontSlantA = FontSlant
_Wrapped' = iso getFontSlant (FontSlantA . Last)
{-# INLINE _Wrapped' #-}

instance Default FontSlant where
def = FontSlantNormal

_FontSlant :: Iso' FontSlantA FontSlant
_FontSlant = _Wrapped'
_FontSlant = iso getFontSlant (FontSlantA . Last)

-- | Extract the font slant from a 'FontSlantA' attribute.
getFontSlant :: FontSlantA -> FontSlant
Expand Down Expand Up @@ -335,17 +320,11 @@ newtype FontWeightA = FontWeightA (Last FontWeight)
deriving (Typeable, Semigroup, Eq)
instance AttributeClass FontWeightA

instance Rewrapped FontWeightA FontWeightA
instance Wrapped FontWeightA where
type Unwrapped FontWeightA = FontWeight
_Wrapped' = iso getFontWeight (FontWeightA . Last)
{-# INLINE _Wrapped' #-}

instance Default FontWeight where
def = FontWeightNormal

_FontWeight :: Iso' FontWeightA FontWeight
_FontWeight = _Wrapped'
_FontWeight = iso getFontWeight (FontWeightA . Last)

-- | Extract the font weight from a 'FontWeightA' attribute.
getFontWeight :: FontWeightA -> FontWeight
Expand Down

0 comments on commit 5b4cd40

Please sign in to comment.