summaryrefslogtreecommitdiffstats
path: root/src/Transformable.hs
blob: 335b4771cc506ba95773010834f470868f0297aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{-# LANGUAGE TypeOperators, TypeSynonymInstances #-}

module Transformable ( Coord
                     , Vector3
                     , TransformMap
                     , Transform(..)
                     , ReversibleTransform(..)
                     , Transformable(..)
                     , (><)
                     , (>:<)
                     ) where

import Data.LinearMap

type Coord = Double

type Vector3 = (Coord, Coord, Coord)
type TransformMap = Vector3 :-* Vector3

class Transformable a where
  transform :: TransformMap -> a -> a

class Transform a where
  toMap :: a -> TransformMap

class Transform a => ReversibleTransform a where
  toMap' :: a -> TransformMap

instance Transformable Vector3 where
  transform = lapply

instance Transform TransformMap where
  toMap = id

instance Transformable TransformMap where
  transform = (*.*)

(><) :: (Transform t, Transformable a) => t -> a -> a
t >< a = transform (toMap t) a

(>:<) :: (ReversibleTransform t, Transformable a) => t -> a -> a
t >:< a = transform (toMap' t) a