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

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

 Source # Methodsfmap :: (a -> b) -> Pair a -> Pair b #(<$) :: a -> Pair b -> Pair a # Source # Methodspure :: a -> Pair a #(<*>) :: Pair (a -> b) -> Pair a -> Pair b #(*>) :: Pair a -> Pair b -> Pair b #(<*) :: Pair a -> Pair b -> Pair a # Source # Methodsfold :: 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 # Source # Methodstraverse :: 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) # Source # MethodsfmapNum1 :: 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 # Source # MethodsgetX :: Pair a -> a Source #getY :: Pair a -> a Source # Source # MethodsgetComponents :: 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 # Source # Methodsiso :: Num a => Pair a -> Rel2' a Source # Source # Methodsiso :: Num a => Pair a -> Point2' a Source # Source # Methodsiso :: Num a => Rel2' a -> Pair a Source # Source # Methodsiso :: Num a => Point2' a -> Pair a Source # Source # MethodsscaleRel :: 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 # Ord a => Ord (Pair a) Source # Methodscompare :: 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 # MethodsreadsPrec :: Int -> ReadS (Pair a) #readList :: ReadS [Pair a] # Show a => Show (Pair a) Source # MethodsshowsPrec :: 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  Source # Methodsfmap :: (a -> b) -> Triple a -> Triple b #(<$) :: a -> Triple b -> Triple a # Source # Methodspure :: a -> Triple a #(<*>) :: Triple (a -> b) -> Triple a -> Triple b #(*>) :: Triple a -> Triple b -> Triple b #(<*) :: Triple a -> Triple b -> Triple a # Source # Methodsfold :: 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 # Source # Methodstraverse :: 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) # Source # MethodsfmapNum1 :: 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 # Source # MethodsgetZ :: Triple a -> a Source # Source # MethodsgetX :: Triple a -> a Source #getY :: Triple a -> a Source # Source # MethodsgetComponents :: 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 # Source # Methodsiso :: Num a => Triple a -> Rel3' a Source # Source # Methodsiso :: Num a => Triple a -> Point3' a Source # Source # Methodsiso :: Num a => Rel3' a -> Triple a Source # Source # Methodsiso :: Num a => Point3' a -> Triple a Source # Source # MethodsscaleRel :: 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 # Ord a => Ord (Triple a) Source # Methodscompare :: 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 # MethodsreadsPrec :: Int -> ReadS (Triple a) #readList :: ReadS [Triple a] # Show a => Show (Triple a) Source # MethodsshowsPrec :: Int -> Triple a -> ShowS #show :: Triple a -> String #showList :: [Triple a] -> ShowS #

A quad, which acts as a 4D vector.

Constructors

Instances

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

 Source # MethodsscaleRel :: 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 # Methodscompare :: 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 # MethodsreadsPrec :: Int -> ReadS (LinePair a) # Show a => Show (LinePair a) Source # MethodsshowsPrec :: 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)

Instances

 Source # MethodsscaleRel :: 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 (LineTriple a) Source # Methods(==) :: LineTriple a -> LineTriple a -> Bool #(/=) :: LineTriple a -> LineTriple a -> Bool # Ord a => Ord (LineTriple a) Source # Methodscompare :: LineTriple a -> LineTriple a -> Ordering #(<) :: LineTriple a -> LineTriple a -> Bool #(<=) :: LineTriple a -> LineTriple a -> Bool #(>) :: LineTriple a -> LineTriple a -> Bool #(>=) :: LineTriple a -> LineTriple a -> Bool #max :: LineTriple a -> LineTriple a -> LineTriple a #min :: LineTriple a -> LineTriple a -> LineTriple a # Read a => Read (LineTriple a) Source # MethodsreadsPrec :: Int -> ReadS (LineTriple a) # Show a => Show (LineTriple a) Source # MethodsshowsPrec :: Int -> LineTriple a -> ShowS #show :: LineTriple a -> String #showList :: [LineTriple a] -> ShowS #