Struct Vector4SB

Namespace
Elegy.Common.Maths
Assembly
Elegy.Common.dll

4-element structure that can be used to represent 4D grid coordinates or sets of integers.

[Serializable]
public struct Vector4SB : IEquatable<Vector4SB>
Implements
Inherited Members

Constructors

Vector4SB(sbyte, sbyte, sbyte, sbyte)

Constructs a new Vector4SB with the given components.

public Vector4SB(sbyte x, sbyte y, sbyte z, sbyte w)

Parameters

x sbyte

The vector's X component.

y sbyte

The vector's Y component.

z sbyte

The vector's Z component.

w sbyte

The vector's W component.

Fields

W

The vector's W component. Also accessible by using the index position [3].

public sbyte W

Field Value

sbyte

X

The vector's X component. Also accessible by using the index position [0].

public sbyte X

Field Value

sbyte

Y

The vector's Y component. Also accessible by using the index position [1].

public sbyte Y

Field Value

sbyte

Z

The vector's Z component. Also accessible by using the index position [2].

public sbyte Z

Field Value

sbyte

Properties

this[int]

Access vector components using their index.

public sbyte this[int index] { readonly get; set; }

Parameters

index int

Property Value

sbyte

[0] is equivalent to X, [1] is equivalent to Y, [2] is equivalent to Z. [3] is equivalent to W.

Exceptions

ArgumentOutOfRangeException

index is not 0, 1, 2 or 3.

MaxValue

Max vector, a vector with all components equal to MaxValue.

public static Vector4SB MaxValue { get; }

Property Value

Vector4SB

Equivalent to new Vector4SB(sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue, sbyte.MaxValue).

MinValue

Min vector, a vector with all components equal to MinValue.

public static Vector4SB MinValue { get; }

Property Value

Vector4SB

Equivalent to new Vector4SB(sbyte.MinValue, sbyte.MinValue, sbyte.MinValue, sbyte.MinValue).

One

One vector, a vector with all components set to 1.

public static Vector4SB One { get; }

Property Value

Vector4SB

Equivalent to new Vector4SB(1, 1, 1, 1).

UnitW

W-facing unit vector. (0 0 0 1)

public static Vector4SB UnitW { get; }

Property Value

Vector4SB

UnitX

X-facing unit vector. (1 0 0 0)

public static Vector4SB UnitX { get; }

Property Value

Vector4SB

UnitY

Y-facing unit vector. (0 1 0 0)

public static Vector4SB UnitY { get; }

Property Value

Vector4SB

UnitZ

Z-facing unit vector. (0 0 1 0)

public static Vector4SB UnitZ { get; }

Property Value

Vector4SB

Zero

Zero vector, a vector with all components set to 0.

public static Vector4SB Zero { get; }

Property Value

Vector4SB

Equivalent to new Vector4SB(0, 0, 0, 0).

Methods

Abs()

Returns a new vector with all components in absolute values (i.e. positive).

public readonly Vector4SB Abs()

Returns

Vector4SB

A vector with Abs(int) called on each component.

Clamp(Vector4SB, Vector4SB)

Returns a new vector with all components clamped between the components of min and max using Clamp(int, int, int).

public readonly Vector4SB Clamp(Vector4SB min, Vector4SB max)

Parameters

min Vector4SB

The vector with minimum allowed values.

max Vector4SB

The vector with maximum allowed values.

Returns

Vector4SB

The vector with all components clamped.

Deconstruct(out int, out int, out int, out int)

Helper method for deconstruction into a tuple.

public readonly void Deconstruct(out int x, out int y, out int z, out int w)

Parameters

x int
y int
z int
w int

DistanceSquaredTo(Vector4SB)

Returns the squared distance between this vector and to. This method runs faster than DistanceTo(Vector4SB), so prefer it if you need to compare vectors or need the squared distance for some formula.

public readonly int DistanceSquaredTo(Vector4SB to)

Parameters

to Vector4SB

The other vector to use.

Returns

int

The squared distance between the two vectors.

DistanceTo(Vector4SB)

Returns the distance between this vector and to.

public readonly float DistanceTo(Vector4SB to)

Parameters

to Vector4SB

The other vector to use.

Returns

float

The distance between the two vectors.

See Also

Equals(Vector4SB)

Returns true if the vectors are equal.

public readonly bool Equals(Vector4SB other)

Parameters

other Vector4SB

The other vector.

Returns

bool

Whether or not the vectors are equal.

Equals(object?)

Returns true if the vector is equal to the given object (obj).

public override readonly bool Equals(object? obj)

Parameters

obj object

The object to compare with.

Returns

bool

Whether or not the vector and the object are equal.

GetHashCode()

Serves as the hash function for Vector4SB.

public override readonly int GetHashCode()

Returns

int

A hash code for this vector.

Length()

Returns the length (magnitude) of this vector.

public readonly float Length()

Returns

float

The length of this vector.

See Also

LengthSquared()

Returns the squared length (squared magnitude) of this vector. This method runs faster than Length(), so prefer it if you need to compare vectors or need the squared length for some formula.

public readonly int LengthSquared()

Returns

int

The squared length of this vector.

MaxAxisIndex()

Returns the axis of the vector's highest value. See Axis. If all components are equal, this method returns X.

public readonly Axis MaxAxisIndex()

Returns

Axis

The index of the highest axis.

MinAxisIndex()

Returns the axis of the vector's lowest value. See Axis. If all components are equal, this method returns W.

public readonly Axis MinAxisIndex()

Returns

Axis

The index of the lowest axis.

Sign()

Returns a vector with each component set to one or negative one, depending on the signs of this vector's components, or zero if the component is zero, by calling Sign(int) on each component.

public readonly Vector4SB Sign()

Returns

Vector4SB

A vector with all components as either 1, -1, or 0.

ToString()

Converts this Vector4SB to a string.

public override readonly string ToString()

Returns

string

A string representation of this vector.

ToString(string?)

Converts this Vector4SB to a string with the given format.

public readonly string ToString(string? format)

Parameters

format string

Returns

string

A string representation of this vector.

Operators

operator +(Vector4SB, Vector4SB)

Adds each component of the Vector4SB with the components of the given Vector4SB.

public static Vector4SB operator +(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

Vector4SB

The added vector.

operator /(Vector4SB, Vector4SB)

Divides each component of the Vector4SB by the components of the given Vector4SB.

public static Vector4SB operator /(Vector4SB vec, Vector4SB divisorv)

Parameters

vec Vector4SB

The dividend vector.

divisorv Vector4SB

The divisor vector.

Returns

Vector4SB

The divided vector.

operator /(Vector4SB, int)

Divides each component of the Vector4SB by the given int.

public static Vector4SB operator /(Vector4SB vec, int divisor)

Parameters

vec Vector4SB

The dividend vector.

divisor int

The divisor value.

Returns

Vector4SB

The divided vector.

operator ==(Vector4SB, Vector4SB)

Returns true if the vectors are equal.

public static bool operator ==(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the vectors are equal.

explicit operator Vector4SB(Vector4)

Converts a Vector4 to a Vector4SB by truncating components' fractional parts (rounding towards zero).

public static explicit operator Vector4SB(Vector4 value)

Parameters

value Vector4

The vector to convert.

Returns

Vector4SB

operator >(Vector4SB, Vector4SB)

Compares two Vector4SB vectors by first checking if the X value of the left vector is greater than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

public static bool operator >(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the left is greater than the right.

operator >=(Vector4SB, Vector4SB)

Compares two Vector4SB vectors by first checking if the X value of the left vector is greater than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

public static bool operator >=(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the left is greater than or equal to the right.

implicit operator Vector4(Vector4SB)

Converts this Vector4SB to a Vector4.

public static implicit operator Vector4(Vector4SB value)

Parameters

value Vector4SB

The vector to convert.

Returns

Vector4

operator !=(Vector4SB, Vector4SB)

Returns true if the vectors are not equal.

public static bool operator !=(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the vectors are not equal.

operator <(Vector4SB, Vector4SB)

Compares two Vector4SB vectors by first checking if the X value of the left vector is less than the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

public static bool operator <(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the left is less than the right.

operator <=(Vector4SB, Vector4SB)

Compares two Vector4SB vectors by first checking if the X value of the left vector is less than or equal to the X value of the right vector. If the X values are exactly equal, then it repeats this check with the Y, Z and finally W values of the two vectors. This operator is useful for sorting vectors.

public static bool operator <=(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

bool

Whether or not the left is less than or equal to the right.

operator %(Vector4SB, Vector4SB)

Gets the remainder of each component of the Vector4SB with the components of the given Vector4SB. This operation uses truncated division, which is often not desired as it does not work well with negative numbers.

public static Vector4SB operator %(Vector4SB vec, Vector4SB divisorv)

Parameters

vec Vector4SB

The dividend vector.

divisorv Vector4SB

The divisor vector.

Returns

Vector4SB

The remainder vector.

Examples

GD.Print(new Vector4UB(10, -20, 30, -40) % new Vector4UB(6, 7, 8, 9)); // Prints "(4, -6, 6, -4)"

operator %(Vector4SB, int)

Gets the remainder of each component of the Vector4SB with the components of the given int. This operation uses truncated division, which is often not desired as it does not work well with negative numbers.

public static Vector4SB operator %(Vector4SB vec, int divisor)

Parameters

vec Vector4SB

The dividend vector.

divisor int

The divisor value.

Returns

Vector4SB

The remainder vector.

Examples

GD.Print(new Vector4UB(10, -20, 30, -40) % 7); // Prints "(3, -6, 2, -5)"

operator *(Vector4SB, Vector4SB)

Multiplies each component of the Vector4SB by the components of the given Vector4SB.

public static Vector4SB operator *(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

Vector4SB

The multiplied vector.

operator *(Vector4SB, int)

Multiplies each component of the Vector4SB by the given int.

public static Vector4SB operator *(Vector4SB vec, int scale)

Parameters

vec Vector4SB

The vector to multiply.

scale int

The scale to multiply by.

Returns

Vector4SB

The multiplied vector.

operator *(int, Vector4SB)

Multiplies each component of the Vector4SB by the given int.

public static Vector4SB operator *(int scale, Vector4SB vec)

Parameters

scale int

The scale to multiply by.

vec Vector4SB

The vector to multiply.

Returns

Vector4SB

The multiplied vector.

operator -(Vector4SB, Vector4SB)

Subtracts each component of the Vector4SB by the components of the given Vector4SB.

public static Vector4SB operator -(Vector4SB left, Vector4SB right)

Parameters

left Vector4SB

The left vector.

right Vector4SB

The right vector.

Returns

Vector4SB

The subtracted vector.

operator -(Vector4SB)

Returns the negative value of the Vector4SB. This is the same as writing new Vector4UB(-v.X, -v.Y, -v.Z, -v.W). This operation flips the direction of the vector while keeping the same magnitude.

public static Vector4SB operator -(Vector4SB vec)

Parameters

vec Vector4SB

The vector to negate/flip.

Returns

Vector4SB

The negated/flipped vector.