This repository has been archived on 2025-03-03. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
htanks/src/Transformable.hs

44 lines
1 KiB
Haskell
Raw Normal View History

{-# LANGUAGE TypeOperators, TypeSynonymInstances #-}
module Transformable ( Coord
, Vector3
2011-06-26 20:55:51 +02:00
, TransformMap
, Transform(..)
, ReversibleTransform(..)
, Transformable(..)
2011-06-26 20:55:51 +02:00
, (><)
, (>:<)
) where
import Data.LinearMap
type Coord = Double
type Vector3 = (Coord, Coord, Coord)
2011-06-26 20:55:51 +02:00
type TransformMap = Vector3 :-* Vector3
class Transformable a where
2011-06-26 20:55:51 +02:00
transform :: TransformMap -> a -> a
2011-06-26 20:55:51 +02:00
class Transform a where
toMap :: a -> TransformMap
class Transform a => ReversibleTransform a where
toMap' :: a -> TransformMap
instance Transformable Vector3 where
2011-06-26 20:55:51 +02:00
transform = lapply
instance Transform TransformMap where
toMap = id
instance Transformable TransformMap where
transform = (*.*)
2011-06-26 20:55:51 +02:00
(><) :: (Transform t, Transformable a) => t -> a -> a
t >< a = transform (toMap t) a
2011-06-26 20:55:51 +02:00
(>:<) :: (ReversibleTransform t, Transformable a) => t -> a -> a
t >:< a = transform (toMap' t) a