Skip to content

Commit

Permalink
Merge pull request #47 from byorgey/master
Browse files Browse the repository at this point in the history
Update to track with diagrams-core renaming, and a better Show instance for R2
  • Loading branch information
fryguybob committed Sep 19, 2012
2 parents d8265b3 + 8c0042b commit c39ede7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Diagrams/TwoD/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ showLabels d =
) <>
fmap (const (Any False)) d
where
SubMap m = names d
SubMap m = subMap d
21 changes: 20 additions & 1 deletion src/Diagrams/TwoD/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,26 @@ import Data.Typeable
-- > foo (coords -> x :& y) = ...

newtype R2 = R2 { unR2 :: (Double, Double) }
deriving (AdditiveGroup, Eq, Ord, Show, Read, Typeable, Num, Fractional)
deriving (AdditiveGroup, Eq, Ord, Typeable, Num, Fractional)

instance Show R2 where
showsPrec p (R2 (x,y)) = showParen (p >= 7) $
showCoord x . showString " & " . showCoord y
where
showCoord x | x < 0 = showParen True (shows x)
| otherwise = shows x

instance Read R2 where
readsPrec d r = readParen (d > app_prec)
(\r -> [ (R2 (x,y), r''')
| (x,r') <- readsPrec (amp_prec + 1) r
, ("&",r'') <- lex r'
, (y,r''') <- readsPrec (amp_prec + 1) r''
])
r
where
app_prec = 10
amp_prec = 7

instance Newtype R2 (Double, Double) where
pack = R2
Expand Down

0 comments on commit c39ede7

Please sign in to comment.