SGplus-1.1: (updated) Small geometry library for dealing with vectors and collision detection

Safe HaskellSafe
LanguageHaskell98

Data.SG.Vector.Basic

Description

Some types that are very basic vectors. Most of the use that can be made of the vectors is in their type-class instances, which support a powerful set of operations. For example:

fmap (*3) v -- Scales vector v by 3
pure 0 -- Creates a vector filled with zeroes
v + w -- Adds two vectors (there is a 'Num' instance, basically)

Plus all the instances for the classes in Data.SG.Vector, which allows you to use getX and so on.

You will probably want to create more friendly type synonyms, such as:

type Vector2 = Pair Double
type Vector3 = Triple Double
type Line2 = LinePair Double
type Line3 = LineTriple Double

Synopsis

Documentation

newtype Pair a Source #

A pair, which acts as a 2D vector.

Constructors

Pair (a, a) 

Instances

Functor Pair Source # 

Methods

fmap :: (a -> b) -> Pair a -> Pair b #

(<$) :: a -> Pair b -> Pair a #

Applicative Pair Source # 

Methods

pure :: a -> Pair a #

(<*>) :: Pair (a -> b) -> Pair a -> Pair b #

(*>) :: Pair a -> Pair b -> Pair b #

(<*) :: Pair a -> Pair b -> Pair a #

Foldable Pair Source # 

Methods

fold :: Monoid m => Pair m -> m #

foldMap :: Monoid m => (a -> m) -> Pair a -> m #

foldr :: (a -> b -> b) -> b -> Pair a -> b #

foldr' :: (a -> b -> b) -> b -> Pair a -> b #

foldl :: (b -> a -> b) -> b -> Pair a -> b #

foldl' :: (b -> a -> b) -> b -> Pair a -> b #

foldr1 :: (a -> a -> a) -> Pair a -> a #

foldl1 :: (a -> a -> a) -> Pair a -> a #

toList :: Pair a -> [a] #

null :: Pair a -> Bool #

length :: Pair a -> Int #

elem :: Eq a => a -> Pair a -> Bool #

maximum :: Ord a => Pair a -> a #

minimum :: Ord a => Pair a -> a #

sum :: Num a => Pair a -> a #

product :: Num a => Pair a -> a #

Traversable Pair Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Pair a -> f (Pair b) #

sequenceA :: Applicative f => Pair (f a) -> f (Pair a) #

mapM :: Monad m => (a -> m b) -> Pair a -> m (Pair b) #

sequence :: Monad m => Pair (m a) -> m (Pair a) #

VectorNum Pair Source # 

Methods

fmapNum1 :: Num b => (a -> b) -> Pair a -> Pair b Source #

fmapNum2 :: Num c => (a -> b -> c) -> Pair a -> Pair b -> Pair c Source #

fmapNum1inv :: Num a => (a -> a) -> Pair a -> Pair a Source #

simpleVec :: Num a => a -> Pair a Source #

Coord2 Pair Source # 

Methods

getX :: Pair a -> a Source #

getY :: Pair a -> a Source #

Coord Pair Source # 

Methods

getComponents :: Num a => Pair a -> [a] Source #

fromComponents :: Num a => [a] -> Pair a Source #

magSq :: Num a => Pair a -> a Source #

dotProduct :: Num a => Pair a -> Pair a -> a Source #

IsomorphicVectors Pair Rel2' Source # 

Methods

iso :: Num a => Pair a -> Rel2' a Source #

IsomorphicVectors Pair Point2' Source # 

Methods

iso :: Num a => Pair a -> Point2' a Source #

IsomorphicVectors Rel2' Pair Source # 

Methods

iso :: Num a => Rel2' a -> Pair a Source #

IsomorphicVectors Point2' Pair Source # 

Methods

iso :: Num a => Point2' a -> Pair a Source #

Geometry Pair Pair LinePair Source # 

Methods

scaleRel :: Num a => a -> Pair a -> Pair a Source #

plusDir :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

fromPt :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

getLineVecs :: Num a => LinePair a -> (Pair a, Pair a) Source #

makeLine :: Num a => Pair a -> Pair a -> LinePair a Source #

Eq a => Eq (Pair a) Source # 

Methods

(==) :: Pair a -> Pair a -> Bool #

(/=) :: Pair a -> Pair a -> Bool #

(Show a, Eq a, Num a) => Num (Pair a) Source # 

Methods

(+) :: Pair a -> Pair a -> Pair a #

(-) :: Pair a -> Pair a -> Pair a #

(*) :: Pair a -> Pair a -> Pair a #

negate :: Pair a -> Pair a #

abs :: Pair a -> Pair a #

signum :: Pair a -> Pair a #

fromInteger :: Integer -> Pair a #

Ord a => Ord (Pair a) Source # 

Methods

compare :: Pair a -> Pair a -> Ordering #

(<) :: Pair a -> Pair a -> Bool #

(<=) :: Pair a -> Pair a -> Bool #

(>) :: Pair a -> Pair a -> Bool #

(>=) :: Pair a -> Pair a -> Bool #

max :: Pair a -> Pair a -> Pair a #

min :: Pair a -> Pair a -> Pair a #

Read a => Read (Pair a) Source # 
Show a => Show (Pair a) Source # 

Methods

showsPrec :: Int -> Pair a -> ShowS #

show :: Pair a -> String #

showList :: [Pair a] -> ShowS #

newtype Triple a Source #

A triple, which acts as a 3D vector.

Constructors

Triple (a, a, a) 

Instances

Functor Triple Source # 

Methods

fmap :: (a -> b) -> Triple a -> Triple b #

(<$) :: a -> Triple b -> Triple a #

Applicative Triple Source # 

Methods

pure :: a -> Triple a #

(<*>) :: Triple (a -> b) -> Triple a -> Triple b #

(*>) :: Triple a -> Triple b -> Triple b #

(<*) :: Triple a -> Triple b -> Triple a #

Foldable Triple Source # 

Methods

fold :: Monoid m => Triple m -> m #

foldMap :: Monoid m => (a -> m) -> Triple a -> m #

foldr :: (a -> b -> b) -> b -> Triple a -> b #

foldr' :: (a -> b -> b) -> b -> Triple a -> b #

foldl :: (b -> a -> b) -> b -> Triple a -> b #

foldl' :: (b -> a -> b) -> b -> Triple a -> b #

foldr1 :: (a -> a -> a) -> Triple a -> a #

foldl1 :: (a -> a -> a) -> Triple a -> a #

toList :: Triple a -> [a] #

null :: Triple a -> Bool #

length :: Triple a -> Int #

elem :: Eq a => a -> Triple a -> Bool #

maximum :: Ord a => Triple a -> a #

minimum :: Ord a => Triple a -> a #

sum :: Num a => Triple a -> a #

product :: Num a => Triple a -> a #

Traversable Triple Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Triple a -> f (Triple b) #

sequenceA :: Applicative f => Triple (f a) -> f (Triple a) #

mapM :: Monad m => (a -> m b) -> Triple a -> m (Triple b) #

sequence :: Monad m => Triple (m a) -> m (Triple a) #

VectorNum Triple Source # 

Methods

fmapNum1 :: Num b => (a -> b) -> Triple a -> Triple b Source #

fmapNum2 :: Num c => (a -> b -> c) -> Triple a -> Triple b -> Triple c Source #

fmapNum1inv :: Num a => (a -> a) -> Triple a -> Triple a Source #

simpleVec :: Num a => a -> Triple a Source #

Coord3 Triple Source # 

Methods

getZ :: Triple a -> a Source #

Coord2 Triple Source # 

Methods

getX :: Triple a -> a Source #

getY :: Triple a -> a Source #

Coord Triple Source # 

Methods

getComponents :: Num a => Triple a -> [a] Source #

fromComponents :: Num a => [a] -> Triple a Source #

magSq :: Num a => Triple a -> a Source #

dotProduct :: Num a => Triple a -> Triple a -> a Source #

IsomorphicVectors Triple Rel3' Source # 

Methods

iso :: Num a => Triple a -> Rel3' a Source #

IsomorphicVectors Triple Point3' Source # 

Methods

iso :: Num a => Triple a -> Point3' a Source #

IsomorphicVectors Rel3' Triple Source # 

Methods

iso :: Num a => Rel3' a -> Triple a Source #

IsomorphicVectors Point3' Triple Source # 

Methods

iso :: Num a => Point3' a -> Triple a Source #

Geometry Triple Triple LineTriple Source # 

Methods

scaleRel :: Num a => a -> Triple a -> Triple a Source #

plusDir :: (Num a, Eq a, Show a) => Triple a -> Triple a -> Triple a Source #

fromPt :: (Num a, Eq a, Show a) => Triple a -> Triple a -> Triple a Source #

getLineVecs :: Num a => LineTriple a -> (Triple a, Triple a) Source #

makeLine :: Num a => Triple a -> Triple a -> LineTriple a Source #

Eq a => Eq (Triple a) Source # 

Methods

(==) :: Triple a -> Triple a -> Bool #

(/=) :: Triple a -> Triple a -> Bool #

(Show a, Eq a, Num a) => Num (Triple a) Source # 

Methods

(+) :: Triple a -> Triple a -> Triple a #

(-) :: Triple a -> Triple a -> Triple a #

(*) :: Triple a -> Triple a -> Triple a #

negate :: Triple a -> Triple a #

abs :: Triple a -> Triple a #

signum :: Triple a -> Triple a #

fromInteger :: Integer -> Triple a #

Ord a => Ord (Triple a) Source # 

Methods

compare :: Triple a -> Triple a -> Ordering #

(<) :: Triple a -> Triple a -> Bool #

(<=) :: Triple a -> Triple a -> Bool #

(>) :: Triple a -> Triple a -> Bool #

(>=) :: Triple a -> Triple a -> Bool #

max :: Triple a -> Triple a -> Triple a #

min :: Triple a -> Triple a -> Triple a #

Read a => Read (Triple a) Source # 
Show a => Show (Triple a) Source # 

Methods

showsPrec :: Int -> Triple a -> ShowS #

show :: Triple a -> String #

showList :: [Triple a] -> ShowS #

newtype Quad a Source #

A quad, which acts as a 4D vector.

Constructors

Quad (a, a, a, a) 

Instances

Functor Quad Source # 

Methods

fmap :: (a -> b) -> Quad a -> Quad b #

(<$) :: a -> Quad b -> Quad a #

Applicative Quad Source # 

Methods

pure :: a -> Quad a #

(<*>) :: Quad (a -> b) -> Quad a -> Quad b #

(*>) :: Quad a -> Quad b -> Quad b #

(<*) :: Quad a -> Quad b -> Quad a #

Foldable Quad Source # 

Methods

fold :: Monoid m => Quad m -> m #

foldMap :: Monoid m => (a -> m) -> Quad a -> m #

foldr :: (a -> b -> b) -> b -> Quad a -> b #

foldr' :: (a -> b -> b) -> b -> Quad a -> b #

foldl :: (b -> a -> b) -> b -> Quad a -> b #

foldl' :: (b -> a -> b) -> b -> Quad a -> b #

foldr1 :: (a -> a -> a) -> Quad a -> a #

foldl1 :: (a -> a -> a) -> Quad a -> a #

toList :: Quad a -> [a] #

null :: Quad a -> Bool #

length :: Quad a -> Int #

elem :: Eq a => a -> Quad a -> Bool #

maximum :: Ord a => Quad a -> a #

minimum :: Ord a => Quad a -> a #

sum :: Num a => Quad a -> a #

product :: Num a => Quad a -> a #

Traversable Quad Source # 

Methods

traverse :: Applicative f => (a -> f b) -> Quad a -> f (Quad b) #

sequenceA :: Applicative f => Quad (f a) -> f (Quad a) #

mapM :: Monad m => (a -> m b) -> Quad a -> m (Quad b) #

sequence :: Monad m => Quad (m a) -> m (Quad a) #

VectorNum Quad Source # 

Methods

fmapNum1 :: Num b => (a -> b) -> Quad a -> Quad b Source #

fmapNum2 :: Num c => (a -> b -> c) -> Quad a -> Quad b -> Quad c Source #

fmapNum1inv :: Num a => (a -> a) -> Quad a -> Quad a Source #

simpleVec :: Num a => a -> Quad a Source #

Coord3 Quad Source # 

Methods

getZ :: Quad a -> a Source #

Coord2 Quad Source # 

Methods

getX :: Quad a -> a Source #

getY :: Quad a -> a Source #

Coord Quad Source # 

Methods

getComponents :: Num a => Quad a -> [a] Source #

fromComponents :: Num a => [a] -> Quad a Source #

magSq :: Num a => Quad a -> a Source #

dotProduct :: Num a => Quad a -> Quad a -> a Source #

Eq a => Eq (Quad a) Source # 

Methods

(==) :: Quad a -> Quad a -> Bool #

(/=) :: Quad a -> Quad a -> Bool #

(Show a, Eq a, Num a) => Num (Quad a) Source # 

Methods

(+) :: Quad a -> Quad a -> Quad a #

(-) :: Quad a -> Quad a -> Quad a #

(*) :: Quad a -> Quad a -> Quad a #

negate :: Quad a -> Quad a #

abs :: Quad a -> Quad a #

signum :: Quad a -> Quad a #

fromInteger :: Integer -> Quad a #

Ord a => Ord (Quad a) Source # 

Methods

compare :: Quad a -> Quad a -> Ordering #

(<) :: Quad a -> Quad a -> Bool #

(<=) :: Quad a -> Quad a -> Bool #

(>) :: Quad a -> Quad a -> Bool #

(>=) :: Quad a -> Quad a -> Bool #

max :: Quad a -> Quad a -> Quad a #

min :: Quad a -> Quad a -> Quad a #

Read a => Read (Quad a) Source # 
Show a => Show (Quad a) Source # 

Methods

showsPrec :: Int -> Quad a -> ShowS #

show :: Quad a -> String #

showList :: [Quad a] -> ShowS #

newtype LinePair a Source #

A pair of (position vector, direction vector) to be used as a 2D line.

Constructors

LinePair (Pair a, Pair a) 

Instances

Geometry Pair Pair LinePair Source # 

Methods

scaleRel :: Num a => a -> Pair a -> Pair a Source #

plusDir :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

fromPt :: (Num a, Eq a, Show a) => Pair a -> Pair a -> Pair a Source #

getLineVecs :: Num a => LinePair a -> (Pair a, Pair a) Source #

makeLine :: Num a => Pair a -> Pair a -> LinePair a Source #

Eq a => Eq (LinePair a) Source # 

Methods

(==) :: LinePair a -> LinePair a -> Bool #

(/=) :: LinePair a -> LinePair a -> Bool #

Ord a => Ord (LinePair a) Source # 

Methods

compare :: LinePair a -> LinePair a -> Ordering #

(<) :: LinePair a -> LinePair a -> Bool #

(<=) :: LinePair a -> LinePair a -> Bool #

(>) :: LinePair a -> LinePair a -> Bool #

(>=) :: LinePair a -> LinePair a -> Bool #

max :: LinePair a -> LinePair a -> LinePair a #

min :: LinePair a -> LinePair a -> LinePair a #

Read a => Read (LinePair a) Source # 
Show a => Show (LinePair a) Source # 

Methods

showsPrec :: Int -> LinePair a -> ShowS #

show :: LinePair a -> String #

showList :: [LinePair a] -> ShowS #

newtype LineTriple a Source #

A pair of (position vector, direction vector) to be used as a 3D line.

Constructors

LineTriple (Triple a, Triple a)