| Copyright | (C) Frank Staals |
|---|---|
| License | see the LICENSE file |
| Maintainer | Frank Staals |
| Safe Haskell | None |
| Language | GHC2024 |
HGeometry.Vector.Class
Contents
Description
A Class defining d-dimensional vectors
Synopsis
- class (r ~ IxValue vector, s ~ IxValue vector', d ~ Dimension vector, d ~ Dimension vector') => AsVector_ vector vector' (d :: Nat) r s | vector -> d, vector -> r, vector' -> s where
- class (HasComponents vector vector, AsVector_ vector vector d r r, KnownNat d) => Vector_ vector (d :: Nat) r where
- generateA :: Applicative f => (Int -> f r) -> f vector
- component' :: Int -> IndexedTraversal' Int vector r
- type Has_ (c :: Type -> Nat -> Type -> k) (d :: Nat) r = c (Vector d r) d r
- generate :: forall vector (d :: Nat) r. Vector_ vector d r => (Int -> r) -> vector
- vectorFromList :: forall vector (d :: Nat) r. Vector_ vector d r => [r] -> Maybe vector
- component :: forall (i :: Natural) vector r (d :: Natural). (i <= (d - 1), KnownNat i, Vector_ vector d r) => IndexedLens' Int vector r
- xComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 0 <= (d - 1)) => IndexedLens' Int vector r
- yComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 1 <= (d - 1)) => IndexedLens' Int vector r
- zComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 2 <= (d - 1)) => IndexedLens' Int vector r
- wComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 3 <= (d - 1)) => IndexedLens' Int vector r
- prefix :: forall (i :: Nat) (d :: Nat) vector vector' r. (i <= d, Vector_ vector d r, Vector_ vector' i r) => vector -> vector'
- suffix :: forall (i :: Nat) (d :: Nat) vector vector' r. (i <= d, Vector_ vector d r, Vector_ vector' i r) => vector -> vector'
- cons :: forall vector' vector (d :: Nat) r. (Vector_ vector d r, Vector_ vector' (d + 1) r) => r -> vector -> vector'
- snoc :: forall vector' vector (d :: Nat) r. (Vector_ vector d r, Vector_ vector' (d + 1) r) => vector -> r -> vector'
- uncons :: forall vector' vector (d :: Natural) r. (Vector_ vector (d + 1) r, Vector_ vector' d r, 0 <= ((d + 1) - 1), d <= Dimension vector) => vector -> (r, vector')
- unsnoc :: forall vector' vector (d :: Natural) r. (Vector_ vector (d + 1) r, Vector_ vector' d r, d <= ((d + 1) - 1), d <= Dimension vector) => vector -> (vector', r)
- class Vector_ vector d r => Additive_ vector (d :: Nat) r where
- zero :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => vector
- liftI2 :: forall vector (d :: Nat) r. Additive_ vector d r => (r -> r -> r) -> vector -> vector -> vector
- lerp :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => r -> vector -> vector -> vector
- (^+^) :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => vector -> vector -> vector
- (^-^) :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => vector -> vector -> vector
- negated :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => vector -> vector
- (*^) :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => r -> vector -> vector
- (^*) :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => vector -> r -> vector
- (^/) :: forall vector (d :: Nat) r. (Vector_ vector d r, Fractional r) => vector -> r -> vector
- sumV :: forall f vector (d :: Nat) r. (Foldable f, Additive_ vector d r, Num r) => f vector -> vector
- basis :: forall vector (d :: Nat) r. (Additive_ vector d r, Num r) => [vector]
- unit :: forall vector (d :: Nat) r. (Additive_ vector d r, Num r) => vector
- foldMapZip :: forall vector (d :: Nat) r m. (Additive_ vector d r, Semigroup m) => (r -> r -> m) -> vector -> vector -> m
- class Additive_ vector d r => Metric_ vector (d :: Nat) r where
Documentation
class (r ~ IxValue vector, s ~ IxValue vector', d ~ Dimension vector, d ~ Dimension vector') => AsVector_ vector vector' (d :: Nat) r s | vector -> d, vector -> r, vector' -> s where Source #
Types that can be converted to and from our canonical 'Vector d r' type
Methods
_Vector :: Iso vector vector' (Vector d r) (Vector d s) Source #
Convert from a 'Vector d r' and into a 'Vector d s'
class (HasComponents vector vector, AsVector_ vector vector d r r, KnownNat d) => Vector_ vector (d :: Nat) r where Source #
Class for representing d dimensional vectors.
Minimal complete definition
Methods
generateA :: Applicative f => (Int -> f r) -> f vector Source #
Generates a vector from an Applicative operation (that takes the index)
component' :: Int -> IndexedTraversal' Int vector r Source #
traversal to access the i^th coordinate.
default component' :: (Index vector ~ Int, Ixed vector) => Int -> IndexedTraversal' Int vector r Source #
Instances
type Has_ (c :: Type -> Nat -> Type -> k) (d :: Nat) r = c (Vector d r) d r Source #
Specifies that we have an appropriate constraint for the vector implementation
generate :: forall vector (d :: Nat) r. Vector_ vector d r => (Int -> r) -> vector Source #
Generate a vector from a given function.
vectorFromList :: forall vector (d :: Nat) r. Vector_ vector d r => [r] -> Maybe vector Source #
Convert a list of exactly d elements into a vector with dimension d.
>>>vectorFromList [10,2,3] :: Maybe (Vector 3 Int)Just (Vector3 10 2 3)>>>vectorFromList [10,2,3,5] :: Maybe (Vector 3 Int)Nothing>>>vectorFromList [10,2] :: Maybe (Vector 3 Int)Nothing
component :: forall (i :: Natural) vector r (d :: Natural). (i <= (d - 1), KnownNat i, Vector_ vector d r) => IndexedLens' Int vector r Source #
Lens to access te i^t component.
>>>myVec3 ^. component @01>>>myVec3 ^. component @12>>>myVec3 & component @1 %~ (*5)Vector3 1 10 3>>>myVec2 & component @1 %~ (*5)Vector2 10 100
xComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 0 <= (d - 1)) => IndexedLens' Int vector r Source #
Shorthand for accessing the x-component
>>>Vector3 1 2 3 ^. xComponent1>>>Vector2 1 2 & xComponent .~ 10Vector2 10 2
yComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 1 <= (d - 1)) => IndexedLens' Int vector r Source #
Shorthand for accessing the y-component
>>>Vector3 1 2 3 ^. yComponent2>>>Vector2 1 2 & yComponent .~ 10Vector2 1 10
zComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 2 <= (d - 1)) => IndexedLens' Int vector r Source #
Shorthand for accessing the z-component
>>>Vector3 1 2 3 ^. zComponent3>>>Vector3 1 2 3 & zComponent .~ 10Vector3 1 2 10
wComponent :: forall vector (d :: Nat) r. (Vector_ vector d r, 3 <= (d - 1)) => IndexedLens' Int vector r Source #
Shorthand for accessing the w-component
>>>Vector4 1 2 3 4 ^. wComponent4>>>Vector4 1 2 3 4 & wComponent .~ 10Vector4 1 2 3 10
prefix :: forall (i :: Nat) (d :: Nat) vector vector' r. (i <= d, Vector_ vector d r, Vector_ vector' i r) => vector -> vector' Source #
Take a prefix of length i of the vector
>>>prefix myVec3 :: Vector 2 IntVector2 1 2
suffix :: forall (i :: Nat) (d :: Nat) vector vector' r. (i <= d, Vector_ vector d r, Vector_ vector' i r) => vector -> vector' Source #
Take a suffix of length i of the vector
>>>suffix @_ @_ @_ @(Vector 2 Int) myVec3Vector2 2 3
cons :: forall vector' vector (d :: Nat) r. (Vector_ vector d r, Vector_ vector' (d + 1) r) => r -> vector -> vector' Source #
Add an element to the front of the vector
>>>cons 5 myVec2 :: Vector 3 IntVector3 5 10 20
snoc :: forall vector' vector (d :: Nat) r. (Vector_ vector d r, Vector_ vector' (d + 1) r) => vector -> r -> vector' Source #
Add an element to the back of the vector.
>>>snoc myVec2 5 :: Vector 3 IntVector3 10 20 5
uncons :: forall vector' vector (d :: Natural) r. (Vector_ vector (d + 1) r, Vector_ vector' d r, 0 <= ((d + 1) - 1), d <= Dimension vector) => vector -> (r, vector') Source #
Extract the first element from the vector
>>>uncons myVec3 :: (Int, Vector 2 Int)(1,Vector2 2 3)
unsnoc :: forall vector' vector (d :: Natural) r. (Vector_ vector (d + 1) r, Vector_ vector' d r, d <= ((d + 1) - 1), d <= Dimension vector) => vector -> (vector', r) Source #
Extract the last element from the vector
>>>unsnoc myVec3 :: (Vector 2 Int, Int)(Vector2 1 2,3)
class Vector_ vector d r => Additive_ vector (d :: Nat) r where Source #
Class that supports additive opreations on vectors
Methods
liftU2 :: (r -> r -> r) -> vector -> vector -> vector Source #
Apply a function to merge the 'non-zero' components of two vectors, unioning the rest of the values.
liftI2A :: Apply f => (r -> r -> f r) -> vector -> vector -> f vector Source #
Apply an Applicative function to the components of two vectors.
liftI2 :: forall vector (d :: Nat) r. Additive_ vector d r => (r -> r -> r) -> vector -> vector -> vector Source #
Apply a function to the components of two vectors.
lerp :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => r -> vector -> vector -> vector Source #
Linearly interpolate between the two vectors
(^+^) :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => vector -> vector -> vector infixl 6 Source #
add two vectors
(^-^) :: forall r vector (d :: Nat). (Num r, Additive_ vector d r) => vector -> vector -> vector infixl 6 Source #
subtract vectors
negated :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => vector -> vector Source #
negate v
(*^) :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => r -> vector -> vector infixl 7 Source #
left scalar multiplication
(^*) :: forall r vector (d :: Nat). (Num r, Vector_ vector d r) => vector -> r -> vector infixl 7 Source #
right scalar multiplication
(^/) :: forall vector (d :: Nat) r. (Vector_ vector d r, Fractional r) => vector -> r -> vector infixl 7 Source #
scalar division
sumV :: forall f vector (d :: Nat) r. (Foldable f, Additive_ vector d r, Num r) => f vector -> vector Source #
sum a collection of vectors.
basis :: forall vector (d :: Nat) r. (Additive_ vector d r, Num r) => [vector] Source #
Produce a default basis for a vector space. If the dimensionality
of the vector space is not statically known, see basisFor.
foldMapZip :: forall vector (d :: Nat) r m. (Additive_ vector d r, Semigroup m) => (r -> r -> m) -> vector -> vector -> m Source #
"zip through the two vectors", folding over the result.
as an example, we can implement the dot product of two vectors u and v using:
>>>let myDot u v = getSum $ foldMapZip (\x x' -> Sum $ x * x') u v>>>myDot (Vector3 1 2 3) (Vector3 10 20 30)140
class Additive_ vector d r => Metric_ vector (d :: Nat) r where Source #
The equivalent class of Linear.Metric
Note that we do not define a distance itself, and that norm and signorm have a Radical constraint rather than Floating.
Minimal complete definition
Nothing
Methods
dot :: vector -> vector -> r Source #
Compute the inner product of two vectors or (equivalently) convert a vector f a into a covector f a -> a.
quadrance :: vector -> r Source #
Compute the squared norm. The name quadrance arises from Norman J. Wildberger's rational trigonometry.
qd :: vector -> vector -> r Source #
Compute the quadrance of the difference
Compute the norm of a vector in a metric space
signorm :: vector -> vector Source #
Convert a non-zero vector to unit vector.
Orphan instances
| (Vector_ (Vector d r) d r, Read r, KnownNat d) => Read (Vector d r) Source # | |
| (Additive_ (Vector d r) d r, Uniform r, UniformRange r, Ord (Vector d r)) => Random (Vector d r) Source # | |
| (Vector_ (Vector d r) d r, Uniform r) => Uniform (Vector d r) Source # | |
Methods uniformM :: StatefulGen g m => g -> m (Vector d r) Source # | |
| (Additive_ (Vector d r) d r, UniformRange r, Ord (Vector d r)) => UniformRange (Vector d r) Source # | |