struct

Geode::Vector2(T)

Inherits Geode::VectorBase < Geode::CommonVector < Geode::VectorOperations < Geode::VectorMatrices < Geode::VectorGeometry < Geode::VectorComparison < Indexable < Enumerable < Iterable < Struct < Value < Object

Vector containing two components. Provides a collection of scalars of the same type.

T is the scalar type.

Constructors

new(x : T, y : T)

Creates a vector from its components.

Source
new(components : Tuple(T, T))

Creates a vector from its components.

Source
new(array : StaticArray(T, 2))

Constructs the vector with pre-existing values.

Source
new(other : CommonVector(T, 2))

Copies the contents of another vector.

Source
new

Constructs the vector by yielding for each component.

The value of each component should be returned from the block. The block will be given the index of each component as an argument.

Vector2(Int32).new { |i| i * 5 } # => (0, 5)
Source

Class methods

[](x : T, y : T)

Constructs a vector with existing components.

The type of the components is derived from the type of each argument.

Vector2[1, 2] # => (1, 2)
Source
[](x, y)

Constructs a vector with existing components.

The type of the components is specified by the type parameter. Each value is cast to the type T.

Vector2F[1, 2] # => (1.0, 2.0)
Source

Instance methods

angle

Computes the rotation of the vector.

Returns the value as radians. The value will be between 0 and 2 pi.

Vector2[1, 1].angle # => 0.785398163
Source
rotate(angle : Number | Angle) : Vector2

Computes a new vector from rotating this one.

The angle must be a Number in radians or an Angle.

Vector2[1.0, 1.0].rotate(180.degrees) # => (-1.0, -1.0)
Source
signed_angle(other : CommonVector(U, 2)) : Number forall U

Computes the angle between this vector and another.

Returns the value as radians. The value will be between -pi and +pi.

The smallest angle between the vectors is calculated.

Positive values indicate that the other vector can be reached by rotating this vector in a positive direction. On a standard coordinate system, this means rotating counter-clockwise. Negative values indicate the opposite - clockwise rotation.

Vector2[1, 1].signed_angle(Vector2[-1, 0]) # => 2.35619449
Vector2[1, 1].signed_angle(Vector2[1, -1]) # => -1.570796327
Source
signed_angle

Computes the rotation of the vector.

Returns the value as radians. The value will be between -pi and +pi.

Vector2[1, 1].signed_angle   # => 0.785398163
Vector2[-1, -1].signed_angle # => -2.35619449
Source
to_column

Converts this vector to a column vector, in other words a matrix with one column.

vector = Vector2[1, 2]
vector.to_column # => [[1], [2]]
Source
to_row

Converts this vector to a row vector, in other words a matrix with one row.

vector = Vector2[1, 2]
vector.to_row # => [[1, 2]]
Source
tuple

Retrieves the components as a tuple.

Source
x

Retrieves the x component.

Source
y

Retrieves the y component.

Source