Struct Vector4d
- Namespace
- FixedMathSharp
- Assembly
- FixedMathSharp.dll
Represents a 4D vector with fixed-point precision.
[MemoryPackable(GenerateType.Object)]
public struct Vector4d : IEquatable<Vector4d>, IComparable<Vector4d>, IEqualityComparer<Vector4d>, ISpanFormattable, IFormattable, IMemoryPackable<Vector4d>, IMemoryPackFormatterRegister
- Implements
-
IMemoryPackable<Vector4d>IMemoryPackFormatterRegister
- Inherited Members
- Extension Methods
Remarks
This type is useful for generic 4D component math and homogeneous coordinates used by 4x4 transforms. It does not define independent forward or backward semantics; direction naming belongs to Vector2d, Vector3d, and adapter-level convention code.
Constructors
Vector4d(Fixed64)
Initializes a new Vector4d with all components set to the same value.
public Vector4d(Fixed64 value)
Parameters
valueFixed64
Vector4d(Fixed64, Fixed64, Fixed64, Fixed64)
Initializes a new Vector4d using the specified components.
[JsonConstructor]
public Vector4d(Fixed64 x, Fixed64 y, Fixed64 z, Fixed64 w)
Parameters
Vector4d(Vector2d, Fixed64, Fixed64)
Initializes a new Vector4d from a Vector2d plus Z and W components.
public Vector4d(Vector2d value, Fixed64 z, Fixed64 w)
Parameters
Vector4d(Vector3d, Fixed64)
Initializes a new Vector4d from a Vector3d plus a W component.
public Vector4d(Vector3d value, Fixed64 w)
Parameters
Vector4d(int, int, int, int)
Initializes a new Vector4d using integer component values.
public Vector4d(int xInt, int yInt, int zInt, int wInt)
Parameters
Fields
W
The W component of the vector.
[JsonInclude]
[MemoryPackOrder(3)]
public Fixed64 W
Field Value
X
The X component of the vector.
[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 X
Field Value
Y
The Y component of the vector.
[JsonInclude]
[MemoryPackOrder(1)]
public Fixed64 Y
Field Value
Z
The Z component of the vector.
[JsonInclude]
[MemoryPackOrder(2)]
public Fixed64 Z
Field Value
Properties
IsZero
Are all components of this vector equal to zero?
[JsonIgnore]
[MemoryPackIgnore]
public readonly bool IsZero { get; }
Property Value
this[int]
Gets or sets the vector component at the specified index.
[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 this[int index] { readonly get; set; }
Parameters
indexint
Property Value
LongStateHash
Returns a long hash of the vector based on its component values.
[JsonIgnore]
[MemoryPackIgnore]
public readonly long LongStateHash { get; }
Property Value
Magnitude
Returns the actual length of this vector.
[JsonIgnore]
[MemoryPackIgnore]
public readonly Fixed64 Magnitude { get; }
Property Value
MagnitudeSquared
Returns the square magnitude of the vector.
[JsonIgnore]
[MemoryPackIgnore]
public readonly Fixed64 MagnitudeSquared { get; }
Property Value
Negative
(-1, -1, -1, -1)
public static Vector4d Negative { get; }
Property Value
Normalized
Normalizes the given vector, returning a unit vector with the same direction.
[JsonIgnore]
[MemoryPackIgnore]
public readonly Vector4d Normalized { get; }
Property Value
One
(1, 1, 1, 1)
public static Vector4d One { get; }
Property Value
StateHash
Returns a hash of the vector based on its state.
[JsonIgnore]
[MemoryPackIgnore]
public readonly int StateHash { get; }
Property Value
UnitW
(0, 0, 0, 1)
public static Vector4d UnitW { get; }
Property Value
UnitX
(1, 0, 0, 0)
public static Vector4d UnitX { get; }
Property Value
UnitY
(0, 1, 0, 0)
public static Vector4d UnitY { get; }
Property Value
UnitZ
The unit Z component vector (0, 0, 1, 0).
public static Vector4d UnitZ { get; }
Property Value
Zero
(0, 0, 0, 0)
public static Vector4d Zero { get; }
Property Value
Methods
Abs(Vector4d)
Returns a new vector containing the absolute value of each component.
public static Vector4d Abs(Vector4d value)
Parameters
valueVector4d
Returns
Add(Vector4d, Vector4d)
Adds two vectors component-wise.
public static Vector4d Add(Vector4d v1, Vector4d v2)
Parameters
Returns
AddInPlace(Fixed64)
Adds the specified scalar to all components in place.
public Vector4d AddInPlace(Fixed64 amount)
Parameters
amountFixed64
Returns
AddInPlace(Fixed64, Fixed64, Fixed64, Fixed64)
Adds the specified component values in place.
public Vector4d AddInPlace(Fixed64 xAmount, Fixed64 yAmount, Fixed64 zAmount, Fixed64 wAmount)
Parameters
Returns
AddInPlace(Vector4d)
Adds another vector in place.
public Vector4d AddInPlace(Vector4d other)
Parameters
otherVector4d
Returns
AllComponentsGreaterThanEpsilon()
Determines whether all components are greater than Fixed64.Epsilon.
public readonly bool AllComponentsGreaterThanEpsilon()
Returns
Clamp(Vector4d, Vector4d, Vector4d)
Clamps each component of the given vector within the specified min and max bounds.
public static Vector4d Clamp(Vector4d value, Vector4d min, Vector4d max)
Parameters
Returns
CompareMagnitudeSquared(Vector4d, Vector4d)
Compares the exact squared magnitudes of two vectors without fixed-point saturation.
public static int CompareMagnitudeSquared(Vector4d left, Vector4d right)
Parameters
Returns
- int
A negative value when
leftis shorter, zero when the magnitudes are equal, or a positive value whenleftis longer.
CompareTo(Vector4d)
Compares the current Vector4d instance with another Vector4d based on squared magnitude.
public readonly int CompareTo(Vector4d other)
Parameters
otherVector4d
Returns
Deconstruct(out Fixed64, out Fixed64, out Fixed64, out Fixed64)
Deconstructs the Vector4d into its four Fixed64 components.
public void Deconstruct(out Fixed64 x, out Fixed64 y, out Fixed64 z, out Fixed64 w)
Parameters
Deconstruct(out double, out double, out double, out double)
Deconstructs the Vector4d into its four double components.
public void Deconstruct(out double x, out double y, out double z, out double w)
Parameters
Deconstruct(out int, out int, out int, out int)
Deconstructs the Vector4d into its four int components.
public void Deconstruct(out int x, out int y, out int z, out int w)
Parameters
Deconstruct(out long, out long, out long, out long)
Deconstructs the Vector4d into its four long components.
public void Deconstruct(out long x, out long y, out long z, out long w)
Parameters
Distance(Fixed64, Fixed64, Fixed64, Fixed64)
Calculates the distance to another vector.
public readonly Fixed64 Distance(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
Parameters
Returns
Distance(Vector4d)
Calculates the distance to another vector.
public readonly Fixed64 Distance(Vector4d other)
Parameters
otherVector4d
Returns
Distance(Vector4d, Vector4d)
Calculates the distance to another vector.
public static Fixed64 Distance(Vector4d start, Vector4d end)
Parameters
Returns
DistanceSquared(Fixed64, Fixed64, Fixed64, Fixed64)
Calculates the squared distance to another vector.
public readonly Fixed64 DistanceSquared(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
Parameters
Returns
DistanceSquared(Vector4d)
Calculates the squared distance to another vector.
public readonly Fixed64 DistanceSquared(Vector4d other)
Parameters
otherVector4d
Returns
DistanceSquared(Vector4d, Vector4d)
Calculates the squared distance to another vector.
public static Fixed64 DistanceSquared(Vector4d start, Vector4d end)
Parameters
Returns
Divide(Vector4d, Fixed64)
Divides each vector component by the specified scalar.
public static Vector4d Divide(Vector4d value, Fixed64 divisor)
Parameters
Returns
Divide(Vector4d, Vector4d)
Divides each component of the first vector by the corresponding component of the second vector.
public static Vector4d Divide(Vector4d v1, Vector4d v2)
Parameters
Returns
DivideInPlace(Fixed64)
Divides all components in place.
public Vector4d DivideInPlace(Fixed64 divisor)
Parameters
divisorFixed64
Returns
DivideInPlace(Fixed64, Fixed64, Fixed64, Fixed64)
Divides the vector components by the specified divisors in place.
public Vector4d DivideInPlace(Fixed64 divisorX, Fixed64 divisorY, Fixed64 divisorZ, Fixed64 divisorW)
Parameters
Returns
DivideInPlace(Vector4d)
Divides all components by another vector in place.
public Vector4d DivideInPlace(Vector4d divisor)
Parameters
divisorVector4d
Returns
Dot(Fixed64, Fixed64, Fixed64, Fixed64)
Calculates the dot product with another vector.
public readonly Fixed64 Dot(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
Parameters
Returns
Dot(Vector4d)
Calculates the dot product with another vector.
public readonly Fixed64 Dot(Vector4d other)
Parameters
otherVector4d
Returns
Dot(Vector4d, Vector4d)
Calculates the dot product of two vectors.
public static Fixed64 Dot(Vector4d lhs, Vector4d rhs)
Parameters
Returns
Equals(Vector4d)
public readonly bool Equals(Vector4d other)
Parameters
otherVector4d
Returns
Equals(Vector4d, Vector4d)
public readonly bool Equals(Vector4d x, Vector4d y)
Parameters
Returns
Equals(object?)
public override readonly bool Equals(object? obj)
Parameters
objobject
Returns
FromDouble(double, double, double, double)
Initializes a new Vector4d using double component values.
public static Vector4d FromDouble(double xDoub, double yDoub, double zDoub, double wDoub)
Parameters
Returns
Remarks
Components are converted through FromDouble(double), so non-finite values throw ArgumentOutOfRangeException and finite values outside the Q32.32 range throw OverflowException.
GetHashCode()
Returns a hash code for this vector based on its state.
public override readonly int GetHashCode()
Returns
GetHashCode(Vector4d)
public readonly int GetHashCode(Vector4d obj)
Parameters
objVector4d
Returns
GetMagnitude(Vector4d)
Returns the magnitude of the given vector.
public static Fixed64 GetMagnitude(Vector4d vector)
Parameters
vectorVector4d
Returns
GetNormalized(Vector4d)
Normalizes the given vector, returning a unit vector with the same direction.
public static Vector4d GetNormalized(Vector4d value)
Parameters
valueVector4d
Returns
IsNormalized()
Determines whether this vector is normalized.
public readonly bool IsNormalized()
Returns
Lerp(Vector4d, Vector4d, Fixed64)
Linearly interpolates between two vectors, clamping the interpolation amount to [0, 1].
public static Vector4d Lerp(Vector4d a, Vector4d b, Fixed64 amount)
Parameters
Returns
Max(Vector4d, Vector4d)
Returns a vector whose elements are the maximum of each pair of elements.
public static Vector4d Max(Vector4d value1, Vector4d value2)
Parameters
Returns
Midpoint(Vector4d, Vector4d)
Computes the midpoint between two vectors.
public static Vector4d Midpoint(Vector4d v1, Vector4d v2)
Parameters
Returns
Min(Vector4d, Vector4d)
Returns a vector whose elements are the minimum of each pair of elements.
public static Vector4d Min(Vector4d value1, Vector4d value2)
Parameters
Returns
Multiply(Vector4d, Fixed64)
Multiplies each vector component by the specified scalar.
public static Vector4d Multiply(Vector4d value, Fixed64 factor)
Parameters
Returns
Multiply(Vector4d, Vector4d)
Multiplies two vectors component-wise.
public static Vector4d Multiply(Vector4d a, Vector4d b)
Parameters
Returns
MultiplyInPlace(Fixed64)
Multiplies all components in place.
public Vector4d MultiplyInPlace(Fixed64 factor)
Parameters
factorFixed64
Returns
MultiplyInPlace(Fixed64, Fixed64, Fixed64, Fixed64)
Multiplies the vector components by the specified factors in place.
public Vector4d MultiplyInPlace(Fixed64 factorX, Fixed64 factorY, Fixed64 factorZ, Fixed64 factorW)
Parameters
Returns
MultiplyInPlace(Vector4d)
Multiplies all components by another vector in place.
public Vector4d MultiplyInPlace(Vector4d factor)
Parameters
factorVector4d
Returns
NormalizeInPlace()
Normalizes this vector in place.
public Vector4d NormalizeInPlace()
Returns
NormalizeInPlace(out Fixed64)
Normalizes this vector in place and returns its original magnitude.
public Vector4d NormalizeInPlace(out Fixed64 mag)
Parameters
magFixed64
Returns
Set(Fixed64, Fixed64, Fixed64, Fixed64)
Sets the vector components in place and returns the modified vector.
public Vector4d Set(Fixed64 newX, Fixed64 newY, Fixed64 newZ, Fixed64 newW)
Parameters
Returns
Sign(Vector4d)
Returns a new vector containing the sign of each component.
public static Vector4d Sign(Vector4d value)
Parameters
valueVector4d
Returns
SnapSmallComponentsToZero(Fixed64?)
Snaps components with absolute values below the threshold to zero.
public readonly Vector4d SnapSmallComponentsToZero(Fixed64? threshold = null)
Parameters
thresholdFixed64?
Returns
Subtract(Vector4d, Vector4d)
Subtracts two vectors component-wise.
public static Vector4d Subtract(Vector4d v1, Vector4d v2)
Parameters
Returns
SubtractInPlace(Fixed64)
Subtracts the specified scalar from all components in place.
public Vector4d SubtractInPlace(Fixed64 amount)
Parameters
amountFixed64
Returns
SubtractInPlace(Fixed64, Fixed64, Fixed64, Fixed64)
Subtracts the specified component values in place.
public Vector4d SubtractInPlace(Fixed64 xAmount, Fixed64 yAmount, Fixed64 zAmount, Fixed64 wAmount)
Parameters
Returns
SubtractInPlace(Vector4d)
Subtracts another vector in place.
public Vector4d SubtractInPlace(Vector4d other)
Parameters
otherVector4d
Returns
ToString()
Returns a string representation of this vector.
public override readonly string ToString()
Returns
ToString(string?, IFormatProvider?)
Returns a string representation of this vector.
public readonly string ToString(string? format, IFormatProvider? formatProvider)
Parameters
formatstringformatProviderIFormatProvider
Returns
ToVector3d()
Converts this vector to Vector3d by dropping the W component.
public readonly Vector3d ToVector3d()
Returns
Remarks
This is a component-preserving conversion, not a coordinate-convention conversion.
Transform(Fixed4x4, Vector4d)
Transforms a 4D vector by a 4x4 matrix.
public static Vector4d Transform(Fixed4x4 matrix, Vector4d vector)
Parameters
Returns
Remarks
This follows the same row-vector storage convention as TransformPoint(Fixed4x4, Vector3d), preserving the computed W component instead of performing perspective division.
TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider?)
Formats this vector into the provided destination buffer.
public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
Parameters
destinationSpan<char>charsWrittenintformatReadOnlySpan<char>providerIFormatProvider
Returns
TryGetMagnitude(Vector4d, out Fixed64)
Attempts to return the magnitude of the given vector without saturating the result.
public static bool TryGetMagnitude(Vector4d vector, out Fixed64 magnitude)
Parameters
vectorVector4dThe vector to measure.
magnitudeFixed64The magnitude, or MaxValue when it is not representable.
Returns
UnclampedLerp(Vector4d, Vector4d, Fixed64)
Linearly interpolates between two vectors without clamping the interpolation amount.
public static Vector4d UnclampedLerp(Vector4d a, Vector4d b, Fixed64 t)
Parameters
Returns
Operators
operator +(Fixed64, Vector4d)
Adds a scalar to each component.
public static Vector4d operator +(Fixed64 mag, Vector4d v1)
Parameters
Returns
operator +(Vector4d, Fixed64)
Adds a scalar to each component.
public static Vector4d operator +(Vector4d v1, Fixed64 mag)
Parameters
Returns
operator +(Vector4d, Vector4d)
Adds two vectors component-wise.
public static Vector4d operator +(Vector4d v1, Vector4d v2)
Parameters
Returns
operator +(Vector4d, (int x, int y, int z, int w))
Adds a tuple to each component.
public static Vector4d operator +(Vector4d v1, (int x, int y, int z, int w) v2)
Parameters
Returns
operator +((int x, int y, int z, int w), Vector4d)
Adds a tuple to each component.
public static Vector4d operator +((int x, int y, int z, int w) v2, Vector4d v1)
Parameters
Returns
operator /(Vector4d, Fixed64)
Divides each component by a scalar.
public static Vector4d operator /(Vector4d v1, Fixed64 div)
Parameters
Returns
operator /(Vector4d, Vector4d)
Divides each component by another vector's corresponding component.
public static Vector4d operator /(Vector4d v1, Vector4d v2)
Parameters
Returns
operator /(Vector4d, int)
Divides each component by an integer scalar.
public static Vector4d operator /(Vector4d v1, int div)
Parameters
Returns
operator ==(Vector4d, Vector4d)
Compares two vectors for equality.
public static bool operator ==(Vector4d left, Vector4d right)
Parameters
Returns
operator >(Vector4d, Vector4d)
Returns true when every component in the left vector is greater than the corresponding component in the right vector.
public static bool operator >(Vector4d left, Vector4d right)
Parameters
Returns
operator >=(Vector4d, Vector4d)
Returns true when every component in the left vector is greater than or equal to the corresponding component in the right vector.
public static bool operator >=(Vector4d left, Vector4d right)
Parameters
Returns
operator !=(Vector4d, Vector4d)
Compares two vectors for inequality.
public static bool operator !=(Vector4d left, Vector4d right)
Parameters
Returns
operator <(Vector4d, Vector4d)
Returns true when every component in the left vector is less than the corresponding component in the right vector.
public static bool operator <(Vector4d left, Vector4d right)
Parameters
Returns
operator <=(Vector4d, Vector4d)
Returns true when every component in the left vector is less than or equal to the corresponding component in the right vector.
public static bool operator <=(Vector4d left, Vector4d right)
Parameters
Returns
operator *(Fixed4x4, Vector4d)
Transforms a vector by a 4x4 matrix.
public static Vector4d operator *(Fixed4x4 matrix, Vector4d vector)
Parameters
Returns
operator *(Fixed64, Vector4d)
Multiplies each component by a scalar.
public static Vector4d operator *(Fixed64 mag, Vector4d v1)
Parameters
Returns
operator *(Vector4d, Fixed4x4)
Transforms a vector by a 4x4 matrix.
public static Vector4d operator *(Vector4d vector, Fixed4x4 matrix)
Parameters
Returns
operator *(Vector4d, Fixed64)
Multiplies each component by a scalar.
public static Vector4d operator *(Vector4d v1, Fixed64 mag)
Parameters
Returns
operator *(Vector4d, Vector4d)
Multiplies two vectors component-wise.
public static Vector4d operator *(Vector4d v1, Vector4d v2)
Parameters
Returns
operator *(Vector4d, int)
Multiplies each component by an integer scalar.
public static Vector4d operator *(Vector4d v1, int mag)
Parameters
Returns
operator *(int, Vector4d)
Multiplies each component by an integer scalar.
public static Vector4d operator *(int mag, Vector4d v1)
Parameters
Returns
operator -(Fixed64, Vector4d)
Subtracts a scalar from each component.
public static Vector4d operator -(Fixed64 mag, Vector4d v1)
Parameters
Returns
operator -(Vector4d, Fixed64)
Subtracts a scalar from each component.
public static Vector4d operator -(Vector4d v1, Fixed64 mag)
Parameters
Returns
operator -(Vector4d, Vector4d)
Subtracts two vectors component-wise.
public static Vector4d operator -(Vector4d v1, Vector4d v2)
Parameters
Returns
operator -(Vector4d, (int x, int y, int z, int w))
Subtracts a tuple from each component.
public static Vector4d operator -(Vector4d v1, (int x, int y, int z, int w) v2)
Parameters
Returns
operator -((int x, int y, int z, int w), Vector4d)
Subtracts each vector component from a tuple component.
public static Vector4d operator -((int x, int y, int z, int w) v1, Vector4d v2)
Parameters
Returns
operator -(Vector4d)
Negates the vector.
public static Vector4d operator -(Vector4d v1)
Parameters
v1Vector4d