Skip to content

Class endstone::Vector

ClassList > endstone > Vector

Represents a 3-dimensional vector.

  • #include <endstone/util/vector.h>

Inherited by the following classes: endstone::Location

Public Functions

Type Name
constexpr Vector () = default
Construct the vector with all components as 0.
constexpr Vector (T x, T y, T z)
Construct the vector with provided components.
float distance (const Vector & other) const
constexpr float distanceSquared (const Vector & other) const
constexpr float getX () const
Gets the X component.
constexpr float getY () const
Gets the Y component.
constexpr float getZ () const
Gets the Z component.
float length () const
Gets the magnitude of the vector, defined as sqrt(x2+y2+z^2).
constexpr float lengthSquared () const
Gets the magnitude of the vector squared.
Vector & normalize ()
constexpr Vector operator* (const Vector & other) const
Vector operator* (float scalar) const
Vector & operator*= (const Vector & other)
constexpr Vector operator+ (const Vector & other) const
Vector operator+ (float scalar) const
Vector & operator+= (const Vector & other)
constexpr Vector operator- (const Vector & other) const
Vector operator- (float scalar) const
Vector & operator-= (const Vector & other)
constexpr Vector operator/ (const Vector & other) const
Vector operator/ (float scalar) const
Vector & operator/= (const Vector & other)
constexpr bool operator== (const Vector & other) const
constexpr void setX (float x)
Set the X component.
constexpr void setY (float y)
Set the Y component.
constexpr void setZ (float z)
Set the Z component.

Protected Attributes

Type Name
float x_ = 0.0
float y_ = 0.0
float z_ = 0.0

Public Functions Documentation

function Vector [½]

Construct the vector with all components as 0.

constexpr endstone::Vector::Vector () = default


function Vector [2/2]

Construct the vector with provided components.

template<typename T>
inline constexpr endstone::Vector::Vector (
    T x,
    T y,
    T z
) 

Parameters:

  • x X component
  • y Y component
  • z Z component

function distance

inline float endstone::Vector::distance (
    const Vector & other
) const

Get the distance between this vector and another.

Parameters:

  • other The other vector

Returns:

the distance


function distanceSquared

inline constexpr float endstone::Vector::distanceSquared (
    const Vector & other
) const

Get the squared distance between this vector and another.

Parameters:

  • other The other vector

Returns:

the distance


function getX

Gets the X component.

inline constexpr float endstone::Vector::getX () const

Returns:

The X component.


function getY

Gets the Y component.

inline constexpr float endstone::Vector::getY () const

Returns:

The Y component.


function getZ

Gets the Z component.

inline constexpr float endstone::Vector::getZ () const

Returns:

The Z component.


function length

Gets the magnitude of the vector, defined as sqrt(x2+y2+z^2).

inline float endstone::Vector::length () const

Returns:

the magnitude


function lengthSquared

Gets the magnitude of the vector squared.

inline constexpr float endstone::Vector::lengthSquared () const

Returns:

the magnitude


function normalize

inline Vector & endstone::Vector::normalize () 

Converts this vector to a unit vector (a vector with length of 1).

Returns:

the same vector


function operator*

inline constexpr Vector endstone::Vector::operator* (
    const Vector & other
) const

function operator*

inline Vector endstone::Vector::operator* (
    float scalar
) const

function operator*=

inline Vector & endstone::Vector::operator*= (
    const Vector & other
) 

function operator+

inline constexpr Vector endstone::Vector::operator+ (
    const Vector & other
) const

function operator+

inline Vector endstone::Vector::operator+ (
    float scalar
) const

function operator+=

inline Vector & endstone::Vector::operator+= (
    const Vector & other
) 

function operator-

inline constexpr Vector endstone::Vector::operator- (
    const Vector & other
) const

function operator-

inline Vector endstone::Vector::operator- (
    float scalar
) const

function operator-=

inline Vector & endstone::Vector::operator-= (
    const Vector & other
) 

function operator/

inline constexpr Vector endstone::Vector::operator/ (
    const Vector & other
) const

function operator/

inline Vector endstone::Vector::operator/ (
    float scalar
) const

function operator/=

inline Vector & endstone::Vector::operator/= (
    const Vector & other
) 

function operator==

inline constexpr bool endstone::Vector::operator== (
    const Vector & other
) const

function setX

Set the X component.

inline constexpr void endstone::Vector::setX (
    float x
) 

Parameters:

  • x The new X component.

Returns:

This vector.


function setY

Set the Y component.

inline constexpr void endstone::Vector::setY (
    float y
) 

Parameters:

  • y The new Y component.

Returns:

This vector.


function setZ

Set the Z component.

inline constexpr void endstone::Vector::setZ (
    float z
) 

Parameters:

  • z The new Z component.

Returns:

This vector.


Protected Attributes Documentation

variable x_

float endstone::Vector::x_;

variable y_

float endstone::Vector::y_;

variable z_

float endstone::Vector::z_;

Friends Documentation

friend operator*

inline Vector endstone::Vector::operator* (
    float scalar,
    const Vector & v
) 

friend operator+

inline Vector endstone::Vector::operator+ (
    float scalar,
    const Vector & v
) 

friend operator-

inline Vector endstone::Vector::operator- (
    float scalar,
    const Vector & v
) 

friend operator/

inline Vector endstone::Vector::operator/ (
    float scalar,
    const Vector & v
) 


The documentation for this class was generated from the following file include/endstone/util/vector.h