Class: Float2

Float2

Float2 is a class describing 2-dimensional points.


new Float2(x, y)

Parameters:
Name Type Description
x

The x-coordinate

y

The y-coordinate

Author:
  • derschmale <http://www.derschmale.com>

Members


length

The length of the vector.


lengthSqr

The squared length of the vector.


<static> X_AXIS

A preset for the X-axis


<static> Y_AXIS

A preset for the Y-axis


<static> ZERO

A preset for the origin

Methods


abs()

Sets the components of this vector to their absolute values.


add()

Adds a vector to this one in place.


addScaled(v, s)

Adds a scalar multiple of another vector in place.

Parameters:
Name Type Description
v

The vector to scale and add.

s

The scale to apply to v


angle()

Returns the angle between this and another vector.


angleNormalized()

Returns the angle between two vectors, assuming they are normalized


clone()

Returns a copy of this object.


copyFrom()

Copies the values from a different Float2


distanceTo()

Returns the distance between this and another point.


dot()

Returns the dot product with another vector.


fromPolarCoordinates(radius, angle)

Sets the euclidian coordinates based on polar coordinates

Parameters:
Name Type Description
radius

The radius coordinate

angle

The angle coordinate


lerp(a, b, t)

Linearly interpolates two vectors.

Parameters:
Name Type Description
a Float2

The first vector to interpolate from.

b Float2

The second vector to interpolate to.

t Number

The interpolation factor.


maximize()

Replaces the components' values if those of the other Float2 are higher, respectively


minimize()

Replaces the components' values if those of the other Float2 are lower, respectively


negate()

Negates the components of this vector.


negativeOf()

Copies the negative of a vector


normalize()

Normalizes the vector.


scale()

Multiplies the components of this vector with a scalar.


set()

Sets the components explicitly.


squareDistanceTo()

Returns the squared distance between this and another point.


subtract()

Subtracts a vector from this one in place.


subtractScaled(v, s)

Subtracts a scaled vector from this one in place.

Parameters:
Name Type Description
v

The vector to scale and subtract.

s

The scale to apply to v


<static> add(a, b [, target])

Adds 2 vectors.

Parameters:
Name Type Argument Description
a
b
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The sum of a and b.


<static> scale(a, s [, target])

Multiplies a vector with a scalar.

Parameters:
Name Type Argument Description
a
s
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The product of a * s


<static> subtract(a, b [, target])

Subtracts 2 vectors.

Parameters:
Name Type Argument Description
a
b
target <optional>

An optional target object. If omitted, a new object will be created.

Returns:

The difference of a and b.