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

scale invariant #3

Merged
merged 1 commit into from
Aug 4, 2012
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
36 changes: 36 additions & 0 deletions src/Diagrams/TwoD/Transform.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE FlexibleContexts
, FlexibleInstances
, TypeFamilies
, ViewPatterns
#-}
Expand Down Expand Up @@ -43,6 +44,7 @@ module Diagrams.TwoD.Transform
-- * Shears
, shearingX, shearX
, shearingY, shearY
, ScaleInv(..)

) where

Expand Down Expand Up @@ -239,3 +241,37 @@ shearingY d = fromLinear (over r2 (sh d) <-> over r2 (sh (-d)))
shearY :: (Transformable t, V t ~ R2) => Double -> t -> t
shearY = transform . shearingY


---------
---------
--Scale invariant

--1 find unit vector
--2 apply transformation to unit vector
--3 find angle difference b/w transformed unit vector and original vector
--4 rotate arrowhead
--5 add rotated arrowhead

data ScaleInv t = ScaleInv t ( R2 )
deriving (Show )

type instance V (ScaleInv t) = R2

instance (V t ~ R2, HasOrigin t) => HasOrigin (ScaleInv t) where
moveOriginTo p (ScaleInv s v) = ScaleInv ( moveOriginTo p s ) v

instance (V t ~ R2, Transformable t) => Transformable (ScaleInv t) where
transform tr (ScaleInv t v) = ScaleInv obj rotUnitVec where
transUnitVec :: R2
transUnitVec = transform tr v
angle :: Rad
angle = direction transUnitVec - direction v
rTrans :: ( Transformable t, (V t ~ R2) ) => t -> t
rTrans = rotate angle
obj = rTrans t
rotUnitVec :: R2
rotUnitVec = rTrans v


--------