Skip to content

Commit

Permalink
Merge branch 'parametric-Located' of github.com:diagrams/diagrams-lib…
Browse files Browse the repository at this point in the history
… into expand
  • Loading branch information
Ryan Yates committed Sep 5, 2013
2 parents 8766c24 + e7a5fa7 commit 3dcb9a9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
14 changes: 9 additions & 5 deletions src/Diagrams/Located.hs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,18 @@ instance Traced a => Traced (Located a) where
instance Qualifiable a => Qualifiable (Located a) where
n |> (Loc p a) = Loc p (n |> a)

type instance Codomain (Located a) = Located (Codomain a)
type instance Codomain (Located a) = Point (Codomain a)

instance (V a ~ V (Codomain a), Parametric a) => Parametric (Located a) where
(Loc x a) `atParam` p = Loc x (a `atParam` p)
instance (Codomain a ~ V a, AdditiveGroup (V a), Parametric a)
=> Parametric (Located a) where
(Loc x a) `atParam` p = x .+^ (a `atParam` p)

instance DomainBounds a => DomainBounds (Located a) where
domainLower (Loc _ a) = domainLower a
domainUpper (Loc _ a) = domainUpper a

instance (V a ~ V (Codomain a), EndValues a) => EndValues (Located a)
instance (Codomain a ~ V a, AdditiveGroup (V a), EndValues a)
=> EndValues (Located a)

instance ( Codomain a ~ V a, Fractional (Scalar (V a)), AdditiveGroup (V a)
, Sectionable a, Parametric a
Expand All @@ -140,7 +142,9 @@ instance ( Codomain a ~ V a, Fractional (Scalar (V a)), AdditiveGroup (V a)
reverseDomain (Loc x a) = Loc (x .+^ y) (reverseDomain a)
where y = a `atParam` (domainUpper a)

instance (HasArcLength a, Fractional (Scalar (V a)), V a ~ V (Codomain a))
instance ( Codomain a ~ V a, AdditiveGroup (V a), Fractional (Scalar (V a))
, HasArcLength a
)
=> HasArcLength (Located a) where
arcLengthBounded eps (Loc _ a) = arcLengthBounded eps a
arcLengthToParam eps (Loc _ a) l = arcLengthToParam eps a l
4 changes: 2 additions & 2 deletions src/Diagrams/TwoD.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ module Diagrams.TwoD
-- * Angles
, tau
, Angle(..)
, Turn(..), CircleFrac, Rad(..), Deg(..)
, Turn(..), asTurn, CircleFrac, Rad(..), asRad, Deg(..), asDeg
, fullCircle, convertAngle

-- * Paths
-- ** Stroking
, stroke, stroke', strokeTrail, strokeT, strokeTrail', strokeT'
, strokeLine, strokeLoop
, strokeLocT, strokeLocLine, strokeLocLoop
, strokeLocTrail, strokeLocT, strokeLocLine, strokeLocLoop
, FillRule(..), fillRule
, StrokeOpts(..)

Expand Down
10 changes: 7 additions & 3 deletions src/Diagrams/TwoD/Path.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module Diagrams.TwoD.Path

stroke, stroke', strokeTrail, strokeT, strokeTrail', strokeT'
, strokeLine, strokeLoop
, strokeLocT, strokeLocLine, strokeLocLoop
, strokeLocTrail, strokeLocT, strokeLocLine, strokeLocLoop

-- ** Stroke options

Expand Down Expand Up @@ -201,9 +201,13 @@ strokeLoop :: (Renderable (Path R2) b) => Trail' Loop R2 -> Diagram b R2
strokeLoop = strokeT . wrapLoop

-- | A convenience function for converting a @Located Trail@ directly
-- into a diagram; @strokeLocT = stroke . trailLike@.
-- into a diagram; @strokeLocTrail = stroke . trailLike@.
strokeLocTrail :: (Renderable (Path R2) b) => Located (Trail R2) -> Diagram b R2
strokeLocTrail = stroke . trailLike

-- | Deprecated synonym for 'strokeLocTrail'.
strokeLocT :: (Renderable (Path R2) b) => Located (Trail R2) -> Diagram b R2
strokeLocT = stroke . trailLike
strokeLocT = strokeLocTrail

-- | A convenience function for converting a @Located@ line directly
-- into a diagram; @strokeLocLine = stroke . trailLike . mapLoc wrapLine@.
Expand Down
26 changes: 25 additions & 1 deletion src/Diagrams/TwoD/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Diagrams.TwoD.Types

-- * Angles
, Angle(..)
, Turn(..), CircleFrac, Rad(..), Deg(..)
, Turn(..), asTurn, CircleFrac, Rad(..), asRad, Deg(..), asDeg
, fullCircle, convertAngle
) where

Expand Down Expand Up @@ -198,17 +198,41 @@ instance Transformable R2 where
newtype Turn = Turn { getTurn :: Double }
deriving (Read, Show, Eq, Ord, Enum, Fractional, Num, Real, RealFrac)

-- | The identity function with a restricted type, for conveniently
-- declaring that some value should have type 'Turn'. For example,
-- @rotation . asTurn . fromRational@ constructs a rotation from a
-- rational value considered as a @Turn@. Without @asTurn@, the angle
-- type would be ambiguous.
asTurn :: Turn -> Turn
asTurn = id

-- | Deprecated synonym for 'Turn', retained for backwards compatibility.
type CircleFrac = Turn

-- | Newtype wrapper for representing angles in radians.
newtype Rad = Rad { getRad :: Double }
deriving (Read, Show, Eq, Ord, Enum, Floating, Fractional, Num, Real, RealFloat, RealFrac)

-- | The identity function with a restricted type, for conveniently
-- declaring that some value should have type 'Rad'. For example,
-- @rotation . asRad . fromRational@ constructs a rotation from a
-- rational value considered as a value in radians. Without @asRad@,
-- the angle type would be ambiguous.
asRad :: Rad -> Rad
asRad = id

-- | Newtype wrapper for representing angles in degrees.
newtype Deg = Deg { getDeg :: Double }
deriving (Read, Show, Eq, Ord, Enum, Fractional, Num, Real, RealFrac)

-- | The identity function with a restricted type, for conveniently
-- declaring that some value should have type 'Deg'. For example,
-- @rotation . asDeg . fromIntegral@ constructs a rotation from an
-- integral value considered as a value in degrees. Without @asDeg@,
-- the angle type would be ambiguous.
asDeg :: Deg -> Deg
asDeg = id

-- | Type class for types that measure angles.
class Num a => Angle a where
-- | Convert to a turn, /i.e./ a fraction of a circle.
Expand Down

0 comments on commit 3dcb9a9

Please sign in to comment.