API Docs for: 1.4.0
Show:

Kiwi.Geom.Vector2 Class

Defined in: src\geom\Vector2.ts:9
Module: Geom
Parent Module: Kiwi

A two dimensional vector object for storing and manipulating x and y vector components.

Constructor

Kiwi.Geom.Vector2

(
  • [x=0]
  • [y=0]
)
Kiwi.Geom.Vector2

Parameters:

  • [x=0] Number optional

    The x component of the vector.

  • [y=0] Number optional

    The y component of the vector.

Returns:

Methods

add

(
  • Vector2
)
Kiwi.Geom.Vector2 public

Add each component of another Vector2 to this vectors components.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the product

addX

(
  • vector2
)
Kiwi.Geom.Vector2 public

Add only the x component of another Vector2 to this vector.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the result

addY

(
  • vector2
)
Kiwi.Geom.Vector2 public

Add only the y component of another Vector2 to this vector.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the result

ceil

() Kiwi.Geom.Vector2 public

Increase each component of the Vector to the closest upper round value.

Returns:

Kiwi.Geom.Vector2:

a rounded up Vector2.

clamp

(
  • min
  • max
)
Kiwi.Geom.Vector2 public

Clamp the vector between a maximum and minimum Vector2 range component-wise.

Parameters:

Returns:

Kiwi.Geom.Vector2:

a clamped Vector2.

clear

() Kiwi.Geom.Vector2 public

Set both components to zero.

Returns:

Kiwi.Geom.Vector2:

This object.

clone

(
  • [output]
)
Kiwi.Geom.Vector2 public

Get a clone of this Vector2.

Parameters:

  • [output] Kiwi.Geom.Vector2 optional

    Optional. A vector2 that will be cloned to. One will be created if none passed.

Returns:

Kiwi.Geom.Vector2:

Either a new cloned Vector2 or the output vector with cloned components.

copyFrom

(
  • source
)
Kiwi.Geom.Vector2 public

Copy components from another Vector2.

Parameters:

Returns:

Kiwi.Geom.Vector2:

This object.

copyTo

(
  • target
)
Kiwi.Geom.Vector2 public

Copy components to another Vector2.

Parameters:

Returns:

Kiwi.Geom.Vector2:

The supplied Vector2.

dot

(
  • vector2
)
Number public

Calculate the dot product if a Vector2 with this Vector2.

Parameters:

Returns:

Number:

Result of dot product.

equal

(
  • vector2
)
Boolean public

Check if two Vector2s from equal components.

Parameters:

Returns:

Boolean:

returns true if equal.

floor

() Kiwi.Geom.Vector2 public

Reduce each component of the Vector to the closest lower round value.

Returns:

Kiwi.Geom.Vector2:

a rounded down Vector2.

fromAngle

(
  • angle
)
Kiwi.Geom.Vector2 public static

Generate a Vector2 from an angle

Parameters:

  • angle Number

    The angle to generate the Vector2 from.

Returns:

Kiwi.Geom.Vector2:

A new Vector2

fromPoint

(
  • point
)
Kiwi.Geom.Vector2 public static

Generate a Vector2 from a point.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2

len

() Number public

Calculate the length of this Vector2 (Distance from the origin).

Returns:

Number:

The length.

lenSqr

() Number public

Calculate the square length of this Vector2 (Distance from the origin).

Returns:

Number:

The square length.

multiply

(
  • vector2
)
Kiwi.Geom.Vector2 public

Multiply each component of another Vector2 with this vectors components.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the result

multiplyScalar

(
  • scalar
)
Kiwi.Geom.Vector2 public

Multiply each component of this vector with a scalar number.

Parameters:

  • scalar Number

    Scalar to multiply

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the result

neg

() Kiwi.Geom.Vector2 public

Calculate a Vector2 opposite to this Vector2.

Returns:

Kiwi.Geom.Vector2:

the opposite Vector2.

objType

() String public

The type of this object.

Returns:

String:

"Vector2"

perp

() Kiwi.Geom.Vector2 public

Calculate a Vector2 perpendicular to this Vector2.

Returns:

Kiwi.Geom.Vector2:

the perpendicular Vector2.

point

() Kiwi.Geom.Point public

Get a Point object with the same components as this Vector2.

Returns:

Kiwi.Geom.Point:

A new Point.

randomRadius

(
  • radius
)
Kiwi.Geom.Vector2 public static

Generate a random Vector2 within a given radius.

Parameters:

  • radius Number

    The size of the radius to use.

Returns:

Kiwi.Geom.Vector2:

A new Vector2

round

() Kiwi.Geom.Vector2 public

Round each component of the Vector to the closest round value.

Returns:

Kiwi.Geom.Vector2:

a rounded Vector2.

setTo

(
  • x
  • y
)
Kiwi.Geom.Vector2 public

Set components on this Vector2.

Parameters:

  • x Number

    x component to set.

  • y Number

    y component to set.

Returns:

Kiwi.Geom.Vector2:

This object.

subtract

(
  • vector2
)
Kiwi.Geom.Vector2 public

Subtract each component of another Vector2 from this vectors components.

Parameters:

Returns:

Kiwi.Geom.Vector2:

A new Vector2 containing the result

toString

() String

Get a string representation of this object.

Returns:

String:

This object as a string.

unit

() Kiwi.Geom.Vector2 public

Calculate a normalised unit Vector2 from this Vector2.

Returns:

Kiwi.Geom.Vector2:

a new Unit Length Vector2.

Properties

x

Number public

The x component of this Vector2.

y

Number public

The y component of this Vector2.