This repository has been archived on 2025-03-03. You can view files and clone it, but cannot push or open issues or pull requests.
htanks/src/Transformable.hs

44 lines
1 KiB
Haskell
Raw Permalink 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
2011-06-26 21:07:41 +02:00
(><) = transform . toMap
2011-06-26 20:55:51 +02:00
(>:<) :: (ReversibleTransform t, Transformable a) => t -> a -> a
2011-06-26 21:07:41 +02:00
(>:<) = transform . toMap'