{-# LANGUAGE FlexibleInstances
, FlexibleContexts
, TypeFamilies
, UndecidableInstances
#-}-- The UndecidableInstances flag is needed under 6.12.3 for the-- HasOrigin (a,b) instance.------------------------------------------------------------------------------- |-- Module : Diagrams.Core.HasOrigin-- Copyright : (c) 2011 diagrams-core team (see LICENSE)-- License : BSD-style (see LICENSE)-- Maintainer : diagrams-discuss@googlegroups.com---- Types which have an intrinsic notion of a \"local origin\",-- /i.e./ things which are /not/ invariant under translation.-------------------------------------------------------------------------------moduleDiagrams.Core.HasOrigin(HasOrigin(..),moveOriginBy,moveTo,place)whereimportqualifiedData.MapasMimportqualifiedData.SetasSimportData.AffineSpace((.-^),(.-.))importData.VectorSpaceimportDiagrams.Core.PointsimportDiagrams.Core.V-- | Class of types which have an intrinsic notion of a \"local-- origin\", i.e. things which are not invariant under translation,-- and which allow the origin to be moved.---- One might wonder why not just use 'Transformable' instead of-- having a separate class for 'HasOrigin'; indeed, for types which-- are instances of both we should have the identity---- > moveOriginTo (origin .^+ v) === translate (negateV v)---- The reason is that some things (e.g. vectors, 'Trail's) are-- transformable but are translationally invariant, i.e. have no-- origin.classVectorSpace(Vt)=>HasOrigintwhere-- | Move the local origin to another point.---- Note that this function is in some sense dual to 'translate'-- (for types which are also 'Transformable'); moving the origin-- itself while leaving the object \"fixed\" is dual to fixing the-- origin and translating the diagram.moveOriginTo::Point(Vt)->t->t-- | Move the local origin by a relative vector.moveOriginBy::HasOrigint=>Vt->t->tmoveOriginBy=moveOriginTo.P-- | Translate the object by the translation that sends the origin to-- the given point. Note that this is dual to 'moveOriginTo', i.e. we-- should have---- > moveTo (origin .^+ v) === moveOriginTo (origin .^- v)---- For types which are also 'Transformable', this is essentially the-- same as 'translate', i.e.---- > moveTo (origin .^+ v) === translate vmoveTo::HasOrigint=>Point(Vt)->t->tmoveTo=moveOriginBy.(origin.-.)-- | A flipped variant of 'moveTo', provided for convenience. Useful-- when writing a function which takes a point as an argument, such-- as when using 'withName' and friends.place::HasOrigint=>t->Point(Vt)->tplace=flipmoveToinstanceVectorSpacev=>HasOrigin(Pointv)wheremoveOriginTo(Pu)p=p.-^uinstance(HasOrigina,HasOriginb,Va~Vb)=>HasOrigin(a,b)wheremoveOriginTop(x,y)=(moveOriginTopx,moveOriginTopy)instanceHasOrigina=>HasOrigin[a]wheremoveOriginTo=map.moveOriginToinstance(HasOrigina,Orda)=>HasOrigin(S.Seta)wheremoveOriginTo=S.map.moveOriginToinstanceHasOrigina=>HasOrigin(M.Mapka)wheremoveOriginTo=M.map.moveOriginTo