< Summary

Information
Class: FixedMathSharp.Vector2d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector2d.cs
Line coverage
99%
Covered lines: 335
Uncovered lines: 3
Coverable lines: 338
Total lines: 1161
Line coverage: 99.1%
Branch coverage
100%
Covered branches: 32
Total branches: 32
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_RotatedRight()100%11100%
get_RotatedLeft()100%11100%
get_RightHandNormal()100%11100%
get_LeftHandNormal()100%11100%
get_Normal()100%11100%
get_Magnitude()100%11100%
get_SqrMagnitude()100%11100%
get_LongStateHash()100%11100%
get_StateHash()100%11100%
get_Item(...)100%44100%
set_Item(...)100%44100%
Set(...)100%11100%
AddInPlace(...)100%11100%
AddInPlace(...)100%11100%
AddInPlace(...)100%11100%
SubtractInPlace(...)100%11100%
SubtractInPlace(...)100%11100%
SubtractInPlace(...)100%11100%
ScaleInPlace(...)100%11100%
ScaleInPlace(...)100%11100%
Normalize()100%11100%
Normalize(...)100%44100%
LerpInPlace(...)100%11100%
LerpInPlace(...)100%44100%
Lerp(...)100%11100%
Lerped(...)100%11100%
RotateInPlace(...)100%11100%
Rotated(...)100%11100%
Rotated(...)100%11100%
RotateInverse(...)100%11100%
RotateRightInPlace()100%11100%
RotateLeftInPlace()100%11100%
ReflectInPlace(...)100%11100%
ReflectInPlace(...)100%11100%
ReflectInPlace(...)100%11100%
Reflected(...)100%11100%
Reflected(...)100%11100%
Dot(...)100%11100%
Dot(...)100%11100%
CrossProduct(...)100%11100%
CrossProduct(...)100%11100%
Distance(...)100%11100%
Distance(...)100%11100%
SqrDistance(...)100%11100%
SqrDistance(...)100%11100%
GetNormalized(...)100%44100%
GetMagnitude(...)100%66100%
Abs(...)100%11100%
Sign(...)100%11100%
CreateRotation(...)100%11100%
Distance(...)100%11100%
SqrDistance(...)100%11100%
ForwardDirection(...)100%11100%
Dot(...)100%11100%
Scale(...)100%11100%
CrossProduct(...)100%210%
Rotate(...)100%11100%
ToString()100%11100%
ToVector3d(...)100%11100%
ToVector4d(...)100%11100%
Deconstruct(...)100%11100%
Deconstruct(...)100%11100%
ToDegrees(...)100%11100%
ToRadians(...)100%11100%
op_Addition(...)100%11100%
op_Addition(...)100%11100%
op_Addition(...)100%11100%
op_Addition(...)100%11100%
op_Addition(...)100%11100%
op_Subtraction(...)100%11100%
op_Subtraction(...)100%11100%
op_Subtraction(...)100%11100%
op_Subtraction(...)100%11100%
op_Subtraction(...)100%11100%
op_UnaryNegation(...)100%11100%
op_Multiply(...)100%11100%
op_Multiply(...)100%11100%
op_Division(...)100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
EqualsZero()100%11100%
NotZero()100%11100%
AllComponentsGreaterThanEpsilon()100%22100%
Equals(...)100%22100%
Equals(...)100%22100%
Equals(...)100%11100%
GetHashCode()100%11100%
GetHashCode(...)100%11100%
CompareTo(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector2d.cs

#LineLine coverage
 1using MemoryPack;
 2using System;
 3using System.Collections.Generic;
 4using System.Runtime.CompilerServices;
 5using System.Text.Json.Serialization;
 6
 7namespace FixedMathSharp;
 8
 9/// <summary>
 10/// Represents a 2D vector with fixed-point precision, offering a range of mathematical operations
 11/// and transformations such as rotation, scaling, reflection, and interpolation.
 12/// </summary>
 13/// <remarks>
 14/// The Vector2d struct is designed for applications that require precise numerical operations,
 15/// such as games, simulations, or physics engines. It provides methods for common vector operations
 16/// like addition, subtraction, dot product, cross product, distance calculations, and rotation.
 17///
 18/// Use Cases:
 19/// - Modeling 2D positions, directions, and velocities in fixed-point math environments.
 20/// - Performing vector transformations, including rotations and reflections.
 21/// - Handling interpolation and distance calculations in physics or simulation systems.
 22/// - Useful for fixed-point math scenarios where floating-point precision is insufficient or not desired.
 23/// </remarks>
 24[Serializable]
 25[MemoryPackable]
 26public partial struct Vector2d : IEquatable<Vector2d>, IComparable<Vector2d>, IEqualityComparer<Vector2d>
 27{
 28    #region Static Readonly Fields
 29
 30    /// <summary>
 31    /// (1, 0)
 32    /// </summary>
 33    public static readonly Vector2d DefaultRotation = new(1, 0);
 34
 35    /// <summary>
 36    /// (0, 1)
 37    /// </summary>
 38    public static readonly Vector2d Forward = new(0, 1);
 39
 40    /// <summary>
 41    /// (1, 0)
 42    /// </summary>
 43    public static readonly Vector2d Right = new(1, 0);
 44
 45    /// <summary>
 46    /// (0, -1)
 47    /// </summary>
 48    public static readonly Vector2d Down = new(0, -1);
 49
 50    /// <summary>
 51    /// (-1, 0)
 52    /// </summary>
 53    public static readonly Vector2d Left = new(-1, 0);
 54
 55    /// <summary>
 56    /// (1, 1)
 57    /// </summary>
 58    public static readonly Vector2d One = new(1, 1);
 59
 60    /// <summary>
 61    /// (-1, -1)
 62    /// </summary>
 63    public static readonly Vector2d Negative = new(-1, -1);
 64
 65    /// <summary>
 66    /// (0, 0)
 67    /// </summary>
 68    public static readonly Vector2d Zero = new(0, 0);
 69
 70    #endregion
 71
 72    #region Fields
 73
 74    /// <summary>
 75    /// The X component of the vector.
 76    /// </summary>
 77    [JsonInclude]
 78    [MemoryPackOrder(0)]
 79    public Fixed64 x;
 80
 81    /// <summary>
 82    /// The Y component of the vector.
 83    /// </summary>
 84    [JsonInclude]
 85    [MemoryPackOrder(1)]
 86    public Fixed64 y;
 87
 88    #endregion
 89
 90    #region Constructors
 91
 92    /// <summary>
 93    /// Initializes a new instance of the Vector2d structure using integer values for the X and Y components.
 94    /// </summary>
 95    /// <param name="xInt">The X component of the vector, specified as an integer.</param>
 96    /// <param name="yInt">The Y component of the vector, specified as an integer.</param>
 41197    public Vector2d(int xInt, int yInt) : this((Fixed64)xInt, (Fixed64)yInt) { }
 98
 99    /// <summary>
 100    /// Initializes a new instance of the Vector2d structure using the specified X and Y coordinates as double-precision
 101    /// floating-point values.
 102    /// </summary>
 103    /// <param name="xDoub">The X coordinate of the vector, specified as a double-precision floating-point value.</param
 104    /// <param name="yDoub">The Y coordinate of the vector, specified as a double-precision floating-point value.</param
 21105    public Vector2d(double xDoub, double yDoub) : this((Fixed64)xDoub, (Fixed64)yDoub) { }
 106
 107    /// <summary>
 108    /// Initializes a new instance of the Vector2d structure with the specified X and Y components.
 109    /// </summary>
 110    /// <param name="x">The value to assign to the X component of the vector.</param>
 111    /// <param name="y">The value to assign to the Y component of the vector.</param>
 112    [JsonConstructor]
 113    public Vector2d(Fixed64 x, Fixed64 y)
 197114    {
 197115        this.x = x;
 197116        this.y = y;
 197117    }
 118
 119    #endregion
 120
 121    #region Properties
 122
 123    /// <summary>
 124    /// Rotates the vector to the right (90 degrees clockwise).
 125    /// </summary>
 126    [JsonIgnore]
 127    [MemoryPackIgnore]
 128    public Vector2d RotatedRight
 129    {
 130        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1131        get => new(y, -x);
 132    }
 133
 134    /// <summary>
 135    /// Rotates the vector to the left (90 degrees counterclockwise).
 136    /// </summary>
 137    [JsonIgnore]
 138    [MemoryPackIgnore]
 139    public Vector2d RotatedLeft
 140    {
 141        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1142        get => new(-y, x);
 143    }
 144
 145    /// <summary>
 146    /// Gets the right-hand (counter-clockwise) normal vector.
 147    /// </summary>
 148    [JsonIgnore]
 149    [MemoryPackIgnore]
 150    public Vector2d RightHandNormal
 151    {
 152        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1153        get => new(-y, x);
 154    }
 155
 156    /// <summary>
 157    /// Gets the left-hand (clockwise) normal vector.
 158    /// </summary>
 159    [JsonIgnore]
 160    [MemoryPackIgnore]
 161    public Vector2d LeftHandNormal
 162    {
 163        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1164        get => new(y, -x);
 165    }
 166
 167    /// <inheritdoc cref="GetNormalized(Vector2d)"/>
 168    [JsonIgnore]
 169    [MemoryPackIgnore]
 170    public Vector2d Normal
 171    {
 172        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1173        get => GetNormalized(this);
 174    }
 175
 176    /// <summary>
 177    /// Returns the actual length of this vector (RO).
 178    /// </summary>
 179    [JsonIgnore]
 180    [MemoryPackIgnore]
 181    public Fixed64 Magnitude
 182    {
 183        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 15184        get => GetMagnitude(this);
 185    }
 186
 187    /// <summary>
 188    /// Returns the square magnitude of the vector (avoids calculating the square root).
 189    /// </summary>
 190    [JsonIgnore]
 191    [MemoryPackIgnore]
 192    public Fixed64 SqrMagnitude
 193    {
 194        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 4195        get => x * x + y * y;
 196    }
 197
 198    /// <summary>
 199    /// Returns a long hash of the vector based on its x and y values.
 200    /// </summary>
 201    [JsonIgnore]
 202    [MemoryPackIgnore]
 203    public long LongStateHash
 204    {
 205        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 7206        get => x.m_rawValue * 31 + y.m_rawValue * 7;
 207    }
 208
 209    /// <summary>
 210    /// Returns a hash of the vector based on its state.
 211    /// </summary>
 212    [JsonIgnore]
 213    [MemoryPackIgnore]
 214    public int StateHash
 215    {
 216        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5217        get => (int)(LongStateHash % int.MaxValue);
 218    }
 219
 220    /// <summary>
 221    /// Gets or sets the vector component at the specified index.
 222    /// </summary>
 223    /// <remarks>
 224    /// This indexer provides array-like access to the vector's components.
 225    /// Index 0 corresponds to the X component, and index 1 corresponds to the Y component.
 226    /// </remarks>
 227    /// <param name="index">The zero-based index of the component to access. Use 0 for the X component and 1 for the Y c
 228    /// <returns>The vector component at the specified index.</returns>
 229    /// <exception cref="IndexOutOfRangeException">Thrown when the index is less than 0 or greater than 1.</exception>
 230    [JsonIgnore]
 231    [MemoryPackIgnore]
 232    public Fixed64 this[int index]
 233    {
 234        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 235        get
 8236        {
 8237            return index switch
 8238            {
 3239                0 => x,
 3240                1 => y,
 2241                _ => throw new IndexOutOfRangeException("Invalid Vector2d index!"),
 8242            };
 6243        }
 244        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 245        set
 8246        {
 8247            switch (index)
 248            {
 249                case 0:
 3250                    x = value;
 3251                    break;
 252                case 1:
 3253                    y = value;
 3254                    break;
 255                default:
 2256                    throw new IndexOutOfRangeException("Invalid Vector2d index!");
 257            }
 6258        }
 259    }
 260
 261    #endregion
 262
 263    #region Methods (Instance)
 264
 265    /// <summary>
 266    /// Set x, y and z components of an existing Vector3.
 267    /// </summary>
 268    /// <param name="newX"></param>
 269    /// <param name="newY"></param>
 270    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 271    public void Set(Fixed64 newX, Fixed64 newY)
 1272    {
 1273        x = newX;
 1274        y = newY;
 1275    }
 276
 277    /// <summary>
 278    /// Adds the specified values to the components of the vector in place and returns the modified vector.
 279    /// </summary>
 280    /// <param name="amount">The amount to add to the components.</param>
 281    /// <returns>The modified vector after addition.</returns>
 282    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 283    public Vector2d AddInPlace(Fixed64 amount)
 2284    {
 2285        x += amount;
 2286        y += amount;
 2287        return this;
 2288    }
 289
 290    /// <summary>
 291    /// Adds the specified values to the components of the vector in place and returns the modified vector.
 292    /// </summary>
 293    /// <param name="xAmount">The amount to add to the x component.</param>
 294    /// <param name="yAmount">The amount to add to the y component.</param>
 295    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 296    public Vector2d AddInPlace(Fixed64 xAmount, Fixed64 yAmount)
 2297    {
 2298        x += xAmount;
 2299        y += yAmount;
 2300        return this;
 2301    }
 302
 303    /// <inheritdoc cref="AddInPlace(Fixed64, Fixed64)"/>
 304    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 305    public Vector2d AddInPlace(Vector2d other)
 1306    {
 1307        AddInPlace(other.x, other.y);
 1308        return this;
 1309    }
 310
 311    /// <summary>
 312    /// Subtracts the specified value from all components of the vector in place and returns the modified vector.
 313    /// </summary>
 314    /// <param name="amount">The amount to subtract from each component.</param>
 315    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 316    public Vector2d SubtractInPlace(Fixed64 amount)
 2317    {
 2318        x -= amount;
 2319        y -= amount;
 2320        return this;
 2321    }
 322
 323    /// <summary>
 324    /// Subtracts the specified values from the components of the vector in place and returns the modified vector.
 325    /// </summary>
 326    /// <param name="xAmount">The amount to subtract from the x component.</param>
 327    /// <param name="yAmount">The amount to subtract from the y component.</param>
 328    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 329    public Vector2d SubtractInPlace(Fixed64 xAmount, Fixed64 yAmount)
 2330    {
 2331        x -= xAmount;
 2332        y -= yAmount;
 2333        return this;
 2334    }
 335
 336    /// <summary>
 337    /// Subtracts the specified vector from the components of the vector in place and returns the modified vector.
 338    /// </summary>
 339    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 340    public Vector2d SubtractInPlace(Vector2d other)
 1341    {
 1342        SubtractInPlace(other.x, other.y);
 1343        return this;
 1344    }
 345
 346    /// <summary>
 347    /// Scales the components of the vector by the specified scalar factor in place and returns the modified vector.
 348    /// </summary>
 349    /// <param name="scaleFactor">The scalar factor to multiply each component by.</param>
 350    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 351    public Vector2d ScaleInPlace(Fixed64 scaleFactor)
 1352    {
 1353        x *= scaleFactor;
 1354        y *= scaleFactor;
 1355        return this;
 1356    }
 357
 358    /// <summary>
 359    /// Scales each component of the vector by the corresponding component of the given vector in place and returns the 
 360    /// </summary>
 361    /// <param name="scale">The vector containing the scale factors for each component.</param>
 362    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 363    public Vector2d ScaleInPlace(Vector2d scale)
 1364    {
 1365        x *= scale.x;
 1366        y *= scale.y;
 1367        return this;
 1368    }
 369
 370    /// <summary>
 371    /// Normalizes this vector in place, making its magnitude (length) equal to 1, and returns the modified vector.
 372    /// </summary>
 373    /// <remarks>
 374    /// If the vector is zero-length or already normalized, no operation is performed.
 375    /// This method modifies the current vector in place and supports method chaining.
 376    /// </remarks>
 377    /// <returns>The normalized vector.</returns>
 378    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 379    public Vector2d Normalize()
 3380    {
 3381        return this = GetNormalized(this);
 3382    }
 383
 384    /// <summary>
 385    /// Normalizes this vector in place and outputs its original magnitude.
 386    /// </summary>
 387    /// <param name="mag">The original magnitude of the vector before normalization.</param>
 388    /// <remarks>
 389    /// If the vector is zero-length or already normalized, no operation is performed, but the original magnitude will s
 390    /// </remarks>
 391    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 392    public Vector2d Normalize(out Fixed64 mag)
 3393    {
 3394        mag = GetMagnitude(this);
 395
 396        // If magnitude is zero, return a zero vector to avoid divide-by-zero errors
 3397        if (mag == Fixed64.Zero)
 1398        {
 1399            x = Fixed64.Zero;
 1400            y = Fixed64.Zero;
 1401            return this;
 402        }
 403
 404        // If already normalized, return as-is
 2405        if (mag == Fixed64.One)
 1406            return this;
 407
 1408        x /= mag;
 1409        y /= mag;
 410
 1411        return this;
 3412    }
 413
 414    /// <summary>
 415    /// Linearly interpolates this vector toward the target vector by the specified amount.
 416    /// </summary>
 417    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 418    public Vector2d LerpInPlace(Vector2d target, Fixed64 amount)
 2419    {
 2420        LerpInPlace(target.x, target.y, amount);
 2421        return this;
 2422    }
 423
 424    /// <summary>
 425    /// Linearly interpolates this vector toward the target values by the specified amount.
 426    /// </summary>
 427    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 428    public Vector2d LerpInPlace(Fixed64 targetx, Fixed64 targety, Fixed64 amount)
 3429    {
 3430        if (amount >= Fixed64.One)
 1431        {
 1432            x = targetx;
 1433            y = targety;
 1434        }
 2435        else if (amount > Fixed64.Zero)
 2436        {
 2437            x = targetx * amount + x * (Fixed64.One - amount);
 2438            y = targety * amount + y * (Fixed64.One - amount);
 2439        }
 3440        return this;
 3441    }
 442
 443    /// <summary>
 444    /// Linearly interpolates between two vectors.
 445    /// </summary>
 446    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 447    public static Vector2d Lerp(Vector2d a, Vector2d b, Fixed64 amount)
 2448    {
 2449        amount = FixedMath.Clamp01(amount);
 2450        return new Vector2d(a.x + (b.x - a.x) * amount, a.y + (b.y - a.y) * amount);
 2451    }
 452
 453    /// <summary>
 454    /// Returns a new vector that is the result of linear interpolation toward the target by the specified amount.
 455    /// </summary>
 456    public Vector2d Lerped(Vector2d target, Fixed64 amount)
 1457    {
 1458        Vector2d vec = this;
 1459        vec.LerpInPlace(target.x, target.y, amount);
 1460        return vec;
 1461    }
 462
 463    /// <summary>
 464    /// Rotates this vector by the specified cosine and sine values (counter-clockwise).
 465    /// </summary>
 466    public Vector2d RotateInPlace(Fixed64 cos, Fixed64 sin)
 4467    {
 4468        Fixed64 temp1 = x * cos - y * sin;
 4469        y = x * sin + y * cos;
 4470        x = temp1;
 4471        return this;
 4472    }
 473
 474    /// <summary>
 475    /// Returns a new vector that is the result of rotating this vector by the specified cosine and sine values.
 476    /// </summary>
 477    public Vector2d Rotated(Fixed64 cos, Fixed64 sin)
 2478    {
 2479        Vector2d vec = this;
 2480        vec.RotateInPlace(cos, sin);
 2481        return vec;
 2482    }
 483
 484    /// <summary>
 485    /// Rotates this vector using another vector representing the cosine and sine of the rotation angle.
 486    /// </summary>
 487    /// <param name="rotation">The vector containing the cosine and sine values for rotation.</param>
 488    /// <returns>A new vector representing the result of the rotation.</returns>
 489    public Vector2d Rotated(Vector2d rotation)
 1490    {
 1491        return Rotated(rotation.x, rotation.y);
 1492    }
 493
 494    /// <summary>
 495    /// Rotates this vector in the inverse direction using cosine and sine values.
 496    /// </summary>
 497    /// <param name="cos">The cosine of the rotation angle.</param>
 498    /// <param name="sin">The sine of the rotation angle.</param>
 499    public void RotateInverse(Fixed64 cos, Fixed64 sin)
 1500    {
 1501        RotateInPlace(cos, -sin);
 1502    }
 503
 504    /// <summary>
 505    /// Rotates this vector 90 degrees to the right (clockwise).
 506    /// </summary>
 507    public Vector2d RotateRightInPlace()
 1508    {
 1509        Fixed64 temp1 = x;
 1510        x = y;
 1511        y = -temp1;
 1512        return this;
 1513    }
 514
 515    /// <summary>
 516    /// Rotates this vector 90 degrees to the left (counterclockwise).
 517    /// </summary>
 518    public Vector2d RotateLeftInPlace()
 1519    {
 1520        Fixed64 temp1 = x;
 1521        x = -y;
 1522        y = temp1;
 1523        return this;
 1524    }
 525
 526    /// <summary>
 527    /// Reflects this vector across the specified axis vector.
 528    /// </summary>
 529    public Vector2d ReflectInPlace(Vector2d axis)
 1530    {
 1531        return ReflectInPlace(axis.x, axis.y);
 1532    }
 533
 534    /// <summary>
 535    /// Reflects this vector across the specified x and y axis.
 536    /// </summary>
 537    public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY)
 4538    {
 4539        Fixed64 projection = Dot(axisX, axisY);
 4540        return ReflectInPlace(axisX, axisY, projection);
 4541    }
 542
 543    /// <summary>
 544    /// Reflects this vector across the specified axis using the provided projection of this vector onto the axis.
 545    /// </summary>
 546    /// /// <param name="axisX">The x component of the axis to reflect across.</param>
 547    /// <param name="axisY">The y component of the axis to reflect across.</param>
 548    /// <param name="projection">The precomputed projection of this vector onto the reflection axis.</param>
 549    public Vector2d ReflectInPlace(Fixed64 axisX, Fixed64 axisY, Fixed64 projection)
 5550    {
 5551        Fixed64 temp1 = axisX * projection;
 5552        Fixed64 temp2 = axisY * projection;
 5553        x = temp1 + temp1 - x;
 5554        y = temp2 + temp2 - y;
 5555        return this;
 5556    }
 557
 558    /// <summary>
 559    /// Reflects this vector across the specified x and y axis.
 560    /// </summary>
 561    /// <returns>A new vector representing the result of the reflection.</returns>
 562    public Vector2d Reflected(Fixed64 axisX, Fixed64 axisY)
 2563    {
 2564        Vector2d vec = this;
 2565        vec.ReflectInPlace(axisX, axisY);
 2566        return vec;
 2567    }
 568
 569    /// <summary>
 570    /// Reflects this vector across the specified axis vector.
 571    /// </summary>
 572    /// <returns>A new vector representing the result of the reflection.</returns>
 573    public Vector2d Reflected(Vector2d axis)
 1574    {
 1575        return Reflected(axis.x, axis.y);
 1576    }
 577
 578    /// <summary>
 579    /// Returns the dot product of this vector with another vector.
 580    /// </summary>
 581    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 582    public Fixed64 Dot(Fixed64 otherX, Fixed64 otherY)
 7583    {
 7584        return x * otherX + y * otherY;
 7585    }
 586
 587    /// <summary>
 588    /// Returns the dot product of this vector with another vector.
 589    /// </summary>
 590    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 591    public Fixed64 Dot(Vector2d other)
 2592    {
 2593        return Dot(other.x, other.y);
 2594    }
 595
 596    /// <summary>
 597    /// Computes the cross product magnitude of this vector with another vector.
 598    /// </summary>
 599    /// <param name="otherX">The X component of the other vector.</param>
 600    /// <param name="otherY">The Y component of the other vector.</param>
 601    /// <returns>The cross product magnitude.</returns>
 602    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 603    public Fixed64 CrossProduct(Fixed64 otherX, Fixed64 otherY)
 1604    {
 1605        return x * otherY - y * otherX;
 1606    }
 607
 608    /// <inheritdoc cref="CrossProduct(Fixed64, Fixed64)"/>
 609    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 610    public Fixed64 CrossProduct(Vector2d other)
 1611    {
 1612        return CrossProduct(other.x, other.y);
 1613    }
 614
 615    /// <summary>
 616    /// Returns the distance between this vector and another vector specified by its components.
 617    /// </summary>
 618    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 619    public Fixed64 Distance(Fixed64 otherX, Fixed64 otherY)
 2620    {
 2621        Fixed64 temp1 = x - otherX;
 2622        temp1 *= temp1;
 2623        Fixed64 temp2 = y - otherY;
 2624        temp2 *= temp2;
 2625        return FixedMath.Sqrt(temp1 + temp2);
 2626    }
 627
 628    /// <summary>
 629    /// Returns the distance between this vector and another vector.
 630    /// </summary>
 631    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 632    public Fixed64 Distance(Vector2d other)
 2633    {
 2634        return Distance(other.x, other.y);
 2635    }
 636
 637    /// <summary>
 638    /// Calculates the squared distance between two vectors, avoiding the need for a square root operation.
 639    /// </summary>
 640    /// <returns>The squared distance between the two vectors.</returns>
 641    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 642    public Fixed64 SqrDistance(Fixed64 otherX, Fixed64 otherY)
 3643    {
 3644        Fixed64 temp1 = x - otherX;
 3645        temp1 *= temp1;
 3646        Fixed64 temp2 = y - otherY;
 3647        temp2 *= temp2;
 3648        return temp1 + temp2;
 3649    }
 650
 651    /// <summary>
 652    /// Calculates the squared distance between two vectors, avoiding the need for a square root operation.
 653    /// </summary>
 654    /// <returns>The squared distance between the two vectors.</returns>
 655    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 656    public Fixed64 SqrDistance(Vector2d other)
 3657    {
 3658        return SqrDistance(other.x, other.y);
 3659    }
 660
 661    #endregion
 662
 663    #region Vector2d Operations
 664
 665    /// <summary>
 666    /// Normalizes the given vector, returning a unit vector with the same direction.
 667    /// </summary>
 668    /// <param name="value">The vector to normalize.</param>
 669    /// <returns>A normalized (unit) vector with the same direction.</returns>
 670    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 671    public static Vector2d GetNormalized(Vector2d value)
 5672    {
 5673        Fixed64 mag = GetMagnitude(value);
 674
 5675        if (mag == Fixed64.Zero)
 1676            return new Vector2d(Fixed64.Zero, Fixed64.Zero);
 677
 678        // If already normalized, return as-is
 4679        if (FixedMath.Abs(mag - Fixed64.One) <= Fixed64.Epsilon)
 1680            return value;
 681
 682        // Normalize it exactly
 3683        return new Vector2d(
 3684            value.x / mag,
 3685            value.y / mag
 3686        );
 5687    }
 688
 689    /// <summary>
 690    /// Returns the magnitude (length) of the given vector.
 691    /// </summary>
 692    /// <param name="vector">The vector to compute the magnitude of.</param>
 693    /// <returns>The magnitude (length) of the vector.</returns>
 694    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 695    public static Fixed64 GetMagnitude(Vector2d vector)
 24696    {
 24697        Fixed64 mag = (vector.x * vector.x) + (vector.y * vector.y);
 698
 699        // If rounding error pushed magnitude slightly above 1, clamp it
 24700        if (mag > Fixed64.One && mag <= Fixed64.One + Fixed64.Epsilon)
 3701            return Fixed64.One;
 702
 21703        return mag.Abs() > Fixed64.Zero ? FixedMath.Sqrt(mag) : Fixed64.Zero;
 24704    }
 705
 706    /// <summary>
 707    /// Returns a new <see cref="Vector2d"/> where each component is the absolute value of the corresponding input compo
 708    /// </summary>
 709    /// <param name="value">The input vector.</param>
 710    /// <returns>A vector with absolute values for each component.</returns>
 711    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 712    public static Vector2d Abs(Vector2d value)
 1713    {
 1714        return new Vector2d(value.x.Abs(), value.y.Abs());
 1715    }
 716
 717    /// <summary>
 718    /// Returns a new <see cref="Vector2d"/> where each component is the sign of the corresponding input component.
 719    /// </summary>
 720    /// <param name="value">The input vector.</param>
 721    /// <returns>A vector where each component is -1, 0, or 1 based on the sign of the input.</returns>
 722    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 723    public static Vector2d Sign(Vector2d value)
 1724    {
 1725        return new Vector2d(value.x.Sign(), value.y.Sign());
 1726    }
 727
 728    /// <summary>
 729    /// Creates a vector from a given angle in radians.
 730    /// </summary>
 731    public static Vector2d CreateRotation(Fixed64 angle)
 1732    {
 1733        return new Vector2d(FixedMath.Cos(angle), FixedMath.Sin(angle));
 1734    }
 735
 736    /// <summary>
 737    /// Computes the distance between two vectors using the Euclidean distance formula.
 738    /// </summary>
 739    /// <param name="start">The starting vector.</param>
 740    /// <param name="end">The ending vector.</param>
 741    /// <returns>The Euclidean distance between the two vectors.</returns>
 742    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 743    public static Fixed64 Distance(Vector2d start, Vector2d end)
 1744    {
 1745        return start.Distance(end);
 1746    }
 747
 748    /// <summary>
 749    /// Calculates the squared distance between two vectors, avoiding the need for a square root operation.
 750    /// </summary>
 751    /// <returns>The squared distance between the two vectors.</returns>
 752    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 753    public static Fixed64 SqrDistance(Vector2d start, Vector2d end)
 1754    {
 1755        return start.SqrDistance(end);
 1756    }
 757
 758    /// <summary>
 759    /// Calculates the forward direction vector in 2D based on a yaw (angle).
 760    /// </summary>
 761    /// <param name="angle">The angle in radians representing the rotation in 2D space.</param>
 762    /// <returns>A unit vector representing the forward direction.</returns>
 763    public static Vector2d ForwardDirection(Fixed64 angle)
 1764    {
 1765        Fixed64 x = FixedMath.Cos(angle); // Forward in the x-direction
 1766        Fixed64 y = FixedMath.Sin(angle); // Forward in the y-direction
 1767        return new Vector2d(x, y);
 1768    }
 769
 770    /// <summary>
 771    /// Dot Product of two vectors.
 772    /// </summary>
 773    /// <param name="lhs"></param>
 774    /// <param name="rhs"></param>
 775    /// <returns></returns>
 776    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 777    public static Fixed64 Dot(Vector2d lhs, Vector2d rhs)
 1778    {
 1779        return lhs.Dot(rhs.x, rhs.y);
 1780    }
 781
 782    /// <summary>
 783    /// Multiplies two vectors component-wise.
 784    /// </summary>
 785    /// <param name="a"></param>
 786    /// <param name="b"></param>
 787    /// <returns></returns>
 788    public static Vector2d Scale(Vector2d a, Vector2d b)
 1789    {
 1790        return new Vector2d(a.x * b.x, a.y * b.y);
 1791    }
 792
 793    /// <summary>
 794    /// Cross Product of two vectors.
 795    /// </summary>
 796    /// <param name="lhs"></param>
 797    /// <param name="rhs"></param>
 798    /// <returns></returns>
 799    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 800    public static Fixed64 CrossProduct(Vector2d lhs, Vector2d rhs)
 0801    {
 0802        return lhs.CrossProduct(rhs);
 0803    }
 804
 805    /// <summary>
 806    /// Rotates this vector by the specified angle (in radians).
 807    /// </summary>
 808    /// <param name="vec">The vector to rotate.</param>
 809    /// <param name="angleInRadians">The angle in radians.</param>
 810    /// <returns>The rotated vector.</returns>
 811    public static Vector2d Rotate(Vector2d vec, Fixed64 angleInRadians)
 1812    {
 1813        Fixed64 cos = FixedMath.Cos(angleInRadians);
 1814        Fixed64 sin = FixedMath.Sin(angleInRadians);
 1815        return new Vector2d(
 1816            vec.x * cos - vec.y * sin,
 1817            vec.x * sin + vec.y * cos
 1818        );
 1819    }
 820
 821    #endregion
 822
 823    #region Conversion
 824
 825    /// <summary>
 826    /// Returns a string that represents the current object, displaying the x and y values rounded to two decimal places
 827    /// </summary>
 828    /// <returns>A string in the format "(x, y)", where x and y are the values of the object rounded to two decimal plac
 829    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 830    public override string ToString()
 27831    {
 27832        return $"({Math.Round((double)x, 2)}, {Math.Round((double)y, 2)})";
 27833    }
 834
 835    /// <summary>
 836    /// Converts this <see cref="Vector2d"/> to a <see cref="Vector3d"/>,
 837    /// mapping the Y component of this vector to the Z axis in the resulting vector.
 838    /// </summary>
 839    /// <param name="z">The value to assign to the Y axis of the resulting <see cref="Vector3d"/>.</param>
 840    /// <returns>
 841    /// A new <see cref="Vector3d"/> where (X, Y) from this <see cref="Vector2d"/>
 842    /// become (X, Z) in the resulting vector, with the provided Z parameter assigned to Y.
 843    /// </returns>
 844    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 845    public readonly Vector3d ToVector3d(Fixed64 z)
 1846    {
 1847        return new Vector3d(x, z, y);
 1848    }
 849
 850    /// <summary>
 851    /// Converts this <see cref="Vector2d"/> to a <see cref="Vector4d"/> with explicit Z and W components.
 852    /// </summary>
 853    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 854    public readonly Vector4d ToVector4d(Fixed64 z, Fixed64 w)
 1855    {
 1856        return new Vector4d(x, y, z, w);
 1857    }
 858
 859    /// <summary>
 860    /// Deconstructs the current instance into its X and Y coordinate values as single-precision floating-point numbers.
 861    /// </summary>
 862    /// <remarks>
 863    /// This method enables deconstruction syntax, allowing the instance to be unpacked into separate
 864    /// X and Y values using tuple deconstruction in client code.
 865    /// </remarks>
 866    /// <param name="x">When this method returns, contains the X coordinate value as a single-precision floating-point n
 867    /// <param name="y">When this method returns, contains the Y coordinate value as a single-precision floating-point n
 868    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 869    public readonly void Deconstruct(out float x, out float y)
 1870    {
 1871        x = this.x.ToPreciseFloat();
 1872        y = this.y.ToPreciseFloat();
 1873    }
 874
 875    /// <summary>
 876    /// Deconstructs the current instance into its X and Y components, rounding each value to the nearest integer.
 877    /// </summary>
 878    /// <remarks>
 879    /// This method enables deconstruction syntax, allowing the instance to be unpacked into two
 880    /// integer variables representing the rounded X and Y values.
 881    /// </remarks>
 882    /// <param name="x">When this method returns, contains the X component of the instance, rounded to the nearest integ
 883    /// <param name="y">When this method returns, contains the Y component of the instance, rounded to the nearest integ
 884    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 885    public readonly void Deconstruct(out int x, out int y)
 1886    {
 1887        x = this.x.RoundToInt();
 1888        y = this.y.RoundToInt();
 1889    }
 890
 891    /// <summary>
 892    /// Converts each component of the vector from radians to degrees.
 893    /// </summary>
 894    /// <param name="radians">The vector with components in radians.</param>
 895    /// <returns>A new vector with components converted to degrees.</returns>
 896    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 897    public static Vector2d ToDegrees(Vector2d radians)
 1898    {
 1899        return new Vector2d(
 1900            FixedMath.RadToDeg(radians.x),
 1901            FixedMath.RadToDeg(radians.y)
 1902        );
 1903    }
 904
 905    /// <summary>
 906    /// Converts each component of the vector from degrees to radians.
 907    /// </summary>
 908    /// <param name="degrees">The vector with components in degrees.</param>
 909    /// <returns>A new vector with components converted to radians.</returns>
 910    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 911    public static Vector2d ToRadians(Vector2d degrees)
 1912    {
 1913        return new Vector2d(
 1914            FixedMath.DegToRad(degrees.x),
 1915            FixedMath.DegToRad(degrees.y)
 1916        );
 1917    }
 918
 919    #endregion
 920
 921    #region Operators
 922
 923    /// <summary>
 924    /// Adds two Vector2d instances component-wise.
 925    /// </summary>
 926    /// <param name="v1">The first vector to add.</param>
 927    /// <param name="v2">The second vector to add.</param>
 928    /// <returns>A new Vector2d whose components are the sums of the corresponding components of v1 and v2.</returns>
 929    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 930    public static Vector2d operator +(Vector2d v1, Vector2d v2)
 1931    {
 1932        return new Vector2d(v1.x + v2.x, v1.y + v2.y);
 1933    }
 934
 935    /// <summary>
 936    /// Adds a scalar value to each component of the specified vector and returns the resulting vector.
 937    /// </summary>
 938    /// <param name="v1">The vector to which the scalar value will be added.</param>
 939    /// <param name="mag">The scalar value to add to each component of the vector.</param>
 940    /// <returns>A new Vector2d whose components are the sum of the corresponding components of the input vector and the
 941    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 942    public static Vector2d operator +(Vector2d v1, Fixed64 mag)
 2943    {
 2944        return new Vector2d(v1.x + mag, v1.y + mag);
 2945    }
 946
 947    /// <inheritdoc cref="operator +(Vector2d, Fixed64)"/>
 948    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 949    public static Vector2d operator +(Fixed64 mag, Vector2d v1)
 1950    {
 1951        return v1 + mag;
 1952    }
 953
 954    /// <summary>
 955    /// Adds a Vector2d instance and a tuple representing X and Y components, returning a new Vector2d with the summed
 956    /// values.
 957    /// </summary>
 958    /// <param name="v1">The first vector to add.</param>
 959    /// <param name="v2">A tuple containing the X and Y values to add to the vector.</param>
 960    /// <returns>A new Vector2d whose X and Y components are the sums of the corresponding components of the input vecto
 961    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 962    public static Vector2d operator +(Vector2d v1, (int x, int y) v2)
 2963    {
 2964        return new Vector2d(v1.x + v2.x, v1.y + v2.y);
 2965    }
 966
 967    /// <summary>
 968    /// Adds a tuple representing X and Y components and a Vector2d instance, returning a new Vector2d with the summed
 969    /// values.
 970    /// </summary>
 971    /// <param name="v2">A tuple containing the X and Y values to add to the vector.</param>
 972    /// <param name="v1">The vector to add.</param>
 973    /// <returns>A new Vector2d whose X and Y components are the sums of the corresponding components of the tuple and i
 974    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 975    public static Vector2d operator +((int x, int y) v2, Vector2d v1)
 1976    {
 1977        return v1 + v2;
 1978    }
 979
 980    /// <summary>
 981    /// Subtracts the components of one Vector2d from another and returns the resulting vector.
 982    /// </summary>
 983    /// <param name="v1">The vector to subtract from.</param>
 984    /// <param name="v2">The vector to subtract.</param>
 985    /// <returns>A Vector2d whose components are the result of subtracting the corresponding components of v2 from v1.</
 986    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 987    public static Vector2d operator -(Vector2d v1, Vector2d v2)
 5988    {
 5989        return new Vector2d(v1.x - v2.x, v1.y - v2.y);
 5990    }
 991
 992    /// <summary>
 993    /// Subtracts the specified scalar value from both components of the given vector and returns the resulting vector.
 994    /// </summary>
 995    /// <param name="v1">The vector from which to subtract the scalar value.</param>
 996    /// <param name="mag">The scalar value to subtract from each component of the vector.</param>
 997    /// <returns>A new Vector2d whose components are the result of subtracting the scalar value from the corresponding c
 998    /// of the input vector.</returns>
 999    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1000    public static Vector2d operator -(Vector2d v1, Fixed64 mag)
 11001    {
 11002        return new Vector2d(v1.x - mag, v1.y - mag);
 11003    }
 1004
 1005    /// <inheritdoc cref="operator -(Vector2d, Fixed64)"/>
 1006    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1007    public static Vector2d operator -(Fixed64 mag, Vector2d v1)
 11008    {
 11009        return new Vector2d(mag - v1.x, mag - v1.y);
 11010    }
 1011
 1012    /// <summary>
 1013    /// Subtracts the specified tuple from the given vector and returns the resulting vector.
 1014    /// </summary>
 1015    /// <param name="v1">The vector from which to subtract the tuple values.</param>
 1016    /// <param name="v2">A tuple containing the x and y values to subtract from the vector.</param>
 1017    /// <returns>A new Vector2d representing the result of subtracting the tuple values from the original vector.</retur
 1018    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1019    public static Vector2d operator -(Vector2d v1, (int x, int y) v2)
 11020    {
 11021        return new Vector2d(v1.x - v2.x, v1.y - v2.y);
 11022    }
 1023
 1024    /// <summary>
 1025    /// Subtracts the specified Vector2d from the given integer tuple and returns the resulting vector.
 1026    /// </summary>
 1027    /// <param name="v1">A tuple containing the x and y components to subtract from.</param>
 1028    /// <param name="v2">The vector whose components are subtracted from the tuple.</param>
 1029    /// <returns>A Vector2d representing the result of subtracting the components of v2 from v1.</returns>
 1030    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1031    public static Vector2d operator -((int x, int y) v1, Vector2d v2)
 11032    {
 11033        return new Vector2d(v1.x - v2.x, v1.y - v2.y);
 11034    }
 1035
 1036    /// <summary>
 1037    /// Negates the specified vector by reversing the sign of each of its components.
 1038    /// </summary>
 1039    /// <param name="v1">The vector to negate.</param>
 1040    /// <returns>A new Vector2d whose components are the negated values of the input vector.</returns>
 1041    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1042    public static Vector2d operator -(Vector2d v1)
 11043    {
 11044        return new Vector2d(v1.x * -Fixed64.One, v1.y * -Fixed64.One);
 11045    }
 1046
 1047    /// <summary>
 1048    /// Scales the specified vector by the given scalar value.
 1049    /// </summary>
 1050    /// <param name="v1">The vector to be scaled.</param>
 1051    /// <param name="mag">The scalar value by which to multiply each component of the vector.</param>
 1052    /// <returns>A new Vector2d whose components are the components of v1 multiplied by mag.</returns>
 1053    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1054    public static Vector2d operator *(Vector2d v1, Fixed64 mag)
 11055    {
 11056        return new Vector2d(v1.x * mag, v1.y * mag);
 11057    }
 1058
 1059    /// <summary>
 1060    /// Multiplies two vectors element-wise and returns the resulting vector.
 1061    /// </summary>
 1062    /// <remarks>Element-wise multiplication multiplies each component of the first vector by the
 1063    /// corresponding component of the second vector. This operation is not a dot product or cross product.</remarks>
 1064    /// <param name="v1">The first vector to multiply.</param>
 1065    /// <param name="v2">The second vector to multiply.</param>
 1066    /// <returns>A new Vector2d whose components are the products of the corresponding components of the input vectors.<
 1067    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1068    public static Vector2d operator *(Vector2d v1, Vector2d v2)
 11069    {
 11070        return new Vector2d(v1.x * v2.x, v1.y * v2.y);
 11071    }
 1072
 1073    /// <summary>
 1074    /// Divides each component of a specified vector by a scalar value.
 1075    /// </summary>
 1076    /// <param name="v1">The vector whose components are to be divided.</param>
 1077    /// <param name="div">The scalar value by which to divide each component of the vector.</param>
 1078    /// <returns>A new Vector2d whose components are the result of dividing the corresponding components of v1 by div.</
 1079    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1080    public static Vector2d operator /(Vector2d v1, Fixed64 div)
 11081    {
 11082        return new Vector2d(v1.x / div, v1.y / div);
 11083    }
 1084
 1085    /// <summary>
 1086    /// Determines whether two Vector2d instances are equal.
 1087    /// </summary>
 1088    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 11089    public static bool operator ==(Vector2d left, Vector2d right) => left.Equals(right);
 1090
 1091    /// <summary>
 1092    /// Determines whether two Vector2d instances are not equal.
 1093    /// </summary>
 1094    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 11095    public static bool operator !=(Vector2d left, Vector2d right) => !left.Equals(right);
 1096
 1097    #endregion
 1098
 1099    #region Equality, HashCode, and Comparable Overrides
 1100
 1101    /// <summary>
 1102    /// Are all components of this vector equal to zero?
 1103    /// </summary>
 1104    /// <returns></returns>
 1105    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 21106    public bool EqualsZero() => this.Equals(Zero);
 1107
 1108    /// <summary>
 1109    /// Determines whether the current value is not equal to zero.
 1110    /// </summary>
 1111    /// <returns>true if the value is not zero; otherwise, false.</returns>
 1112    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 11113    public bool NotZero() => !EqualsZero();
 1114
 1115    /// <summary>
 1116    /// Checks whether all components are strictly greater than <see cref="Fixed64.Epsilon"/>.
 1117    /// </summary>
 1118    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1119    public bool AllComponentsGreaterThanEpsilon()
 21120    {
 21121        return x.Abs() > Fixed64.Epsilon && y.Abs() > Fixed64.Epsilon;
 21122    }
 1123
 1124    /// <inheritdoc/>
 1125    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 51126    public override bool Equals(object? obj) => obj is Vector2d other && Equals(other);
 1127
 1128    /// <inheritdoc/>
 1129    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 681130    public bool Equals(Vector2d other) => other.x == x && other.y == y;
 1131
 1132    /// <inheritdoc/>
 21133    public bool Equals(Vector2d x, Vector2d y) => x.Equals(y);
 1134
 1135    /// <inheritdoc/>
 1136    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 31137    public override int GetHashCode() => StateHash;
 1138
 1139    /// <inheritdoc/>
 1140    public int GetHashCode(Vector2d obj)
 11141    {
 11142        return obj.GetHashCode();
 11143    }
 1144
 1145    /// <summary>
 1146    /// Compares the current Vector2d instance with another Vector2d based on their squared magnitudes.
 1147    /// </summary>
 1148    /// <remarks>
 1149    /// This comparison uses the squared magnitude of each vector, which avoids the computational
 1150    /// cost of calculating the actual magnitude.
 1151    /// Use this method when only relative vector lengths are
 1152    /// important.
 1153    /// </remarks>
 1154    /// <param name="other">The Vector2d instance to compare with the current instance.</param>
 1155    /// <returns>A value less than zero if this instance is less than <paramref name="other"/>; zero if this instance is
 1156    /// <paramref name="other"/>; or a value greater than zero if this instance is greater than <paramref
 1157    /// name="other"/>, as determined by their squared magnitudes.</returns>
 11158    public int CompareTo(Vector2d other) => SqrMagnitude.CompareTo(other.SqrMagnitude);
 1159
 1160    #endregion
 1161}

Methods/Properties

.ctor(System.Int32,System.Int32)
.ctor(System.Double,System.Double)
.ctor(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
get_RotatedRight()
get_RotatedLeft()
get_RightHandNormal()
get_LeftHandNormal()
get_Normal()
get_Magnitude()
get_SqrMagnitude()
get_LongStateHash()
get_StateHash()
get_Item(System.Int32)
set_Item(System.Int32,FixedMathSharp.Fixed64)
Set(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Vector2d)
SubtractInPlace(FixedMathSharp.Fixed64)
SubtractInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
SubtractInPlace(FixedMathSharp.Vector2d)
ScaleInPlace(FixedMathSharp.Fixed64)
ScaleInPlace(FixedMathSharp.Vector2d)
Normalize()
Normalize(FixedMathSharp.Fixed64&)
LerpInPlace(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
LerpInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Lerp(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
Lerped(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
RotateInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Rotated(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Rotated(FixedMathSharp.Vector2d)
RotateInverse(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
RotateRightInPlace()
RotateLeftInPlace()
ReflectInPlace(FixedMathSharp.Vector2d)
ReflectInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
ReflectInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Reflected(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Reflected(FixedMathSharp.Vector2d)
Dot(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Dot(FixedMathSharp.Vector2d)
CrossProduct(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
CrossProduct(FixedMathSharp.Vector2d)
Distance(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Distance(FixedMathSharp.Vector2d)
SqrDistance(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
SqrDistance(FixedMathSharp.Vector2d)
GetNormalized(FixedMathSharp.Vector2d)
GetMagnitude(FixedMathSharp.Vector2d)
Abs(FixedMathSharp.Vector2d)
Sign(FixedMathSharp.Vector2d)
CreateRotation(FixedMathSharp.Fixed64)
Distance(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
SqrDistance(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
ForwardDirection(FixedMathSharp.Fixed64)
Dot(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
Scale(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
CrossProduct(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
Rotate(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
ToString()
ToVector3d(FixedMathSharp.Fixed64)
ToVector4d(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Deconstruct(System.Single&,System.Single&)
Deconstruct(System.Int32&,System.Int32&)
ToDegrees(FixedMathSharp.Vector2d)
ToRadians(FixedMathSharp.Vector2d)
op_Addition(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
op_Addition(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
op_Addition(FixedMathSharp.Fixed64,FixedMathSharp.Vector2d)
op_Addition(FixedMathSharp.Vector2d,System.ValueTuple`2<System.Int32,System.Int32>)
op_Addition(System.ValueTuple`2<System.Int32,System.Int32>,FixedMathSharp.Vector2d)
op_Subtraction(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
op_Subtraction(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
op_Subtraction(FixedMathSharp.Fixed64,FixedMathSharp.Vector2d)
op_Subtraction(FixedMathSharp.Vector2d,System.ValueTuple`2<System.Int32,System.Int32>)
op_Subtraction(System.ValueTuple`2<System.Int32,System.Int32>,FixedMathSharp.Vector2d)
op_UnaryNegation(FixedMathSharp.Vector2d)
op_Multiply(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
op_Multiply(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
op_Division(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64)
op_Equality(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
op_Inequality(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
EqualsZero()
NotZero()
AllComponentsGreaterThanEpsilon()
Equals(System.Object)
Equals(FixedMathSharp.Vector2d)
Equals(FixedMathSharp.Vector2d,FixedMathSharp.Vector2d)
GetHashCode()
GetHashCode(FixedMathSharp.Vector2d)
CompareTo(FixedMathSharp.Vector2d)