SmartFoxServer 3 C++ Client API 3.1.0-beta
Client API for SmartFoxServer 3
Loading...
Searching...
No Matches
sfs3::entities::SFSVector2 Struct Reference

A class representing a Vector in 2D space. More...

#include <SFSVector2.h>

Public Member Functions

float lengthSquared () const
 Returns the squared length of this vector.
float length () const
 Returns the length (magnitude) of this vector.
bool isNormalized () const
 Returns true if the vector is normalized, i.e.
SFSVector2 sum (const SFSVector2 &vec) const
 Returns a new vector that is the sum of this vector and the specified vector.
SFSVector2 sub (const SFSVector2 &vec) const
 Returns a new vector that is the result of subtracting the specified vector from this vector.
SFSVector2 mult (const SFSVector2 &vec) const
 Returns a new vector that is the component-wise multiplication of this vector and the specified vector.
SFSVector2 divide (const SFSVector2 &vec) const
 Returns a new vector that is the component-wise division of this vector by the specified vector.
SFSVector2 normalize () const
 Returns a new vector that is the normalized (unit length) version of this vector.
float angle () const
 Returns the angle of this vector in radians, measured from the positive x-axis.
SFSVector2 rotate (float angle) const
 Returns a new vector that is the result of rotating this vector by the specified angle.
float dot (const SFSVector2 &vec) const
 Returns the dot product of this vector and the specified vector.
float cross (const SFSVector2 &vec) const
 Returns the 2D cross product (also known as the perpendicular dot product or wedge product) of this vector and the specified vector.
float distanceTo (const SFSVector2 &vec) const
 Returns the Euclidean distance between this vector and the specified vector.
float distanceSquaredTo (const SFSVector2 &vec) const
 Returns the squared distance between this vector and the specified vector.
SFSVector2 abs () const
 Returns a new vector with all components in absolute values.
SFSVector2 min (const SFSVector2 &vec) const
 Returns a new vector with the component-wise minimum of this vector and the specified vector.
SFSVector2 max (const SFSVector2 &vec) const
 Returns a new vector with the component-wise maximum of this vector and the specified vector.
SFSVector2 floor () const
 Returns a new vector with all components rounded down to the nearest integer.
SFSVector2 ceil () const
 Returns a new vector with all components rounded up to the nearest integer.
SFSVector2 round () const
 Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded towards positive infinity (-1.5 rounds to -1.0).
SFSVector2 lerp (const SFSVector2 &vec, float weight) const
 Returns the result of the linear interpolation between this vector and the specified vector by the specified weight.
float aspect () const
 Returns the aspect ratio of this vector, the ratio of x to y.

Detailed Description

A class representing a Vector in 2D space.

NOTE: equality and hashing are value-based (x,y); mutating a component while the instance is used as a key in a hash-based container will corrupt lookups.

Member Function Documentation

◆ lengthSquared()

float sfs3::entities::SFSVector2::lengthSquared ( ) const
inline

Returns the squared length of this vector.

Cheaper than length(), and enough whenever lengths are only compared to each other.

Returns
the squared length of the vector

◆ length()

float sfs3::entities::SFSVector2::length ( ) const
inline

Returns the length (magnitude) of this vector.

Returns
the length of the vector

◆ isNormalized()

bool sfs3::entities::SFSVector2::isNormalized ( ) const
inline

Returns true if the vector is normalized, i.e.

its length is approximately equal to 1.

Returns
true if the vector is normalized, false otherwise

◆ sum()

SFSVector2 sfs3::entities::SFSVector2::sum ( const SFSVector2 & vec) const
inline

Returns a new vector that is the sum of this vector and the specified vector.

Parameters
vecthe vector to add
Returns
a new vector representing the sum

◆ sub()

SFSVector2 sfs3::entities::SFSVector2::sub ( const SFSVector2 & vec) const
inline

Returns a new vector that is the result of subtracting the specified vector from this vector.

Parameters
vecthe vector to subtract
Returns
a new vector representing the difference

◆ mult()

SFSVector2 sfs3::entities::SFSVector2::mult ( const SFSVector2 & vec) const
inline

Returns a new vector that is the component-wise multiplication of this vector and the specified vector.

Parameters
vecthe vector to multiply with
Returns
a new vector representing the component-wise product

◆ divide()

SFSVector2 sfs3::entities::SFSVector2::divide ( const SFSVector2 & vec) const
inline

Returns a new vector that is the component-wise division of this vector by the specified vector.

If any component of the divisor is zero, the result will be Infinity or NaN.

Parameters
vecthe vector to divide by
Returns
a new vector representing the component-wise quotient

◆ normalize()

SFSVector2 sfs3::entities::SFSVector2::normalize ( ) const
inline

Returns a new vector that is the normalized (unit length) version of this vector.

If this vector has zero length, returns a zero vector.

Returns
a new normalized vector

◆ angle()

float sfs3::entities::SFSVector2::angle ( ) const
inline

Returns the angle of this vector in radians, measured from the positive x-axis.

The returned angle is in the range [-PI, PI].

Returns
the angle in radians

◆ rotate()

SFSVector2 sfs3::entities::SFSVector2::rotate ( float angle) const
inline

Returns a new vector that is the result of rotating this vector by the specified angle.

Parameters
anglethe angle to rotate by, in radians
Returns
a new rotated vector

◆ dot()

float sfs3::entities::SFSVector2::dot ( const SFSVector2 & vec) const
inline

Returns the dot product of this vector and the specified vector.

The dot product will be 0 for a right angle (90 degrees), greater than 0 for angles narrower than 90 degrees and lower than 0 for angles wider than 90 degrees. When using unit (normalized) vectors, the result will always be between -1.0 (180 degree angle) when the vectors are facing opposite directions, and 1.0 (0 degree angle) when the vectors are aligned.

Parameters
vecthe vector to compute the dot product with
Returns
the dot product

◆ cross()

float sfs3::entities::SFSVector2::cross ( const SFSVector2 & vec) const
inline

Returns the 2D cross product (also known as the perpendicular dot product or wedge product) of this vector and the specified vector.

This returns a scalar representing the z-component of the 3D cross product when treating the 2D vectors as 3D vectors with z=0. The magnitude represents the area of the parallelogram formed by the two vectors. The sign indicates orientation: positive if vec is counterclockwise from this vector, negative if clockwise.

Parameters
vecthe vector to compute the cross product with
Returns
the scalar cross product

◆ distanceTo()

float sfs3::entities::SFSVector2::distanceTo ( const SFSVector2 & vec) const
inline

Returns the Euclidean distance between this vector and the specified vector.

Parameters
vecthe vector to measure distance to
Returns
the distance between the two vectors

◆ distanceSquaredTo()

float sfs3::entities::SFSVector2::distanceSquaredTo ( const SFSVector2 & vec) const
inline

Returns the squared distance between this vector and the specified vector.

This is more efficient than distanceTo() when comparing distances.

Parameters
vecthe vector to measure squared distance to
Returns
the squared distance between the two vectors

◆ abs()

SFSVector2 sfs3::entities::SFSVector2::abs ( ) const
inline

Returns a new vector with all components in absolute values.

Returns
a new vector with absolute values

◆ min()

SFSVector2 sfs3::entities::SFSVector2::min ( const SFSVector2 & vec) const
inline

Returns a new vector with the component-wise minimum of this vector and the specified vector.

Parameters
vecthe vector to compare with
Returns
a new vector with the minimum components

◆ max()

SFSVector2 sfs3::entities::SFSVector2::max ( const SFSVector2 & vec) const
inline

Returns a new vector with the component-wise maximum of this vector and the specified vector.

Parameters
vecthe vector to compare with
Returns
a new vector with the maximum components

◆ floor()

SFSVector2 sfs3::entities::SFSVector2::floor ( ) const
inline

Returns a new vector with all components rounded down to the nearest integer.

Returns
a new vector with floored components

◆ ceil()

SFSVector2 sfs3::entities::SFSVector2::ceil ( ) const
inline

Returns a new vector with all components rounded up to the nearest integer.

Returns
a new vector with ceiling components

◆ round()

SFSVector2 sfs3::entities::SFSVector2::round ( ) const
inline

Returns a new vector with all components rounded to the nearest integer, with halfway cases rounded towards positive infinity (-1.5 rounds to -1.0).

Returns
a new vector with rounded components

◆ lerp()

SFSVector2 sfs3::entities::SFSVector2::lerp ( const SFSVector2 & vec,
float weight ) const
inline

Returns the result of the linear interpolation between this vector and the specified vector by the specified weight.

The weight range is 0.0 to 1.0, representing the amount of interpolation. Values outside this range will extrapolate.

Parameters
vecthe target vector to interpolate towards
weightthe interpolation weight (0.0 = this vector, 1.0 = target vector)
Returns
a new interpolated vector

◆ aspect()

float sfs3::entities::SFSVector2::aspect ( ) const
inline

Returns the aspect ratio of this vector, the ratio of x to y.

If y is zero, the result will be Infinity, -Infinity, or NaN.

Returns
the aspect ratio (x / y)

The documentation for this struct was generated from the following file: