Module

Data.Vector3

Package
purescript-vectors
Repository
thought2/purescript-vectors

#Vec Source

data Vec a

Polymorphic 3D vector

Constructors

  • Vec a a a

    Creates a vector from three components

Instances

#vec Source

vec :: forall a. a -> a -> a -> Vec a

Creates a vector from two components

#oneX Source

oneX :: forall a. Semiring a => Vec a

Vector with Y value one and other values zero.

In analogy to the existing Semiring methods one and zero for Vec.

> oneX + oneY + oneZ == one
true

#oneY Source

oneY :: forall a. Semiring a => Vec a

Vector with Z value one and other values zero.

In analogy to the existing Semiring methods one and zero for Vec

> oneX + oneY + oneZ == one
true

#oneZ Source

oneZ :: forall a. Semiring a => Vec a

Vector with X value one and other values zero.

In analogy to the existing Semiring methods one and zero for Vec

> oneX + oneY + oneZ == one
true

#unVec Source

unVec :: forall a z. (a -> a -> a -> z) -> Vec a -> z

Pattern match on a vector by providing a reducer function

> unVec (\x y z -> x <> y <> z) (Vec "1" "2" "3")
"123"

#getX Source

getX :: forall a. Vec a -> a

Retrieves the X component of a vector

> getX (Vec 1 2 3)
1

#getY Source

getY :: forall a. Vec a -> a

Retrieves the Y component of a vector

> getY (Vec 1 2 3)
2

#getZ Source

getZ :: forall a. Vec a -> a

Retrieves the Z component of a vector

> getZ (Vec 1 2 3)
3

#rotRight Source

rotRight :: forall a. Vec a -> Vec a

Rotates the components of the vector to the right

> rotRight (Vec 1 2 3)
Vec 3 1 2

#rotLeft Source

rotLeft :: forall a. Vec a -> Vec a

Rotates the components of the vector to the left

> rotRight (Vec 1 2 3)
Vec 2 3 1

#vdiv Source

vdiv :: forall a. EuclideanRing a => Vec a -> Vec a -> Vec a

Divides two vectors componentwise. This exists because there cannot be an EuclideanRing instance for Vec

> vdiv (Vec 9 6 4) (Vec 3 2 4)
Vec 3 3 1

#(//) Source

Operator alias for Data.Vector3.vdiv (left-associative / precedence 7)

#vmod Source

vmod :: forall a. EuclideanRing a => Vec a -> Vec a -> Vec a

Componentwise Modulo operation This exists because there cannot be an EuclideanRing instance for Vec

> mod (Vec 12 120 1200) (Vec 120 100 1000)
Vec 2 20 200

#half Source

half :: forall a. EuclideanRing a => Vec a -> Vec a

Halves the amount of each component

> half (Vec 10 100 1000)
Vec 5 50 500

#twice Source

twice :: forall a. EuclideanRing a => Vec a -> Vec a

Duplicates the amount of each component

> twice (Vec 10 100 1000)
Vec 20 200 2000

#setX Source

setX :: forall a. a -> Vec a -> Vec a

Sets the X component of a vector

> setX "G" (Vec "A" "B" "C")
Vec "G" "B" "C"

#setY Source

setY :: forall a. a -> Vec a -> Vec a

Sets the Y component of a vector

> setY "G" (Vec "A" "B" "C")
Vec "A" "G" "C"

#setZ Source

setZ :: forall a. a -> Vec a -> Vec a

Sets the Z component of a vector

> setZ "G" (Vec "A" "B" "C")
Vec "A" "B" "G"

#modifyX Source

modifyX :: forall a. (a -> a) -> Vec a -> Vec a

Modifies the X component of a vector

> modifyX (add 10) (Vec 3 4 2)
Vec 13 4 2

#modifyY Source

modifyY :: forall a. (a -> a) -> Vec a -> Vec a

Modifies the Y component of a vector

> modifyY (add 10) (Vec 3 4 2)
Vec 3 14 2

#modifyZ Source

modifyZ :: forall a. (a -> a) -> Vec a -> Vec a

Modifies the Z component of a vector

> modifyZ (add 10) (Vec 3 4 2)
Vec 3 4 20

#_x Source

_x :: forall a. Lens' (Vec a) a

A Lens on the X component of a vector

#_y Source

_y :: forall a. Lens' (Vec a) a

A Lens on the Y component of a vector

#_z Source

_z :: forall a. Lens' (Vec a) a

A Lens on the Z component of a vector