# struct Geode::Vector4(T)

## Overview

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

T is the scalar type.

## Defined in:

geode/vectors/vector4.cr

## Constructor Detail

def self.new(x : T, y : T, z : T, w : T) #

Creates a vector from its components.

def self.new(components : Tuple(T, T, T, T)) #

Creates a vector from its components.

def self.new(array : StaticArray(T, 4)) #

Constructs the vector with pre-existing values.

def self.new(other : CommonVector(T, 4)) #

Copies the contents of another vector.

def self.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.

``Vector4(Int32).new { |i| i * 5 } # => (0, 5, 10, 15)``

## Class Method Detail

def self.[](x : T, y : T, z : T, w : T) #

Constructs a vector with existing components.

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

``Vector4[1, 2, 3, 4] # => (1, 2, 3, 4)``

def self.[](x, y, z, w) #

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.

``Vector4F[1, 2, 3, 4] # => (1.0, 2.0, 3.0, 4.0)``

## Instance Method Detail

def to_column : Matrix4x1(T) #

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

``````vector = Vector4[1, 2, 3, 4]
vector.to_column # => [[1], [2], [3], [4]]``````

def to_row : Matrix1x4(T) #

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

``````vector = Vector4[1, 2, 3, 4]
vector.to_row # => [[1, 2, 3, 4]]``````

def tuple : Tuple(T, T, T, T) #

Retrieves the components as a tuple.

def w : T #

Retrieves the w component.

def x : T #

Retrieves the x component.

def y : T #

Retrieves the y component.

def z : T #

Retrieves the z component.