API Docs for: 0.5.5
Show:

kick.math.Vec2 Class

Defined in: kick/math/Vec2.js:14
Module: kick.math

Vec2 - 2 dimensional vector Any javascript array containing at least 2 numeric elements can serve as a vec2

Item Index

Methods

Methods

add

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Adds two vec2's

Parameters:

Returns:

array

(
  • count
  • ref
)
kick.math.Vec2 static

Create a continuous array in memory mapped to vec2.

Parameters:

  • count Number

    Number of vec 2 to be layed out in memory

  • ref Object

    Optional, if set a memory reference is set to ref.mem

Returns:

kick.math.Vec2:

New vec2

clone

(
  • a
)
kick.math.Vec2 static

Parameters:

Returns:

kick.math.Vec2:

a new 2D vector

copy

(
  • out
  • a
)
kick.math.Vec2 static

Copies the values of one vec2 to another

Parameters:

Returns:

create

() kick.math.Vec2 static

Creates a new, empty vec2

Returns:

kick.math.Vec2:

New vec2

cross

(
  • out
  • a
  • b
)
kick.math.Vec3 static

Computes the cross product of two vec2's Note that the cross product must by definition produce a 3D vector

Parameters:

Returns:

distance

(
  • a
  • b
)
Number static

Calculates the euclidian distance between two vec2's

Parameters:

Returns:

Number:

distance between a and b

divide

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Divides two vec2's

Parameters:

Returns:

dot

(
  • a
  • b
)
Number static

Calculates the dot product of two vec2's

Parameters:

Returns:

Number:

dot product of a and b

equal

(
  • vec
  • vec2
  • epsilon
)
Boolean static

Test to see if vectors are equal (difference is less than epsilon)

Parameters:

Returns:

Boolean:

true if two vectors are equals

forEach

(
  • a
  • stride
  • offset
  • count
  • fn
  • [arg]
)
Array static

Perform some operation over an array of vec2s.

Parameters:

  • a Array

    the array of vectors to iterate over

  • stride Number

    Number of elements between the start of each vec2. If 0 assumes tightly packed

  • offset Number

    Number of elements to skip at the beginning of the array

  • count Number

    Number of vec2s to iterate over. If 0 iterates over entire array

  • fn Function

    Function to call for each vector in the array

  • [arg] Object optional

    additional argument to pass to fn

Returns:

Array:

a

fromValues

(
  • x
  • y
)
kick.math.Vec2 static

Creates a new vec2 initialized with the given values

Parameters:

  • x Number

    X component

  • y Number

    Y component

Returns:

kick.math.Vec2:

a new 2D vector

length

(
  • a
)
Number static

Calculates the length of a vec2

Parameters:

Returns:

Number:

length of a

lerp

(
  • out
  • a
  • b
  • t
)
kick.math.Vec2 static

Performs a linear interpolation between two vec2's

Parameters:

Returns:

max

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Returns the maximum of two vec2's

Parameters:

Returns:

min

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Returns the minimum of two vec2's

Parameters:

Returns:

multiply

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Multiplies two vec2's

Parameters:

Returns:

negate

(
  • out
  • a
)
kick.math.Vec2 static

Negates the components of a vec2

Parameters:

Returns:

normalize

(
  • out
  • a
)
kick.math.Vec2 static

Normalize a vec2

Parameters:

Returns:

scale

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Scales a vec2 by a scalar number

Parameters:

Returns:

set

(
  • out
  • x
  • y
)
kick.math.Vec2 static

Set the components of a vec2 to the given values

Parameters:

  • out kick.math.Vec2

    the receiving vector

  • x Number

    X component

  • y Number

    Y component

Returns:

squaredDistance

(
  • a
  • b
)
Number static

Calculates the squared euclidian distance between two vec2's

Parameters:

Returns:

Number:

squared distance between a and b

squaredLength

(
  • a
)
Number static

Calculates the squared length of a vec2

Parameters:

Returns:

Number:

squared length of a

str

(
  • vec
)
String static

Returns a string representation of a vector

Parameters:

Returns:

String:

string representation of vec

subtract

(
  • out
  • a
  • b
)
kick.math.Vec2 static

Subtracts two vec2's

Parameters:

Returns:

transformMat2

(
  • out
  • a
  • m
)
kick.math.Vec2 static

Transforms the vec2 with a mat2

Parameters:

Returns:

transformMat2d

(
  • out
  • a
  • m
)
kick.math.Vec2 static

Transforms the vec2 with a mat2d

Parameters:

Returns:

transformMat3

(
  • out
  • a
  • m
)
kick.math.Vec2 static

Transforms the vec2 with a mat3 3rd vector component is implicitly '1'

Parameters:

Returns:

transformMat4

(
  • out
  • a
  • m
)
kick.math.Vec2 static

Transforms the vec2 with a mat4 3rd vector component is implicitly '0' 4th vector component is implicitly '1'

Parameters:

Returns:

wrapArray

(
  • array
)
Array_kick.math.Vec2 static

See kick.math.Vec4.wrapArray

Parameters:

  • array Float32Array

Returns:

Array_kick.math.Vec2:

of vec2