hgeometry-0.12.0.0: Geometric Algorithms, Data structures, and Data types.
Copyright(C) Frank Staals
Licensesee the LICENSE file
MaintainerFrank Staals
Safe HaskellNone
LanguageHaskell2010

Data.Geometry.Vector.VectorFamily

Description

Implementation of \(d\)-dimensional vectors. The implementation automatically selects an optimized representation for small (up to size 4) vectors.

Synopsis

d dimensional Vectors

newtype Vector (d :: Nat) (r :: *) Source #

Datatype representing d dimensional vectors. The default implementation is based n VectorFixed. However, for small vectors we automatically select a more efficient representation.

Constructors

MKVector 

Fields

Instances

Instances details
Arity d => FunctorWithIndex Int (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

imap :: (Int -> a -> b) -> Vector d a -> Vector d b #

Arity d => FoldableWithIndex Int (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

ifoldMap :: Monoid m => (Int -> a -> m) -> Vector d a -> m #

ifoldMap' :: Monoid m => (Int -> a -> m) -> Vector d a -> m #

ifoldr :: (Int -> a -> b -> b) -> b -> Vector d a -> b #

ifoldl :: (Int -> b -> a -> b) -> b -> Vector d a -> b #

ifoldr' :: (Int -> a -> b -> b) -> b -> Vector d a -> b #

ifoldl' :: (Int -> b -> a -> b) -> b -> Vector d a -> b #

Arity d => TraversableWithIndex Int (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

itraverse :: Applicative f => (Int -> a -> f b) -> Vector d a -> f (Vector d b) #

Arity d => Functor (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

fmap :: (a -> b) -> Vector d a -> Vector d b #

(<$) :: a -> Vector d b -> Vector d a #

Arity d => Applicative (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

pure :: a -> Vector d a #

(<*>) :: Vector d (a -> b) -> Vector d a -> Vector d b #

liftA2 :: (a -> b -> c) -> Vector d a -> Vector d b -> Vector d c #

(*>) :: Vector d a -> Vector d b -> Vector d b #

(<*) :: Vector d a -> Vector d b -> Vector d a #

Arity d => Foldable (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

fold :: Monoid m => Vector d m -> m #

foldMap :: Monoid m => (a -> m) -> Vector d a -> m #

foldMap' :: Monoid m => (a -> m) -> Vector d a -> m #

foldr :: (a -> b -> b) -> b -> Vector d a -> b #

foldr' :: (a -> b -> b) -> b -> Vector d a -> b #

foldl :: (b -> a -> b) -> b -> Vector d a -> b #

foldl' :: (b -> a -> b) -> b -> Vector d a -> b #

foldr1 :: (a -> a -> a) -> Vector d a -> a #

foldl1 :: (a -> a -> a) -> Vector d a -> a #

toList :: Vector d a -> [a] #

null :: Vector d a -> Bool #

length :: Vector d a -> Int #

elem :: Eq a => a -> Vector d a -> Bool #

maximum :: Ord a => Vector d a -> a #

minimum :: Ord a => Vector d a -> a #

sum :: Num a => Vector d a -> a #

product :: Num a => Vector d a -> a #

Arity d => Traversable (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

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

sequenceA :: Applicative f => Vector d (f a) -> f (Vector d a) #

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

sequence :: Monad m => Vector d (m a) -> m (Vector d a) #

Arity d => Arbitrary1 (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector

Methods

liftArbitrary :: Gen a -> Gen (Vector d a) #

liftShrink :: (a -> [a]) -> Vector d a -> [Vector d a] #

Arity d => Eq1 (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

liftEq :: (a -> b -> Bool) -> Vector d a -> Vector d b -> Bool #

Arity d => Read1 (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (Vector d a) #

liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [Vector d a] #

liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (Vector d a) #

liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [Vector d a] #

Arity d => Show1 (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> Vector d a -> ShowS #

liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [Vector d a] -> ShowS #

Arity d => Affine (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Associated Types

type Diff (Vector d) :: Type -> Type #

Methods

(.-.) :: Num a => Vector d a -> Vector d a -> Diff (Vector d) a #

(.+^) :: Num a => Vector d a -> Diff (Vector d) a -> Vector d a #

(.-^) :: Num a => Vector d a -> Diff (Vector d) a -> Vector d a #

Arity d => Metric (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

dot :: Num a => Vector d a -> Vector d a -> a #

quadrance :: Num a => Vector d a -> a #

qd :: Num a => Vector d a -> Vector d a -> a #

distance :: Floating a => Vector d a -> Vector d a -> a #

norm :: Floating a => Vector d a -> a #

signorm :: Floating a => Vector d a -> Vector d a #

Arity d => Additive (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

zero :: Num a => Vector d a #

(^+^) :: Num a => Vector d a -> Vector d a -> Vector d a #

(^-^) :: Num a => Vector d a -> Vector d a -> Vector d a #

lerp :: Num a => a -> Vector d a -> Vector d a -> Vector d a #

liftU2 :: (a -> a -> a) -> Vector d a -> Vector d a -> Vector d a #

liftI2 :: (a -> b -> c) -> Vector d a -> Vector d b -> Vector d c #

Arity d => Vector (Vector d) r Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

construct :: Fun (Peano (Dim (Vector d))) r (Vector d r) #

inspect :: Vector d r -> Fun (Peano (Dim (Vector d))) r b -> b #

basicIndex :: Vector d r -> Int -> r #

(Eq r, Arity d) => Eq (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

(==) :: Vector d r -> Vector d r -> Bool #

(/=) :: Vector d r -> Vector d r -> Bool #

(Ord r, Arity d) => Ord (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

compare :: Vector d r -> Vector d r -> Ordering #

(<) :: Vector d r -> Vector d r -> Bool #

(<=) :: Vector d r -> Vector d r -> Bool #

(>) :: Vector d r -> Vector d r -> Bool #

(>=) :: Vector d r -> Vector d r -> Bool #

max :: Vector d r -> Vector d r -> Vector d r #

min :: Vector d r -> Vector d r -> Vector d r #

(Read r, Arity d) => Read (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

(Show r, Arity d) => Show (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

showsPrec :: Int -> Vector d r -> ShowS #

show :: Vector d r -> String #

showList :: [Vector d r] -> ShowS #

(Random r, Arity d) => Random (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector

Methods

randomR :: RandomGen g => (Vector d r, Vector d r) -> g -> (Vector d r, g) #

random :: RandomGen g => g -> (Vector d r, g) #

randomRs :: RandomGen g => (Vector d r, Vector d r) -> g -> [Vector d r] #

randoms :: RandomGen g => g -> [Vector d r] #

(Arbitrary r, Arity d) => Arbitrary (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector

Methods

arbitrary :: Gen (Vector d r) #

shrink :: Vector d r -> [Vector d r] #

(Arity d, Hashable r) => Hashable (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

hashWithSalt :: Int -> Vector d r -> Int #

hash :: Vector d r -> Int #

(ToJSON r, Arity d) => ToJSON (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

toJSON :: Vector d r -> Value #

toEncoding :: Vector d r -> Encoding #

toJSONList :: [Vector d r] -> Value #

toEncodingList :: [Vector d r] -> Encoding #

(FromJSON r, Arity d) => FromJSON (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

parseJSON :: Value -> Parser (Vector d r) #

parseJSONList :: Value -> Parser [Vector d r] #

(NFData r, Arity d) => NFData (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

rnf :: Vector d r -> () #

Arity d => Ixed (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Methods

ix :: Index (Vector d r) -> Traversal' (Vector d r) (IxValue (Vector d r)) #

(Fractional r, Arity d, Arity (d + 1)) => IsTransformable (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Transformation

Methods

transformBy :: Transformation (Dimension (Vector d r)) (NumType (Vector d r)) -> Vector d r -> Vector d r Source #

type Dim (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

type Dim (Vector d) = FromPeano (Peano d)
type Diff (Vector d) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

type Diff (Vector d) = Vector d
type Index (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

type Index (Vector d r) = Int
type IxValue (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

type IxValue (Vector d r) = r
type NumType (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector

type NumType (Vector d r) = r
type Dimension (Vector d r) Source # 
Instance details

Defined in Data.Geometry.Vector

type Dimension (Vector d r) = d

unV :: Iso (Vector d r) (Vector d s) (VectorFamily (Peano d) r) (VectorFamily (Peano d) s) Source #

Vectors are isomorphic to a definition determined by VectorFamily.

class (ImplicitArity (Peano d), KnownNat d) => Arity d Source #

Instances

Instances details
(ImplicitArity (Peano d), KnownNat d) => Arity d Source # 
Instance details

Defined in Data.Geometry.Vector.VectorFamily

Convenience "constructors"

pattern Vector :: VectorFamilyF (Peano d) r -> Vector d r Source #

Constant sized vector with d elements.

pattern Vector1 :: r -> Vector 1 r Source #

Constant sized vector with 1 element.

pattern Vector2 :: r -> r -> Vector 2 r Source #

Constant sized vector with 2 elements.

pattern Vector3 :: r -> r -> r -> Vector 3 r Source #

Constant sized vector with 3 elements.

pattern Vector4 :: r -> r -> r -> r -> Vector 4 r Source #

Constant sized vector with 4 elements.

vectorFromList :: Arity d => [r] -> Maybe (Vector d r) Source #

\( O(n) \) Convert from a list to a non-empty vector.

vectorFromListUnsafe :: Arity d => [r] -> Vector d r Source #

\( O(n) \) Convert from a list to a non-empty vector.

destruct :: (Arity d, Arity (d + 1)) => Vector (d + 1) r -> (r, Vector d r) Source #

\( O(n) \) Pop the first element off a vector.

head :: (Arity d, 1 <= d) => Vector d r -> r Source #

\( O(1) \) First element. Since arity is at least 1, this function is total.

Indexing vectors

element :: forall proxy i d r. (Arity d, KnownNat i, (i + 1) <= d) => proxy i -> Lens' (Vector d r) r Source #

Lens into the i th element

element' :: forall d r. Arity d => Int -> Traversal' (Vector d r) r Source #

Similar to element above. Except that we don't have a static guarantee that the index is in bounds. Hence, we can only return a Traversal

Snoccing and consindg

cons :: (Arity d, Arity (d + 1)) => r -> Vector d r -> Vector (d + 1) r Source #

\( O(n) \) Prepend an element.

snoc :: (Arity (d + 1), Arity d) => Vector d r -> r -> Vector (d + 1) r Source #

Add an element at the back of the vector

init :: (Arity d, Arity (d + 1)) => Vector (d + 1) r -> Vector d r Source #

Get a vector of the first d - 1 elements.

last :: forall d r. (KnownNat d, Arity (d + 1)) => Vector (d + 1) r -> r Source #

\( O(1) \) Last element. Since the vector is non-empty, runtime bounds checks are bypassed.

prefix :: forall i d r. (Arity d, Arity i, i <= d) => Vector d r -> Vector i r Source #

Get a prefix of i elements of a vector

Specific on 3-dimensional vectors

cross :: Num r => Vector 3 r -> Vector 3 r -> Vector 3 r Source #

Cross product of two three-dimensional vectors