struct SF::Vector3(T)

Overview

Utility generic struct for manipulating 2-dimensional vectors

SF::Vector3 is a simple struct that defines a mathematical vector with three coordinates (x, y and z). It can be used to represent anything that has three dimensions: a size, a point, a velocity, etc.

The generic parameter T is the type of the coordinates. It can be any type that supports arithmetic operations (+, -, /, *) and comparisons (==, !=), for example Int or Float.

You generally don't have to care about the generic form, the most common specialization has a special alias:

The SF::Vector3 struct has a small and simple interface, its #x, #y, #z members can be accessed directly and it contains no mathematical function like dot product, cross product, length, etc.

Note: for 2-dimensional vectors, see SF::Vector2.

Included Modules

Defined in:

system/system.cr

Constructors

Instance Method Summary

Constructor Detail

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

Construct the vector from its coordinates.


[View source]
def self.new #

Default constructor: equivalent to .new(0, 0, 0)


[View source]

Instance Method Detail

def *(n : Number) #

Memberwise multiplication by a scalar


[View source]
def +(other) #

Memberwise addition of two vectors


[View source]
def -(other) #

Memberwise subtraction of two vectors


[View source]
def - #

Memberwise opposite of the vector


[View source]
def /(n : Number) #

Memberwise division by a scalar


[View source]
def ==(other : Vector3) #

Returns true if all corresponding coordinates of two vectors are equal


[View source]
def [](i) #

Get a coordinate by its index: 0 is #x, 1 is #y, 2 is #z.

Raises IndexError for other indices.


[View source]
def each(&) #

Yields #x, then #y, then #z


[View source]
def size #

Returns 3


[View source]
def x : T #

The x coordinate


[View source]
def x=(x : T) #

The x coordinate


[View source]
def y : T #

The y coordinate


[View source]
def y=(y : T) #

The y coordinate


[View source]
def z : T #

The z coordinate


[View source]
def z=(z : T) #

The z coordinate


[View source]