Module

Data.Vector2

Package
purescript-vectors
Repository
thought2/purescript-vectors

#Vec Source

data Vec a

Polymorphic 2D vector

Constructors

  • Vec a a

    Creates a vector from two components

Instances

#vec Source

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

Creates a vector from two components

#oneX Source

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

Vector with X value one and Y value zero.

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

> oneX + oneY == one
true

#oneY Source

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

Vector with X value zero and Y value one.

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

> oneX + oneY == one
true

#unVec Source

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

Pattern match on a vector by providing a reducer function

> unVec (+) (Vec 1 2)
3

#getX Source

getX :: forall a. Vec a -> a

Retrieves the X component of a vector

> getX (Vec 1 2)
1

#getY Source

getY :: forall a. Vec a -> a

Retrieves the Y component of a vector

> getY (Vec 1 2)
2

#swap Source

swap :: forall a. Vec a -> Vec a

Exchanges the X and Y component of a vector

> swap (Vec 1 2)
Vec 2 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) (Vec 3 2)
Vec 3 3

#(//) Source

Operator alias for Data.Vector2.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) (Vec 120 100)
Vec 2 20

#half Source

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

Halves the amount of each component

> half (Vec 10 100)
Vec 5 50

#twice Source

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

Duplicates the amount of each component

> twice (Vec 10 100)
Vec 20 200

#setX Source

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

Sets the X component of a vector

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

#setY Source

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

Sets the Y component of a vector

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

#modifyX Source

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

Modifies the X component of a vector

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

#modifyY Source

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

Modifies the Y component of a vector

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

#_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