Skip to content

Commit

Permalink
Merge pull request #36 from bergey/matrix-basis-rep
Browse files Browse the repository at this point in the history
onBasis gets the matrix equivalent of the Transformation
  • Loading branch information
byorgey committed Mar 22, 2013
2 parents 2a85db0 + 2e169f8 commit c7c69b8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Diagrams/Core/Transform.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
, MultiParamTypeClasses
, GeneralizedNewtypeDeriving
, TypeSynonymInstances
, ScopedTypeVariables
#-}

-----------------------------------------------------------------------------
Expand Down Expand Up @@ -37,6 +38,7 @@ module Diagrams.Core.Transform
, apply
, papply
, fromLinear
, onBasis

-- * The Transformable class

Expand Down Expand Up @@ -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 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)
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 -------------------------------
------------------------------------------------------------
Expand Down

0 comments on commit c7c69b8

Please sign in to comment.