Table of Contents

Struct Vector2d

Namespace
FixedMathSharp
Assembly
FixedMathSharp.dll

Represents a 2D vector with fixed-point precision, offering a range of mathematical operations and transformations such as rotation, scaling, reflection, and interpolation.

[MemoryPackable(GenerateType.Object)]
public struct Vector2d : IEquatable<Vector2d>, IComparable<Vector2d>, IEqualityComparer<Vector2d>, ISpanFormattable, IFormattable, IMemoryPackable<Vector2d>, IMemoryPackFormatterRegister
Implements
IMemoryPackable<Vector2d>
IMemoryPackFormatterRegister
Inherited Members
Extension Methods

Remarks

The Vector2d struct is designed for applications that require precise numerical operations, such as games, simulations, or physics engines. It provides methods for common vector operations like addition, subtraction, dot product, cross product, distance calculations, and rotation.

FixedMathSharp treats Vector2d as plane math: +X is right and +Y is the named Forward direction. Polar angle helpers are separate: ForwardDirection(Fixed64) returns +X at angle zero.

Use Cases:

  • Modeling 2D positions, directions, and velocities in fixed-point math environments.
  • Performing vector transformations, including rotations and reflections.
  • Handling interpolation and distance calculations in physics or simulation systems.
  • Useful for fixed-point math scenarios where floating-point precision is insufficient or not desired.

Constructors

Vector2d(Fixed64, Fixed64)

Initializes a new instance of the Vector2d structure with the specified X and Y components.

[JsonConstructor]
public Vector2d(Fixed64 x, Fixed64 y)

Parameters

x Fixed64

The value to assign to the X component of the vector.

y Fixed64

The value to assign to the Y component of the vector.

Vector2d(int, int)

Initializes a new instance of the Vector2d structure using integer values for the X and Y components.

public Vector2d(int xInt, int yInt)

Parameters

xInt int

The X component of the vector, specified as an integer.

yInt int

The Y component of the vector, specified as an integer.

Fields

X

The X component of the vector.

[JsonInclude]
[MemoryPackOrder(0)]
public Fixed64 X

Field Value

Fixed64

Y

The Y component of the vector.

[JsonInclude]
[MemoryPackOrder(1)]
public Fixed64 Y

Field Value

Fixed64

Properties

Backward

(0, -1)

public static Vector2d Backward { get; }

Property Value

Vector2d

Forward

The named 2D plane forward direction (0, 1).

public static Vector2d Forward { get; }

Property Value

Vector2d

Remarks

This is distinct from polar angle math: ForwardDirection(Fixed64) returns Right when its angle argument is zero.

this[int]

Gets or sets the vector component at the specified index.

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 this[int index] { get; set; }

Parameters

index int

The zero-based index of the component to access. Use 0 for the X component and 1 for the Y component.

Property Value

Fixed64

The vector component at the specified index.

Remarks

This indexer provides array-like access to the vector's components. Index 0 corresponds to the X component, and index 1 corresponds to the Y component.

Exceptions

IndexOutOfRangeException

Thrown when the index is less than 0 or greater than 1.

Left

(-1, 0)

public static Vector2d Left { get; }

Property Value

Vector2d

LeftHandNormal

Gets the left-hand (clockwise) normal vector.

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d LeftHandNormal { get; }

Property Value

Vector2d

LongStateHash

Returns a long hash of the vector based on its x and y values.

[JsonIgnore]
[MemoryPackIgnore]
public long LongStateHash { get; }

Property Value

long

Magnitude

Returns the actual length of this vector (RO).

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 Magnitude { get; }

Property Value

Fixed64

MagnitudeSquared

Returns the square magnitude of the vector (avoids calculating the square root).

[JsonIgnore]
[MemoryPackIgnore]
public Fixed64 MagnitudeSquared { get; }

Property Value

Fixed64

Negative

(-1, -1)

public static Vector2d Negative { get; }

Property Value

Vector2d

Normalized

Normalizes the given vector, returning a unit vector with the same direction.

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d Normalized { get; }

Property Value

Vector2d

A normalized (unit) vector with the same direction.

One

(1, 1)

public static Vector2d One { get; }

Property Value

Vector2d

Right

The named 2D plane right direction (1, 0).

public static Vector2d Right { get; }

Property Value

Vector2d

RightHandNormal

Gets the right-hand (counter-clockwise) normal vector.

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RightHandNormal { get; }

Property Value

Vector2d

RotatedLeft

Rotates the vector to the left (90 degrees counterclockwise).

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RotatedLeft { get; }

Property Value

Vector2d

RotatedRight

Rotates the vector to the right (90 degrees clockwise).

[JsonIgnore]
[MemoryPackIgnore]
public Vector2d RotatedRight { get; }

Property Value

Vector2d

StateHash

Returns a hash of the vector based on its state.

[JsonIgnore]
[MemoryPackIgnore]
public int StateHash { get; }

Property Value

int

Zero

(0, 0)

public static Vector2d Zero { get; }

Property Value

Vector2d

Methods

Abs(Vector2d)

Returns a new Vector2d where each component is the absolute value of the corresponding input component.

public static Vector2d Abs(Vector2d value)

Parameters

value Vector2d

The input vector.

Returns

Vector2d

A vector with absolute values for each component.

Add(Vector2d, Vector2d)

Adds two vectors component-wise.

public static Vector2d Add(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d
v2 Vector2d

Returns

Vector2d

AddInPlace(Fixed64)

Adds the specified values to the components of the vector in place and returns the modified vector.

public Vector2d AddInPlace(Fixed64 amount)

Parameters

amount Fixed64

The amount to add to the components.

Returns

Vector2d

The modified vector after addition.

AddInPlace(Fixed64, Fixed64)

Adds the specified values to the components of the vector in place and returns the modified vector.

public Vector2d AddInPlace(Fixed64 xAmount, Fixed64 yAmount)

Parameters

xAmount Fixed64

The amount to add to the x component.

yAmount Fixed64

The amount to add to the y component.

Returns

Vector2d

AddInPlace(Vector2d)

Adds the specified values to the components of the vector in place and returns the modified vector.

public Vector2d AddInPlace(Vector2d other)

Parameters

other Vector2d

Returns

Vector2d

AllComponentsGreaterThanEpsilon()

Checks whether all components are strictly greater than Epsilon.

public bool AllComponentsGreaterThanEpsilon()

Returns

bool

BarycentricCoordinates(Vector2d, Vector2d, Vector2d, Fixed64, Fixed64)

Calculates a position between three points using barycentric weights for the second and third vertices.

public static Vector2d BarycentricCoordinates(Vector2d coordA, Vector2d coordB, Vector2d coordC, Fixed64 weightB, Fixed64 weightC)

Parameters

coordA Vector2d

The first vertex of the triangle.

coordB Vector2d

The second vertex of the triangle.

coordC Vector2d

The third vertex of the triangle.

weightB Fixed64

The barycentric weight for the second vertex.

weightC Fixed64

The barycentric weight for the third vertex.

Returns

Vector2d

The cartesian translation represented by the barycentric coordinates within the triangle.

Clamp(Vector2d, Vector2d, Vector2d)

Clamps each component of the given vector within the specified min and max bounds.

public static Vector2d Clamp(Vector2d value, Vector2d min, Vector2d max)

Parameters

value Vector2d
min Vector2d
max Vector2d

Returns

Vector2d

ClosestPointOnLineSegment(Vector2d, Vector2d, Vector2d)

Calculates the closest point on a finite line segment to a given point.

public static Vector2d ClosestPointOnLineSegment(Vector2d point, Vector2d start, Vector2d end)

Parameters

point Vector2d

The point to project onto the segment.

start Vector2d

The start of the line segment.

end Vector2d

The end of the line segment.

Returns

Vector2d

The closest point on the segment to the given point.

Remarks

Zero-length segments deterministically return start.

CompareDistanceSquared(Vector2d, Vector2d, Vector2d, Vector2d)

Compares the exact squared distances between two pairs of points without fixed-point saturation.

public static int CompareDistanceSquared(Vector2d leftStart, Vector2d leftEnd, Vector2d rightStart, Vector2d rightEnd)

Parameters

leftStart Vector2d
leftEnd Vector2d
rightStart Vector2d
rightEnd Vector2d

Returns

int

A negative value when the left distance is shorter, zero when the distances are equal, or a positive value when the left distance is longer.

CompareMagnitudeSquared(Vector2d, Vector2d)

Compares the exact squared magnitudes of two vectors without fixed-point saturation.

public static int CompareMagnitudeSquared(Vector2d left, Vector2d right)

Parameters

left Vector2d
right Vector2d

Returns

int

A negative value when left is shorter, zero when the magnitudes are equal, or a positive value when left is longer.

CompareProjection(Vector2d, Vector2d, Vector2d)

Compares the exact component-difference projections of two vectors.

public static int CompareProjection(Vector2d candidate, Vector2d current, Vector2d direction)

Parameters

candidate Vector2d

The candidate point.

current Vector2d

The point to compare against.

direction Vector2d

The projection direction; it need not be normalized.

Returns

int

A negative value, zero, or a positive value when the candidate projection is respectively less than, equal to, or greater than the current projection.

CompareTo(Vector2d)

Compares the current Vector2d instance with another Vector2d based on their squared magnitudes.

public int CompareTo(Vector2d other)

Parameters

other Vector2d

The Vector2d instance to compare with the current instance.

Returns

int

A value less than zero if this instance is less than other; zero if this instance is equal to other; or a value greater than zero if this instance is greater than other, as determined by their squared magnitudes.

Remarks

This comparison uses the squared magnitude of each vector, which avoids the computational cost of calculating the actual magnitude. Use this method when only relative vector lengths are important.

CreateRotation(Fixed64)

Creates a vector from a given angle in radians.

public static Vector2d CreateRotation(Fixed64 angle)

Parameters

angle Fixed64

Returns

Vector2d

CrossProduct(Fixed64, Fixed64)

Computes the cross product magnitude of this vector with another vector.

public Fixed64 CrossProduct(Fixed64 otherX, Fixed64 otherY)

Parameters

otherX Fixed64

The X component of the other vector.

otherY Fixed64

The Y component of the other vector.

Returns

Fixed64

The cross product magnitude.

CrossProduct(Vector2d)

Computes the cross product magnitude of this vector with another vector.

public Fixed64 CrossProduct(Vector2d other)

Parameters

other Vector2d

Returns

Fixed64

The cross product magnitude.

CrossProduct(Vector2d, Vector2d)

Cross Product of two vectors.

public static Fixed64 CrossProduct(Vector2d lhs, Vector2d rhs)

Parameters

lhs Vector2d
rhs Vector2d

Returns

Fixed64

Deconstruct(out Fixed64, out Fixed64)

Deconstructs the Vector2d into its two Fixed64 components.

public void Deconstruct(out Fixed64 x, out Fixed64 y)

Parameters

x Fixed64
y Fixed64

Deconstruct(out double, out double)

Deconstructs the Vector2d into its two double components.

public void Deconstruct(out double x, out double y)

Parameters

x double
y double

Deconstruct(out int, out int)

Deconstructs the Vector2d into its two int components.

public void Deconstruct(out int x, out int y)

Parameters

x int
y int

Deconstruct(out long, out long)

Deconstructs the Vector2d into its two long components.

public void Deconstruct(out long x, out long y)

Parameters

x long
y long

Distance(Fixed64, Fixed64)

Returns the distance between this vector and another vector specified by its components.

public Fixed64 Distance(Fixed64 otherX, Fixed64 otherY)

Parameters

otherX Fixed64
otherY Fixed64

Returns

Fixed64

Distance(Vector2d)

Returns the distance between this vector and another vector.

public Fixed64 Distance(Vector2d other)

Parameters

other Vector2d

Returns

Fixed64

Distance(Vector2d, Vector2d)

Computes the distance between two vectors using the Euclidean distance formula.

public static Fixed64 Distance(Vector2d start, Vector2d end)

Parameters

start Vector2d

The starting vector.

end Vector2d

The ending vector.

Returns

Fixed64

The Euclidean distance between the two vectors.

DistanceSquared(Fixed64, Fixed64)

Calculates the squared distance between two vectors, avoiding the need for a square root operation.

public Fixed64 DistanceSquared(Fixed64 otherX, Fixed64 otherY)

Parameters

otherX Fixed64
otherY Fixed64

Returns

Fixed64

The squared distance between the two vectors.

DistanceSquared(Vector2d)

Calculates the squared distance between two vectors, avoiding the need for a square root operation.

public Fixed64 DistanceSquared(Vector2d other)

Parameters

other Vector2d

Returns

Fixed64

The squared distance between the two vectors.

DistanceSquared(Vector2d, Vector2d)

Calculates the squared distance between two vectors, avoiding the need for a square root operation.

public static Fixed64 DistanceSquared(Vector2d start, Vector2d end)

Parameters

start Vector2d
end Vector2d

Returns

Fixed64

The squared distance between the two vectors.

Divide(Vector2d, Fixed64)

Divides each vector component by the specified scalar.

public static Vector2d Divide(Vector2d value, Fixed64 divisor)

Parameters

value Vector2d
divisor Fixed64

Returns

Vector2d

Divide(Vector2d, Vector2d)

Divides each component of the first vector by the corresponding component of the second vector.

public static Vector2d Divide(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d
v2 Vector2d

Returns

Vector2d

DivideInPlace(Fixed64)

Divides each component of the vector by the specified scalar divisor in place and returns the modified vector.

public Vector2d DivideInPlace(Fixed64 divisor)

Parameters

divisor Fixed64

Returns

Vector2d

DivideInPlace(Fixed64, Fixed64)

Divides the components of the vector by the specified x and y divisors in place and returns the modified vector.

public Vector2d DivideInPlace(Fixed64 divisorX, Fixed64 divisorY)

Parameters

divisorX Fixed64
divisorY Fixed64

Returns

Vector2d

DivideInPlace(Vector2d)

Divides each component of the vector by the corresponding component of the given vector in place and returns the modified vector.

public Vector2d DivideInPlace(Vector2d divisor)

Parameters

divisor Vector2d

Returns

Vector2d

Dot(Fixed64, Fixed64)

Returns the dot product of this vector with another vector.

public Fixed64 Dot(Fixed64 otherX, Fixed64 otherY)

Parameters

otherX Fixed64
otherY Fixed64

Returns

Fixed64

Dot(Vector2d)

Returns the dot product of this vector with another vector.

public Fixed64 Dot(Vector2d other)

Parameters

other Vector2d

Returns

Fixed64

Dot(Vector2d, Vector2d)

Dot Product of two vectors.

public static Fixed64 Dot(Vector2d lhs, Vector2d rhs)

Parameters

lhs Vector2d
rhs Vector2d

Returns

Fixed64

Equals(Vector2d)

public bool Equals(Vector2d other)

Parameters

other Vector2d

Returns

bool

Equals(Vector2d, Vector2d)

public bool Equals(Vector2d x, Vector2d y)

Parameters

x Vector2d
y Vector2d

Returns

bool

Equals(object?)

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

EqualsZero()

Are all components of this vector equal to zero?

public bool EqualsZero()

Returns

bool

ForwardDirection(Fixed64)

Calculates the forward direction vector in 2D based on a yaw (angle).

public static Vector2d ForwardDirection(Fixed64 angle)

Parameters

angle Fixed64

The angle in radians representing the rotation in 2D space.

Returns

Vector2d

A unit vector representing the forward direction.

Remarks

This is a polar-angle helper: angle zero points along Right. It intentionally differs from the named Forward plane constant, which is +Y.

FromDouble(double, double)

Initializes a new instance of the Vector2d structure using double-precision floating-point values for the X and Y components.

public static Vector2d FromDouble(double xDoub, double yDoub)

Parameters

xDoub double
yDoub double

Returns

Vector2d

Remarks

Components are converted through FromDouble(double), so non-finite values throw ArgumentOutOfRangeException and finite values outside the Q32.32 range throw OverflowException.

GetAverage(ReadOnlySpan<Vector2d>)

Calculates the arithmetic mean with one final round-half-to-even conversion per component.

public static Vector2d GetAverage(ReadOnlySpan<Vector2d> values)

Parameters

values ReadOnlySpan<Vector2d>

The non-empty sequence of vectors to average.

Returns

Vector2d

The arithmetic mean of values.

Exceptions

ArgumentException

values is empty.

GetDirection(Vector2d, Vector2d)

Returns the normalized direction from start toward end across the complete coordinate domain.

public static Vector2d GetDirection(Vector2d start, Vector2d end)

Parameters

start Vector2d
end Vector2d

Returns

Vector2d

Remarks

Equal endpoints return Zero. Endpoint differences are evaluated exactly even when a component cannot be represented by Fixed64.

GetHashCode()

Returns a hash code for this instance, which is based on the combined hash codes of the X and Y components.

public override int GetHashCode()

Returns

int

GetHashCode(Vector2d)

public int GetHashCode(Vector2d obj)

Parameters

obj Vector2d

Returns

int

GetMagnitude(Vector2d)

Returns the magnitude (length) of the given vector.

public static Fixed64 GetMagnitude(Vector2d vector)

Parameters

vector Vector2d

The vector to compute the magnitude of.

Returns

Fixed64

The magnitude (length) of the vector.

GetNormalized(Vector2d)

Normalizes the given vector, returning a unit vector with the same direction.

public static Vector2d GetNormalized(Vector2d value)

Parameters

value Vector2d

The vector to normalize.

Returns

Vector2d

A normalized (unit) vector with the same direction.

IsNormalized()

Checks whether this nonzero vector's squared magnitude is within epsilon of one.

public readonly bool IsNormalized()

Returns

bool

Lerp(Vector2d, Fixed64)

Returns a new vector that is the result of linear interpolation toward the target by the specified amount.

public Vector2d Lerp(Vector2d target, Fixed64 amount)

Parameters

target Vector2d
amount Fixed64

Returns

Vector2d

Lerp(Vector2d, Vector2d, Fixed64)

Linearly interpolates between two vectors.

public static Vector2d Lerp(Vector2d a, Vector2d b, Fixed64 amount)

Parameters

a Vector2d
b Vector2d
amount Fixed64

Returns

Vector2d

LerpInPlace(Fixed64, Fixed64, Fixed64)

Linearly interpolates this vector toward the target values by the specified amount.

public Vector2d LerpInPlace(Fixed64 targetx, Fixed64 targety, Fixed64 amount)

Parameters

targetx Fixed64
targety Fixed64
amount Fixed64

Returns

Vector2d

LerpInPlace(Vector2d, Fixed64)

Linearly interpolates this vector toward the target vector by the specified amount.

public Vector2d LerpInPlace(Vector2d target, Fixed64 amount)

Parameters

target Vector2d
amount Fixed64

Returns

Vector2d

Multiply(Vector2d, Fixed64)

Multiplies each vector component by the specified scalar.

public static Vector2d Multiply(Vector2d value, Fixed64 factor)

Parameters

value Vector2d
factor Fixed64

Returns

Vector2d

Multiply(Vector2d, Vector2d)

Multiplies two vectors component-wise.

public static Vector2d Multiply(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d
v2 Vector2d

Returns

Vector2d

MultiplyInPlace(Fixed64)

Multiplies the components of the vector by the specified scalar factor in place and returns the modified vector.

public Vector2d MultiplyInPlace(Fixed64 factor)

Parameters

factor Fixed64

The scalar factor to multiply each component by.

Returns

Vector2d

MultiplyInPlace(Fixed64, Fixed64)

Multiplies the components of the vector by the specified x and y factors in place and returns the modified vector.

public Vector2d MultiplyInPlace(Fixed64 factorX, Fixed64 factorY)

Parameters

factorX Fixed64

The factor to multiply the x component by.

factorY Fixed64

The factor to multiply the y component by.

Returns

Vector2d

The modified vector after multiplication.

MultiplyInPlace(Vector2d)

Multiplies each component of the vector by the corresponding component of the given vector in place and returns the modified vector.

public Vector2d MultiplyInPlace(Vector2d factor)

Parameters

factor Vector2d

The vector containing the multiplication factors for each component.

Returns

Vector2d

NormalizeInPlace()

Normalizes this vector in place, making its magnitude (length) equal to 1, and returns the modified vector.

public Vector2d NormalizeInPlace()

Returns

Vector2d

The normalized vector.

Remarks

If the vector is zero-length or already normalized, no operation is performed. This method modifies the current vector in place and supports method chaining.

NormalizeInPlace(out Fixed64)

Normalizes this vector in place and outputs its original magnitude.

public Vector2d NormalizeInPlace(out Fixed64 mag)

Parameters

mag Fixed64

The original magnitude of the vector before normalization.

Returns

Vector2d

Remarks

If the vector is zero-length or already normalized, no operation is performed, but the original magnitude will still be output.

NotZero()

Determines whether the current value is not equal to zero.

public bool NotZero()

Returns

bool

true if the value is not zero; otherwise, false.

OrientationSign(Vector2d, Vector2d, Vector2d)

Returns the exact orientation sign of the ordered points without fixed-point saturation.

public static int OrientationSign(Vector2d origin, Vector2d first, Vector2d second)

Parameters

origin Vector2d
first Vector2d
second Vector2d

Returns

int

1 for a counter-clockwise turn, -1 for a clockwise turn, or 0 when the points are exactly collinear.

ReflectInPlace(Fixed64, Fixed64)

Reflects this vector across the specified x and y axis.

public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY)

Parameters

axisX Fixed64
axisY Fixed64

Returns

Vector2d

ReflectInPlace(Fixed64, Fixed64, Fixed64)

Reflects this vector across the specified axis using the provided projection of this vector onto the axis.

public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY, Fixed64 projection)

Parameters

axisX Fixed64

The x component of the axis to reflect across.

axisY Fixed64

The y component of the axis to reflect across.

projection Fixed64

The precomputed projection of this vector onto the reflection axis.

Returns

Vector2d

ReflectInPlace(Vector2d)

Reflects this vector across the specified axis vector.

public Vector2d ReflectInPlace(Vector2d axis)

Parameters

axis Vector2d

Returns

Vector2d

Reflected(Fixed64, Fixed64)

Reflects this vector across the specified x and y axis.

public Vector2d Reflected(Fixed64 axisX, Fixed64 axisY)

Parameters

axisX Fixed64
axisY Fixed64

Returns

Vector2d

A new vector representing the result of the reflection.

Reflected(Vector2d)

Reflects this vector across the specified axis vector.

public Vector2d Reflected(Vector2d axis)

Parameters

axis Vector2d

Returns

Vector2d

A new vector representing the result of the reflection.

Rotate(Vector2d, Fixed64)

Rotates this vector by the specified angle (in radians).

public static Vector2d Rotate(Vector2d vec, Fixed64 angleInRadians)

Parameters

vec Vector2d

The vector to rotate.

angleInRadians Fixed64

The angle in radians.

Returns

Vector2d

The rotated vector.

RotateInPlace(Fixed64, Fixed64)

Rotates this vector by the specified cosine and sine values (counter-clockwise).

public Vector2d RotateInPlace(Fixed64 cos, Fixed64 sin)

Parameters

cos Fixed64
sin Fixed64

Returns

Vector2d

RotateInverse(Fixed64, Fixed64)

Rotates this vector in the inverse direction using cosine and sine values.

public void RotateInverse(Fixed64 cos, Fixed64 sin)

Parameters

cos Fixed64

The cosine of the rotation angle.

sin Fixed64

The sine of the rotation angle.

RotateLeftInPlace()

Rotates this vector 90 degrees to the left (counterclockwise).

public Vector2d RotateLeftInPlace()

Returns

Vector2d

RotateRightInPlace()

Rotates this vector 90 degrees to the right (clockwise).

public Vector2d RotateRightInPlace()

Returns

Vector2d

Rotated(Fixed64, Fixed64)

Returns a new vector that is the result of rotating this vector by the specified cosine and sine values.

public Vector2d Rotated(Fixed64 cos, Fixed64 sin)

Parameters

cos Fixed64
sin Fixed64

Returns

Vector2d

Rotated(Vector2d)

Rotates this vector using another vector representing the cosine and sine of the rotation angle.

public Vector2d Rotated(Vector2d rotation)

Parameters

rotation Vector2d

The vector containing the cosine and sine values for rotation.

Returns

Vector2d

A new vector representing the result of the rotation.

Set(Fixed64, Fixed64)

Set x, y and z components of an existing Vector3.

public void Set(Fixed64 newX, Fixed64 newY)

Parameters

newX Fixed64
newY Fixed64

Sign(Vector2d)

Returns a new Vector2d where each component is the sign of the corresponding input component.

public static Vector2d Sign(Vector2d value)

Parameters

value Vector2d

The input vector.

Returns

Vector2d

A vector where each component is -1, 0, or 1 based on the sign of the input.

Subtract(Vector2d, Vector2d)

Subtracts two vectors component-wise.

public static Vector2d Subtract(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d
v2 Vector2d

Returns

Vector2d

SubtractInPlace(Fixed64)

Subtracts the specified value from all components of the vector in place and returns the modified vector.

public Vector2d SubtractInPlace(Fixed64 amount)

Parameters

amount Fixed64

The amount to subtract from each component.

Returns

Vector2d

SubtractInPlace(Fixed64, Fixed64)

Subtracts the specified values from the components of the vector in place and returns the modified vector.

public Vector2d SubtractInPlace(Fixed64 xAmount, Fixed64 yAmount)

Parameters

xAmount Fixed64

The amount to subtract from the x component.

yAmount Fixed64

The amount to subtract from the y component.

Returns

Vector2d

SubtractInPlace(Vector2d)

Subtracts the specified vector from the components of the vector in place and returns the modified vector.

public Vector2d SubtractInPlace(Vector2d other)

Parameters

other Vector2d

Returns

Vector2d

ToDegrees(Vector2d)

Converts each component of the vector from radians to degrees.

public static Vector2d ToDegrees(Vector2d radians)

Parameters

radians Vector2d

The vector with components in radians.

Returns

Vector2d

A new vector with components converted to degrees.

ToRadians(Vector2d)

Converts each component of the vector from degrees to radians.

public static Vector2d ToRadians(Vector2d degrees)

Parameters

degrees Vector2d

The vector with components in degrees.

Returns

Vector2d

A new vector with components converted to radians.

ToString()

Returns a string representation of this vector.

public override readonly string ToString()

Returns

string

ToString(string?, IFormatProvider?)

Returns a string representation of this vector.

public readonly string ToString(string? format, IFormatProvider? formatProvider)

Parameters

format string
formatProvider IFormatProvider

Returns

string

ToVector3d(Fixed64)

Converts this Vector2d to a Vector3d, mapping the Y component of this vector to the Z axis in the resulting vector.

public Vector3d ToVector3d(Fixed64 z)

Parameters

z Fixed64

The value to assign to the Y axis of the resulting Vector3d.

Returns

Vector3d

A new Vector3d where (X, Y) from this Vector2d become (X, Z) in the resulting vector, with the provided Z parameter assigned to Y.

ToVector4d(Fixed64, Fixed64)

Converts this Vector2d to a Vector4d with explicit Z and W components.

public Vector4d ToVector4d(Fixed64 z, Fixed64 w)

Parameters

z Fixed64
w Fixed64

Returns

Vector4d

TryAdd(Vector2d, Vector2d, out Vector2d)

Attempts to add two vectors without component saturation.

public static bool TryAdd(Vector2d left, Vector2d right, out Vector2d result)

Parameters

left Vector2d

The left operand.

right Vector2d

The right operand.

result Vector2d

The exact component-wise sum when every component is representable; otherwise, default.

Returns

bool

true when every exact component is representable; otherwise, false.

TryAddSubtract(Vector2d, Vector2d, Vector2d, out Vector2d)

Attempts to add two vectors and subtract a third component-wise without intermediate saturation.

public static bool TryAddSubtract(Vector2d firstAddend, Vector2d secondAddend, Vector2d subtrahend, out Vector2d result)

Parameters

firstAddend Vector2d

The first addend.

secondAddend Vector2d

The second addend.

subtrahend Vector2d

The vector to subtract from the exact component-wise sum.

result Vector2d

The exact component-wise result when every component is representable; otherwise, default.

Returns

bool

true when every exact component is representable; otherwise, false.

TryComposeScaledLocalPoints(Vector2d, Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to compose two component-scaled offsets in a shared frame and one rotated inner-frame displacement with one final round-half-to-even conversion per component.

public static bool TryComposeScaledLocalPoints(Vector2d outerLocalPoint, Vector2d outerScale, Vector2d innerFrameOffset, Vector2d innerFrameScale, Vector2d innerLocalDisplacement, Fixed64 innerAngleInRadians, out Vector2d result)

Parameters

outerLocalPoint Vector2d
outerScale Vector2d
innerFrameOffset Vector2d
innerFrameScale Vector2d
innerLocalDisplacement Vector2d
innerAngleInRadians Fixed64
result Vector2d

Returns

bool

Remarks

Computes outerScale * outerLocalPoint

  • innerFrameScale * innerFrameOffset
  • Rotate(innerLocalDisplacement) without narrowing either scaled offset or the rotated displacement independently.

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

destination Span<char>
charsWritten int
format ReadOnlySpan<char>
provider IFormatProvider

Returns

bool

TryGetDistance(Vector2d, Vector2d, out Fixed64)

Attempts to return the distance between two endpoints without saturating either component difference.

public static bool TryGetDistance(Vector2d start, Vector2d end, out Fixed64 distance)

Parameters

start Vector2d

The first endpoint.

end Vector2d

The second endpoint.

distance Fixed64

The rounded distance, or MaxValue when it is not representable.

Returns

bool

true when the distance fits in Fixed64; otherwise, false.

TryGetMagnitude(Vector2d, out Fixed64)

Attempts to return the magnitude of the given vector without saturating the result.

public static bool TryGetMagnitude(Vector2d vector, out Fixed64 magnitude)

Parameters

vector Vector2d

The vector to measure.

magnitude Fixed64

The magnitude, or MaxValue when it is not representable.

Returns

bool

true when the magnitude fits in Fixed64; otherwise, false.

TryGetMagnitudeCeiling(out Fixed64)

Attempts to return this vector's magnitude rounded outward to the smallest containing Q32.32 value.

public readonly bool TryGetMagnitudeCeiling(out Fixed64 magnitude)

Parameters

magnitude Fixed64

Returns

bool

false only when the final ceiling exceeds the positive Fixed64 domain.

TryGetRelativeOffset(Vector2d, Vector2d, Fixed64, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to obtain the exact relative offset between two transformed local points.

public static bool TryGetRelativeOffset(Vector2d firstOrigin, Vector2d firstLocalPoint, Fixed64 firstAngleInRadians, Vector2d secondOrigin, Vector2d secondLocalPoint, Fixed64 secondAngleInRadians, out Vector2d result)

Parameters

firstOrigin Vector2d
firstLocalPoint Vector2d
firstAngleInRadians Fixed64
secondOrigin Vector2d
secondLocalPoint Vector2d
secondAngleInRadians Fixed64
result Vector2d

Returns

bool

true when both final components are representable; otherwise, false and result is default.

Remarks

The computed relation is firstOrigin + Rotate(firstLocalPoint, firstAngleInRadians)

  • secondOrigin - Rotate(secondLocalPoint, secondAngleInRadians). Neither rotated point nor any intermediate sum is narrowed independently.

TryGetRelativeOffset(Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to obtain the exact relative offset firstOrigin + firstOffset - secondOrigin - Rotate(secondLocalPoint).

public static bool TryGetRelativeOffset(Vector2d firstOrigin, Vector2d firstOffset, Vector2d secondOrigin, Vector2d secondLocalPoint, Fixed64 angleInRadians, out Vector2d result)

Parameters

firstOrigin Vector2d
firstOffset Vector2d
secondOrigin Vector2d
secondLocalPoint Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

true when both final components are representable; otherwise, false and result is default.

Remarks

No rotated point or intermediate sum is narrowed independently.

TryGetWeightedAverage(ReadOnlySpan<Vector2d>, ReadOnlySpan<Fixed64>, out Vector2d)

Attempts to calculate the exact non-negative weighted average with one final round-half-to-even conversion per component.

public static bool TryGetWeightedAverage(ReadOnlySpan<Vector2d> values, ReadOnlySpan<Fixed64> weights, out Vector2d average)

Parameters

values ReadOnlySpan<Vector2d>
weights ReadOnlySpan<Fixed64>
average Vector2d

Returns

bool

Remarks

Zero-weight values are ignored. The operation returns false only when the total weight is zero.

TryInverseTransformScaledPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to transform a world point into a component-scaled local frame with one final round-half-to-even conversion per component.

public static bool TryInverseTransformScaledPoint(Vector2d origin, Vector2d worldPoint, Vector2d scale, Fixed64 angleInRadians, out Vector2d localPoint)

Parameters

origin Vector2d
worldPoint Vector2d
scale Vector2d
angleInRadians Fixed64
localPoint Vector2d

Returns

bool

Remarks

Computes InverseRotate(worldPoint - origin) / scale without narrowing the world offset, rotated projection, or scale division independently. A zero scale component or unrepresentable final coordinate returns false and a zero result.

TryRotate(Vector2d, Fixed64, out Vector2d)

Attempts to rotate a vector by the specified angle with one final round-half-to-even conversion per component.

public static bool TryRotate(Vector2d vector, Fixed64 angleInRadians, out Vector2d result)

Parameters

vector Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

true when both final components are representable; otherwise, false and result is default.

TrySubtract(Vector2d, Vector2d, out Vector2d)

Attempts to subtract two vectors without component saturation.

public static bool TrySubtract(Vector2d left, Vector2d right, out Vector2d result)

Parameters

left Vector2d

The left operand.

right Vector2d

The right operand.

result Vector2d

The exact component-wise difference when every component is representable; otherwise, default.

Returns

bool

true when every exact component is representable; otherwise, false.

TrySubtractSums(Vector2d, Vector2d, Vector2d, Vector2d, out Vector2d)

Attempts to compute (firstLeft + firstRight) - (secondLeft + secondRight) component-wise without intermediate saturation.

public static bool TrySubtractSums(Vector2d firstLeft, Vector2d firstRight, Vector2d secondLeft, Vector2d secondRight, out Vector2d result)

Parameters

firstLeft Vector2d
firstRight Vector2d
secondLeft Vector2d
secondRight Vector2d
result Vector2d

Returns

bool

TryTransformPoint(Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to transform a local point by a rotation and origin with one final round-half-to-even conversion per component.

public static bool TryTransformPoint(Vector2d origin, Vector2d localPoint, Fixed64 angleInRadians, out Vector2d result)

Parameters

origin Vector2d
localPoint Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

true when both final world components are representable; otherwise, false and result is default.

TryTransformPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to transform a local point by a rotation and add two origins with one final round-half-to-even conversion per component.

public static bool TryTransformPoint(Vector2d firstOrigin, Vector2d secondOrigin, Vector2d localPoint, Fixed64 angleInRadians, out Vector2d result)

Parameters

firstOrigin Vector2d
secondOrigin Vector2d
localPoint Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

true when both final world components are representable; otherwise, false and result is default.

TryTransformScaledPoint(Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to transform a component-scaled local point by a rotation and world origin with one final round-half-to-even conversion per component.

public static bool TryTransformScaledPoint(Vector2d origin, Vector2d localPoint, Vector2d scale, Fixed64 angleInRadians, out Vector2d result)

Parameters

origin Vector2d
localPoint Vector2d
scale Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

TryTransformScaledPoint(Vector2d, Vector2d, Vector2d, Vector2d, Fixed64, out Vector2d)

Attempts to transform a component-scaled local point plus an unscaled local displacement by a rotation and world origin with one final round-half-to-even conversion per component.

public static bool TryTransformScaledPoint(Vector2d origin, Vector2d localPoint, Vector2d scale, Vector2d localDisplacement, Fixed64 angleInRadians, out Vector2d result)

Parameters

origin Vector2d
localPoint Vector2d
scale Vector2d
localDisplacement Vector2d
angleInRadians Fixed64
result Vector2d

Returns

bool

Remarks

Computes origin + Rotate(scale * localPoint + localDisplacement) without narrowing the scaled point, local sum, or rotated offset independently.

Operators

operator +(Fixed64, Vector2d)

Adds a scalar value to each component of the specified vector and returns the resulting vector.

public static Vector2d operator +(Fixed64 mag, Vector2d v1)

Parameters

mag Fixed64

The scalar value to add to each component of the vector.

v1 Vector2d

The vector to which the scalar value will be added.

Returns

Vector2d

A new Vector2d whose components are the sum of the corresponding components of the input vector and the scalar value.

operator +(Vector2d, Fixed64)

Adds a scalar value to each component of the specified vector and returns the resulting vector.

public static Vector2d operator +(Vector2d v1, Fixed64 mag)

Parameters

v1 Vector2d

The vector to which the scalar value will be added.

mag Fixed64

The scalar value to add to each component of the vector.

Returns

Vector2d

A new Vector2d whose components are the sum of the corresponding components of the input vector and the scalar value.

operator +(Vector2d, Vector2d)

Adds two Vector2d instances component-wise.

public static Vector2d operator +(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d

The first vector to add.

v2 Vector2d

The second vector to add.

Returns

Vector2d

A new Vector2d whose components are the sums of the corresponding components of v1 and v2.

operator +(Vector2d, (int x, int y))

Adds a Vector2d instance and a tuple representing X and Y components, returning a new Vector2d with the summed values.

public static Vector2d operator +(Vector2d v1, (int x, int y) v2)

Parameters

v1 Vector2d

The first vector to add.

v2 (int x, int y)

A tuple containing the X and Y values to add to the vector.

Returns

Vector2d

A new Vector2d whose X and Y components are the sums of the corresponding components of the input vector and tuple.

operator +((int x, int y), Vector2d)

Adds a tuple representing X and Y components and a Vector2d instance, returning a new Vector2d with the summed values.

public static Vector2d operator +((int x, int y) v2, Vector2d v1)

Parameters

v2 (int x, int y)

A tuple containing the X and Y values to add to the vector.

v1 Vector2d

The vector to add.

Returns

Vector2d

A new Vector2d whose X and Y components are the sums of the corresponding components of the tuple and input vector.

operator /(Vector2d, Fixed64)

Divides each component of a specified vector by a scalar value.

public static Vector2d operator /(Vector2d v1, Fixed64 div)

Parameters

v1 Vector2d

The vector whose components are to be divided.

div Fixed64

The scalar value by which to divide each component of the vector.

Returns

Vector2d

A new Vector2d whose components are the result of dividing the corresponding components of v1 by div.

operator ==(Vector2d, Vector2d)

Determines whether two Vector2d instances are equal.

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

Parameters

left Vector2d
right Vector2d

Returns

bool

operator !=(Vector2d, Vector2d)

Determines whether two Vector2d instances are not equal.

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

Parameters

left Vector2d
right Vector2d

Returns

bool

operator *(Fixed64, Vector2d)

Scales the specified vector by the given scalar value.

public static Vector2d operator *(Fixed64 mag, Vector2d v1)

Parameters

mag Fixed64

The scalar value by which to multiply each component of the vector.

v1 Vector2d

The vector to be scaled.

Returns

Vector2d

A new Vector2d whose components are the components of v1 multiplied by mag.

operator *(Vector2d, Fixed64)

Scales the specified vector by the given scalar value.

public static Vector2d operator *(Vector2d v1, Fixed64 mag)

Parameters

v1 Vector2d

The vector to be scaled.

mag Fixed64

The scalar value by which to multiply each component of the vector.

Returns

Vector2d

A new Vector2d whose components are the components of v1 multiplied by mag.

operator *(Vector2d, Vector2d)

Multiplies two vectors element-wise and returns the resulting vector.

public static Vector2d operator *(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d

The first vector to multiply.

v2 Vector2d

The second vector to multiply.

Returns

Vector2d

A new Vector2d whose components are the products of the corresponding components of the input vectors.

Remarks

Element-wise multiplication multiplies each component of the first vector by the corresponding component of the second vector. This operation is not a dot product or cross product.

operator -(Fixed64, Vector2d)

Subtracts the specified scalar value from both components of the given vector and returns the resulting vector.

public static Vector2d operator -(Fixed64 mag, Vector2d v1)

Parameters

mag Fixed64

The scalar value to subtract from each component of the vector.

v1 Vector2d

The vector from which to subtract the scalar value.

Returns

Vector2d

A new Vector2d whose components are the result of subtracting the scalar value from the corresponding components of the input vector.

operator -(Vector2d, Fixed64)

Subtracts the specified scalar value from both components of the given vector and returns the resulting vector.

public static Vector2d operator -(Vector2d v1, Fixed64 mag)

Parameters

v1 Vector2d

The vector from which to subtract the scalar value.

mag Fixed64

The scalar value to subtract from each component of the vector.

Returns

Vector2d

A new Vector2d whose components are the result of subtracting the scalar value from the corresponding components of the input vector.

operator -(Vector2d, Vector2d)

Subtracts the components of one Vector2d from another and returns the resulting vector.

public static Vector2d operator -(Vector2d v1, Vector2d v2)

Parameters

v1 Vector2d

The vector to subtract from.

v2 Vector2d

The vector to subtract.

Returns

Vector2d

A Vector2d whose components are the result of subtracting the corresponding components of v2 from v1.

operator -(Vector2d, (int x, int y))

Subtracts the specified tuple from the given vector and returns the resulting vector.

public static Vector2d operator -(Vector2d v1, (int x, int y) v2)

Parameters

v1 Vector2d

The vector from which to subtract the tuple values.

v2 (int x, int y)

A tuple containing the x and y values to subtract from the vector.

Returns

Vector2d

A new Vector2d representing the result of subtracting the tuple values from the original vector.

operator -((int x, int y), Vector2d)

Subtracts the specified Vector2d from the given integer tuple and returns the resulting vector.

public static Vector2d operator -((int x, int y) v1, Vector2d v2)

Parameters

v1 (int x, int y)

A tuple containing the x and y components to subtract from.

v2 Vector2d

The vector whose components are subtracted from the tuple.

Returns

Vector2d

A Vector2d representing the result of subtracting the components of v2 from v1.

operator -(Vector2d)

Negates the specified vector by reversing the sign of each of its components.

public static Vector2d operator -(Vector2d v1)

Parameters

v1 Vector2d

The vector to negate.

Returns

Vector2d

A new Vector2d whose components are the negated values of the input vector.