hgeometry-0.12.0.4: Geometric Algorithms, Data structures, and Data types.

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_unV :: VectorFamily (Peano d) r

#### Instances

Instances details

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 detailsDefined 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