diff --git a/src/Diagrams/Backend/Show.hs b/src/Diagrams/Backend/Show.hs index 52b0429f..51b605f1 100644 --- a/src/Diagrams/Backend/Show.hs +++ b/src/Diagrams/Backend/Show.hs @@ -19,6 +19,7 @@ module Diagrams.Backend.Show where import Diagrams.Prelude +import Diagrams.Core.Transform (onBasis) import Data.Basis @@ -46,14 +47,8 @@ instance Monoid (Render ShowBackend v) where renderTransf :: forall v. (Num (Scalar v), HasLinearMap v, Show (Scalar v)) => Transformation v -> Doc renderTransf t = renderMat mat - where tr :: v - tr = transl t - basis :: [Basis v] - basis = map fst (decompose tr) - es :: [v] - es = map basisValue basis - vmat :: [v] - vmat = map (apply t) es + where vmat :: [v] + (vmat, _) = onBasis t mat :: [[Scalar v]] mat = map decompV vmat -- mat' :: [[Scalar v]] diff --git a/src/Diagrams/TwoD/Transform.hs b/src/Diagrams/TwoD/Transform.hs index f61ab8f8..b4ee3d77 100644 --- a/src/Diagrams/TwoD/Transform.hs +++ b/src/Diagrams/TwoD/Transform.hs @@ -48,9 +48,12 @@ module Diagrams.TwoD.Transform -- * Scale invariance , ScaleInv(..), scaleInv + -- * component-wise + , onBasis ) where import Diagrams.Core +import qualified Diagrams.Core.Transform as T import Control.Newtype (over) @@ -308,3 +311,10 @@ instance (V t ~ R2, Transformable t) => Transformable (ScaleInv t) where rot = rotateAbout l angle l' = transform tr l trans = translate (l' .-. l) + +-- | Get the matrix equivalent of the linear transform, +-- (as a pair of columns) and the translation vector. This +-- is mostly useful for implementing backends. +onBasis :: Transformation R2 -> ((R2, R2), R2) +onBasis t = ((x, y), v) + where ((x:y:[]), v) = T.onBasis t