Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onBasis gets the matrix equivalent of the Transformation #36

Merged
merged 2 commits into from
Mar 22, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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