From 8da9ad560022344674a6ff49c3373caa7e2810a2 Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Fri, 22 Mar 2013 14:59:01 -0400 Subject: [PATCH 1/2] onBasis gets the matrix equivalent of the Transformation --- src/Diagrams/Core/Transform.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Diagrams/Core/Transform.hs b/src/Diagrams/Core/Transform.hs index 38d244e..90e2773 100644 --- a/src/Diagrams/Core/Transform.hs +++ b/src/Diagrams/Core/Transform.hs @@ -6,6 +6,7 @@ , MultiParamTypeClasses , GeneralizedNewtypeDeriving , TypeSynonymInstances + , ScopedTypeVariables #-} ----------------------------------------------------------------------------- @@ -37,6 +38,7 @@ module Diagrams.Core.Transform , apply , papply , fromLinear + , onBasis -- * The Transformable class @@ -179,6 +181,20 @@ papply (Transformation t _ v) (P p) = P $ lapp t p ^+^ v fromLinear :: AdditiveGroup v => (v :-: v) -> (v :-: v) -> Transformation v fromLinear l1 l2 = Transformation l1 l2 zeroV +-- | Get the matrix equivalent of the linear transform, +-- (as a list of rows) and the translation vector. This +-- is mostly useful for implementing backends. +onBasis :: forall v. HasLinearMap v => Transformation v -> ([v], v) +onBasis t = (vmat, tr) + 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 + ------------------------------------------------------------ -- The Transformable class ------------------------------- ------------------------------------------------------------ From 2e169f8dbb6ab7051bf87d88c7588b9a5d9c7bec Mon Sep 17 00:00:00 2001 From: Daniel Bergey Date: Fri, 22 Mar 2013 16:25:43 -0400 Subject: [PATCH 2/2] doc fix: list of columns, not rows --- src/Diagrams/Core/Transform.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Diagrams/Core/Transform.hs b/src/Diagrams/Core/Transform.hs index 90e2773..34ef4b3 100644 --- a/src/Diagrams/Core/Transform.hs +++ b/src/Diagrams/Core/Transform.hs @@ -182,7 +182,7 @@ fromLinear :: AdditiveGroup v => (v :-: v) -> (v :-: v) -> Transformation v fromLinear l1 l2 = Transformation l1 l2 zeroV -- | Get the matrix equivalent of the linear transform, --- (as a list of rows) and the translation vector. This +-- (as a list of columns) and the translation vector. This -- is mostly useful for implementing backends. onBasis :: forall v. HasLinearMap v => Transformation v -> ([v], v) onBasis t = (vmat, tr)