< Summary

Information
Class: FixedMathSharp.Vector4d
Assembly: FixedMathSharp
File(s): /home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector4d.cs
Line coverage
100%
Covered lines: 338
Uncovered lines: 0
Coverable lines: 338
Total lines: 973
Line coverage: 100%
Branch coverage
100%
Covered branches: 72
Total branches: 72
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%
.ctor(...)100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_Normal()100%11100%
get_Magnitude()100%11100%
get_SqrMagnitude()100%11100%
get_LongStateHash()100%11100%
get_StateHash()100%11100%
get_IsZero()100%11100%
get_Item(...)100%55100%
set_Item(...)100%55100%
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%
IsNormalized()100%22100%
AllComponentsGreaterThanEpsilon()100%66100%
SnapSmallComponentsToZero(...)100%1010100%
Distance(...)100%11100%
Distance(...)100%11100%
SqrDistance(...)100%11100%
SqrDistance(...)100%11100%
Dot(...)100%11100%
Dot(...)100%11100%
ToVector3d()100%11100%
Lerp(...)100%11100%
UnclampedLerp(...)100%11100%
GetNormalized(...)100%44100%
GetMagnitude(...)100%44100%
Abs(...)100%11100%
Sign(...)100%11100%
Clamp(...)100%11100%
Midpoint(...)100%11100%
Distance(...)100%11100%
SqrDistance(...)100%11100%
Dot(...)100%11100%
Scale(...)100%11100%
Max(...)100%11100%
Min(...)100%11100%
Transform(...)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_Multiply(...)100%11100%
op_Multiply(...)100%11100%
op_Multiply(...)100%11100%
op_Multiply(...)100%11100%
op_Multiply(...)100%11100%
op_Division(...)100%11100%
op_Division(...)100%11100%
op_Division(...)100%11100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
op_GreaterThan(...)100%66100%
op_LessThan(...)100%66100%
op_GreaterThanOrEqual(...)100%66100%
op_LessThanOrEqual(...)100%66100%
ToString()100%11100%
Deconstruct(...)100%11100%
Deconstruct(...)100%11100%
Equals(...)100%22100%
Equals(...)100%66100%
Equals(...)100%11100%
GetHashCode()100%11100%
GetHashCode(...)100%11100%
CompareTo(...)100%11100%

File(s)

/home/runner/work/FixedMathSharp/FixedMathSharp/src/FixedMathSharp/Numerics/Vectors/Vector4d.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 4D vector with fixed-point precision.
 11/// </summary>
 12/// <remarks>
 13/// This type is useful for generic 4D component math and homogeneous coordinates used by 4x4 transforms.
 14/// </remarks>
 15[Serializable]
 16[MemoryPackable]
 17public partial struct Vector4d : IEquatable<Vector4d>, IComparable<Vector4d>, IEqualityComparer<Vector4d>
 18{
 19    #region Static Readonly Fields
 20
 21    /// <summary>
 22    /// (1, 0, 0, 0)
 23    /// </summary>
 24    public static readonly Vector4d UnitX = new(1, 0, 0, 0);
 25
 26    /// <summary>
 27    /// (0, 1, 0, 0)
 28    /// </summary>
 29    public static readonly Vector4d UnitY = new(0, 1, 0, 0);
 30
 31    /// <summary>
 32    /// (0, 0, 1, 0)
 33    /// </summary>
 34    public static readonly Vector4d UnitZ = new(0, 0, 1, 0);
 35
 36    /// <summary>
 37    /// (0, 0, 0, 1)
 38    /// </summary>
 39    public static readonly Vector4d UnitW = new(0, 0, 0, 1);
 40
 41    /// <summary>
 42    /// (1, 1, 1, 1)
 43    /// </summary>
 44    public static readonly Vector4d One = new(1, 1, 1, 1);
 45
 46    /// <summary>
 47    /// (-1, -1, -1, -1)
 48    /// </summary>
 49    public static readonly Vector4d Negative = new(-1, -1, -1, -1);
 50
 51    /// <summary>
 52    /// (0, 0, 0, 0)
 53    /// </summary>
 54    public static readonly Vector4d Zero = new(0, 0, 0, 0);
 55
 56    #endregion
 57
 58    #region Fields
 59
 60    /// <summary>
 61    /// The X component of the vector.
 62    /// </summary>
 63    [JsonInclude]
 64    [MemoryPackOrder(0)]
 65    public Fixed64 x;
 66
 67    /// <summary>
 68    /// The Y component of the vector.
 69    /// </summary>
 70    [JsonInclude]
 71    [MemoryPackOrder(1)]
 72    public Fixed64 y;
 73
 74    /// <summary>
 75    /// The Z component of the vector.
 76    /// </summary>
 77    [JsonInclude]
 78    [MemoryPackOrder(2)]
 79    public Fixed64 z;
 80
 81    /// <summary>
 82    /// The W component of the vector.
 83    /// </summary>
 84    [JsonInclude]
 85    [MemoryPackOrder(3)]
 86    public Fixed64 w;
 87
 88    #endregion
 89
 90    #region Constructors
 91
 92    /// <summary>
 93    /// Initializes a new Vector4d using integer component values.
 94    /// </summary>
 95    public Vector4d(int xInt, int yInt, int zInt, int wInt)
 39396        : this((Fixed64)xInt, (Fixed64)yInt, (Fixed64)zInt, (Fixed64)wInt) { }
 97
 98    /// <summary>
 99    /// Initializes a new Vector4d using double component values.
 100    /// </summary>
 101    public Vector4d(double xDoub, double yDoub, double zDoub, double wDoub)
 18102        : this((Fixed64)xDoub, (Fixed64)yDoub, (Fixed64)zDoub, (Fixed64)wDoub) { }
 103
 104    /// <summary>
 105    /// Initializes a new Vector4d using the specified components.
 106    /// </summary>
 107    [JsonConstructor]
 108    public Vector4d(Fixed64 x, Fixed64 y, Fixed64 z, Fixed64 w)
 200109    {
 200110        this.x = x;
 200111        this.y = y;
 200112        this.z = z;
 200113        this.w = w;
 200114    }
 115
 116    /// <summary>
 117    /// Initializes a new Vector4d with all components set to the same value.
 118    /// </summary>
 119    public Vector4d(Fixed64 value)
 3120        : this(value, value, value, value) { }
 121
 122    /// <summary>
 123    /// Initializes a new Vector4d from a Vector2d plus Z and W components.
 124    /// </summary>
 125    public Vector4d(Vector2d value, Fixed64 z, Fixed64 w)
 3126        : this(value.x, value.y, z, w) { }
 127
 128    /// <summary>
 129    /// Initializes a new Vector4d from a Vector3d plus a W component.
 130    /// </summary>
 131    public Vector4d(Vector3d value, Fixed64 w)
 3132        : this(value.x, value.y, value.z, w) { }
 133
 134    #endregion
 135
 136    #region Properties
 137
 138    /// <inheritdoc cref="GetNormalized(Vector4d)"/>
 139    [JsonIgnore]
 140    [MemoryPackIgnore]
 141    public readonly Vector4d Normal
 142    {
 143        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1144        get => GetNormalized(this);
 145    }
 146
 147    /// <summary>
 148    /// Returns the actual length of this vector.
 149    /// </summary>
 150    [JsonIgnore]
 151    [MemoryPackIgnore]
 152    public readonly Fixed64 Magnitude
 153    {
 154        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 3155        get => GetMagnitude(this);
 156    }
 157
 158    /// <summary>
 159    /// Returns the square magnitude of the vector.
 160    /// </summary>
 161    [JsonIgnore]
 162    [MemoryPackIgnore]
 163    public readonly Fixed64 SqrMagnitude
 164    {
 165        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5166        get => (x * x) + (y * y) + (z * z) + (w * w);
 167    }
 168
 169    /// <summary>
 170    /// Returns a long hash of the vector based on its component values.
 171    /// </summary>
 172    [JsonIgnore]
 173    [MemoryPackIgnore]
 174    public readonly long LongStateHash
 175    {
 176        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 177        get
 6178        {
 179            unchecked
 6180            {
 6181                return (x.m_rawValue * 31) + (y.m_rawValue * 7) + (z.m_rawValue * 11) + (w.m_rawValue * 17);
 182            }
 6183        }
 184    }
 185
 186    /// <summary>
 187    /// Returns a hash of the vector based on its state.
 188    /// </summary>
 189    [JsonIgnore]
 190    [MemoryPackIgnore]
 191    public readonly int StateHash
 192    {
 193        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 4194        get => unchecked((int)(LongStateHash % int.MaxValue));
 195    }
 196
 197    /// <summary>
 198    /// Are all components of this vector equal to zero?
 199    /// </summary>
 200    [JsonIgnore]
 201    [MemoryPackIgnore]
 202    public readonly bool IsZero
 203    {
 204        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 5205        get => Equals(Zero);
 206    }
 207
 208    /// <summary>
 209    /// Gets or sets the vector component at the specified index.
 210    /// </summary>
 211    [JsonIgnore]
 212    [MemoryPackIgnore]
 213    public Fixed64 this[int index]
 214    {
 215        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 216        readonly get
 10217        {
 10218            return index switch
 10219            {
 2220                0 => x,
 2221                1 => y,
 2222                2 => z,
 2223                3 => w,
 2224                _ => throw new IndexOutOfRangeException("Invalid Vector4d index!"),
 10225            };
 8226        }
 227        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 228        set
 34229        {
 34230            switch (index)
 231            {
 232                case 0:
 8233                    x = value;
 8234                    break;
 235                case 1:
 8236                    y = value;
 8237                    break;
 238                case 2:
 8239                    z = value;
 8240                    break;
 241                case 3:
 8242                    w = value;
 8243                    break;
 244                default:
 2245                    throw new IndexOutOfRangeException("Invalid Vector4d index!");
 246            }
 32247        }
 248    }
 249
 250    #endregion
 251
 252    #region Instance Methods
 253
 254    /// <summary>
 255    /// Sets the vector components in place and returns the modified vector.
 256    /// </summary>
 257    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 258    public Vector4d Set(Fixed64 newX, Fixed64 newY, Fixed64 newZ, Fixed64 newW)
 1259    {
 1260        x = newX;
 1261        y = newY;
 1262        z = newZ;
 1263        w = newW;
 1264        return this;
 1265    }
 266
 267    /// <summary>
 268    /// Adds the specified scalar to all components in place.
 269    /// </summary>
 270    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 271    public Vector4d AddInPlace(Fixed64 amount)
 1272    {
 1273        x += amount;
 1274        y += amount;
 1275        z += amount;
 1276        w += amount;
 1277        return this;
 1278    }
 279
 280    /// <summary>
 281    /// Adds the specified component values in place.
 282    /// </summary>
 283    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 284    public Vector4d AddInPlace(Fixed64 xAmount, Fixed64 yAmount, Fixed64 zAmount, Fixed64 wAmount)
 1285    {
 1286        x += xAmount;
 1287        y += yAmount;
 1288        z += zAmount;
 1289        w += wAmount;
 1290        return this;
 1291    }
 292
 293    /// <summary>
 294    /// Adds another vector in place.
 295    /// </summary>
 296    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 297    public Vector4d AddInPlace(Vector4d other)
 1298    {
 1299        x += other.x;
 1300        y += other.y;
 1301        z += other.z;
 1302        w += other.w;
 1303        return this;
 1304    }
 305
 306    /// <summary>
 307    /// Subtracts the specified scalar from all components in place.
 308    /// </summary>
 309    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 310    public Vector4d SubtractInPlace(Fixed64 amount)
 1311    {
 1312        x -= amount;
 1313        y -= amount;
 1314        z -= amount;
 1315        w -= amount;
 1316        return this;
 1317    }
 318
 319    /// <summary>
 320    /// Subtracts the specified component values in place.
 321    /// </summary>
 322    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 323    public Vector4d SubtractInPlace(Fixed64 xAmount, Fixed64 yAmount, Fixed64 zAmount, Fixed64 wAmount)
 1324    {
 1325        x -= xAmount;
 1326        y -= yAmount;
 1327        z -= zAmount;
 1328        w -= wAmount;
 1329        return this;
 1330    }
 331
 332    /// <summary>
 333    /// Subtracts another vector in place.
 334    /// </summary>
 335    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 336    public Vector4d SubtractInPlace(Vector4d other)
 1337    {
 1338        x -= other.x;
 1339        y -= other.y;
 1340        z -= other.z;
 1341        w -= other.w;
 1342        return this;
 1343    }
 344
 345    /// <summary>
 346    /// Scales all components in place.
 347    /// </summary>
 348    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 349    public Vector4d ScaleInPlace(Fixed64 scaleFactor)
 1350    {
 1351        x *= scaleFactor;
 1352        y *= scaleFactor;
 1353        z *= scaleFactor;
 1354        w *= scaleFactor;
 1355        return this;
 1356    }
 357
 358    /// <summary>
 359    /// Scales all components by another vector in place.
 360    /// </summary>
 361    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 362    public Vector4d ScaleInPlace(Vector4d scale)
 1363    {
 1364        x *= scale.x;
 1365        y *= scale.y;
 1366        z *= scale.z;
 1367        w *= scale.w;
 1368        return this;
 1369    }
 370
 371    /// <summary>
 372    /// Normalizes this vector in place.
 373    /// </summary>
 374    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 375    public Vector4d Normalize()
 1376    {
 1377        return this = GetNormalized(this);
 1378    }
 379
 380    /// <summary>
 381    /// Normalizes this vector in place and returns its original magnitude.
 382    /// </summary>
 383    public Vector4d Normalize(out Fixed64 mag)
 3384    {
 3385        mag = GetMagnitude(this);
 386
 3387        if (mag == Fixed64.Zero)
 1388            return this = Zero;
 389
 2390        if (FixedMath.Abs(mag - Fixed64.One) <= Fixed64.Epsilon)
 1391            return this;
 392
 1393        return this = new Vector4d(x / mag, y / mag, z / mag, w / mag);
 3394    }
 395
 396    /// <summary>
 397    /// Determines whether this vector is normalized.
 398    /// </summary>
 399    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 400    public readonly bool IsNormalized()
 3401    {
 3402        return !IsZero && FixedMath.Abs(SqrMagnitude - Fixed64.One) <= Fixed64.Epsilon;
 3403    }
 404
 405    /// <summary>
 406    /// Determines whether all components are greater than Fixed64.Epsilon.
 407    /// </summary>
 408    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 409    public readonly bool AllComponentsGreaterThanEpsilon()
 5410    {
 5411        return x > Fixed64.Epsilon && y > Fixed64.Epsilon && z > Fixed64.Epsilon && w > Fixed64.Epsilon;
 5412    }
 413
 414    /// <summary>
 415    /// Snaps components with absolute values below the threshold to zero.
 416    /// </summary>
 417    public readonly Vector4d SnapSmallComponentsToZero(Fixed64? threshold = null)
 3418    {
 3419        Fixed64 t = threshold ?? Fixed64.Epsilon;
 3420        return new Vector4d(
 3421            FixedMath.Abs(x) < t ? Fixed64.Zero : x,
 3422            FixedMath.Abs(y) < t ? Fixed64.Zero : y,
 3423            FixedMath.Abs(z) < t ? Fixed64.Zero : z,
 3424            FixedMath.Abs(w) < t ? Fixed64.Zero : w);
 3425    }
 426
 427    /// <summary>
 428    /// Calculates the distance to another vector.
 429    /// </summary>
 430    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 431    public readonly Fixed64 Distance(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
 3432    {
 3433        return FixedMath.Sqrt(SqrDistance(otherX, otherY, otherZ, otherW));
 3434    }
 435
 436    /// <summary>
 437    /// Calculates the distance to another vector.
 438    /// </summary>
 439    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 440    public readonly Fixed64 Distance(Vector4d other)
 1441    {
 1442        return Distance(other.x, other.y, other.z, other.w);
 1443    }
 444
 445    /// <summary>
 446    /// Calculates the squared distance to another vector.
 447    /// </summary>
 448    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 449    public readonly Fixed64 SqrDistance(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
 5450    {
 5451        Fixed64 dx = otherX - x;
 5452        Fixed64 dy = otherY - y;
 5453        Fixed64 dz = otherZ - z;
 5454        Fixed64 dw = otherW - w;
 5455        return (dx * dx) + (dy * dy) + (dz * dz) + (dw * dw);
 5456    }
 457
 458    /// <summary>
 459    /// Calculates the squared distance to another vector.
 460    /// </summary>
 461    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 462    public readonly Fixed64 SqrDistance(Vector4d other)
 1463    {
 1464        return SqrDistance(other.x, other.y, other.z, other.w);
 1465    }
 466
 467    /// <summary>
 468    /// Calculates the dot product with another vector.
 469    /// </summary>
 470    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 471    public readonly Fixed64 Dot(Fixed64 otherX, Fixed64 otherY, Fixed64 otherZ, Fixed64 otherW)
 2472    {
 2473        return (x * otherX) + (y * otherY) + (z * otherZ) + (w * otherW);
 2474    }
 475
 476    /// <summary>
 477    /// Calculates the dot product with another vector.
 478    /// </summary>
 479    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 480    public readonly Fixed64 Dot(Vector4d other)
 1481    {
 1482        return Dot(other.x, other.y, other.z, other.w);
 1483    }
 484
 485    /// <summary>
 486    /// Converts this vector to Vector3d by dropping the W component.
 487    /// </summary>
 488    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 489    public readonly Vector3d ToVector3d()
 1490    {
 1491        return new Vector3d(x, y, z);
 1492    }
 493
 494    #endregion
 495
 496    #region Static Methods
 497
 498    /// <summary>
 499    /// Linearly interpolates between two vectors, clamping the interpolation amount to [0, 1].
 500    /// </summary>
 501    public static Vector4d Lerp(Vector4d a, Vector4d b, Fixed64 amount)
 1502    {
 1503        amount = FixedMath.Clamp01(amount);
 1504        return UnclampedLerp(a, b, amount);
 1505    }
 506
 507    /// <summary>
 508    /// Linearly interpolates between two vectors without clamping the interpolation amount.
 509    /// </summary>
 510    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 511    public static Vector4d UnclampedLerp(Vector4d a, Vector4d b, Fixed64 t)
 2512    {
 2513        return new Vector4d(
 2514            a.x + ((b.x - a.x) * t),
 2515            a.y + ((b.y - a.y) * t),
 2516            a.z + ((b.z - a.z) * t),
 2517            a.w + ((b.w - a.w) * t));
 2518    }
 519
 520    /// <summary>
 521    /// Normalizes the given vector, returning a unit vector with the same direction.
 522    /// </summary>
 523    public static Vector4d GetNormalized(Vector4d value)
 4524    {
 4525        Fixed64 mag = GetMagnitude(value);
 526
 4527        if (mag == Fixed64.Zero)
 2528            return Zero;
 529
 2530        if (FixedMath.Abs(mag - Fixed64.One) <= Fixed64.Epsilon)
 1531            return value;
 532
 1533        return new Vector4d(value.x / mag, value.y / mag, value.z / mag, value.w / mag);
 4534    }
 535
 536    /// <summary>
 537    /// Returns the magnitude of the given vector.
 538    /// </summary>
 539    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 540    public static Fixed64 GetMagnitude(Vector4d vector)
 10541    {
 10542        Fixed64 mag = (vector.x * vector.x) + (vector.y * vector.y) + (vector.z * vector.z) + (vector.w * vector.w);
 543
 10544        if (FixedMath.Abs(mag - Fixed64.One) <= Fixed64.Epsilon)
 4545            return Fixed64.One;
 546
 6547        return mag != Fixed64.Zero ? FixedMath.Sqrt(mag) : Fixed64.Zero;
 10548    }
 549
 550    /// <summary>
 551    /// Returns a new vector containing the absolute value of each component.
 552    /// </summary>
 553    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 554    public static Vector4d Abs(Vector4d value)
 2555    {
 2556        return new Vector4d(FixedMath.Abs(value.x), FixedMath.Abs(value.y), FixedMath.Abs(value.z), FixedMath.Abs(value.
 2557    }
 558
 559    /// <summary>
 560    /// Returns a new vector containing the sign of each component.
 561    /// </summary>
 562    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 563    public static Vector4d Sign(Vector4d value)
 2564    {
 2565        return new Vector4d(value.x.Sign(), value.y.Sign(), value.z.Sign(), value.w.Sign());
 2566    }
 567
 568    /// <summary>
 569    /// Clamps each component of the given vector within the specified min and max bounds.
 570    /// </summary>
 571    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 572    public static Vector4d Clamp(Vector4d value, Vector4d min, Vector4d max)
 1573    {
 1574        return new Vector4d(
 1575            FixedMath.Clamp(value.x, min.x, max.x),
 1576            FixedMath.Clamp(value.y, min.y, max.y),
 1577            FixedMath.Clamp(value.z, min.z, max.z),
 1578            FixedMath.Clamp(value.w, min.w, max.w));
 1579    }
 580
 581    /// <summary>
 582    /// Computes the midpoint between two vectors.
 583    /// </summary>
 584    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 585    public static Vector4d Midpoint(Vector4d v1, Vector4d v2)
 1586    {
 1587        return new Vector4d(
 1588            (v1.x + v2.x) * Fixed64.Half,
 1589            (v1.y + v2.y) * Fixed64.Half,
 1590            (v1.z + v2.z) * Fixed64.Half,
 1591            (v1.w + v2.w) * Fixed64.Half);
 1592    }
 593
 594    /// <inheritdoc cref="Distance(Fixed64, Fixed64, Fixed64, Fixed64)" />
 595    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 596    public static Fixed64 Distance(Vector4d start, Vector4d end)
 1597    {
 1598        return start.Distance(end.x, end.y, end.z, end.w);
 1599    }
 600
 601    /// <inheritdoc cref="SqrDistance(Fixed64, Fixed64, Fixed64, Fixed64)" />
 602    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 603    public static Fixed64 SqrDistance(Vector4d start, Vector4d end)
 1604    {
 1605        return start.SqrDistance(end.x, end.y, end.z, end.w);
 1606    }
 607
 608    /// <summary>
 609    /// Calculates the dot product of two vectors.
 610    /// </summary>
 611    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 612    public static Fixed64 Dot(Vector4d lhs, Vector4d rhs)
 1613    {
 1614        return lhs.Dot(rhs.x, rhs.y, rhs.z, rhs.w);
 1615    }
 616
 617    /// <summary>
 618    /// Multiplies two vectors component-wise.
 619    /// </summary>
 620    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 621    public static Vector4d Scale(Vector4d a, Vector4d b)
 2622    {
 2623        return new Vector4d(a.x * b.x, a.y * b.y, a.z * b.z, a.w * b.w);
 2624    }
 625
 626    /// <summary>
 627    /// Returns a vector whose elements are the maximum of each pair of elements.
 628    /// </summary>
 629    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 630    public static Vector4d Max(Vector4d value1, Vector4d value2)
 1631    {
 1632        return new Vector4d(
 1633            FixedMath.Max(value1.x, value2.x),
 1634            FixedMath.Max(value1.y, value2.y),
 1635            FixedMath.Max(value1.z, value2.z),
 1636            FixedMath.Max(value1.w, value2.w));
 1637    }
 638
 639    /// <summary>
 640    /// Returns a vector whose elements are the minimum of each pair of elements.
 641    /// </summary>
 642    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 643    public static Vector4d Min(Vector4d value1, Vector4d value2)
 1644    {
 1645        return new Vector4d(
 1646            FixedMath.Min(value1.x, value2.x),
 1647            FixedMath.Min(value1.y, value2.y),
 1648            FixedMath.Min(value1.z, value2.z),
 1649            FixedMath.Min(value1.w, value2.w));
 1650    }
 651
 652    /// <summary>
 653    /// Transforms a 4D vector by a 4x4 matrix.
 654    /// </summary>
 655    /// <remarks>
 656    /// This follows the same storage convention as <see cref="Fixed4x4.TransformPoint(Fixed4x4, Vector3d)"/>,
 657    /// preserving the computed W component instead of performing perspective division.
 658    /// </remarks>
 659    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 660    public static Vector4d Transform(Fixed4x4 matrix, Vector4d vector)
 8661    {
 8662        return new Vector4d(
 8663            matrix.m00 * vector.x + matrix.m01 * vector.y + matrix.m02 * vector.z + matrix.m30 * vector.w,
 8664            matrix.m10 * vector.x + matrix.m11 * vector.y + matrix.m12 * vector.z + matrix.m31 * vector.w,
 8665            matrix.m20 * vector.x + matrix.m21 * vector.y + matrix.m22 * vector.z + matrix.m32 * vector.w,
 8666            matrix.m03 * vector.x + matrix.m13 * vector.y + matrix.m23 * vector.z + matrix.m33 * vector.w);
 8667    }
 668
 669    #endregion
 670
 671    #region Operators
 672
 673    /// <summary>
 674    /// Adds two vectors component-wise.
 675    /// </summary>
 676    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 677    public static Vector4d operator +(Vector4d v1, Vector4d v2)
 1678    {
 1679        return new Vector4d(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
 1680    }
 681
 682    /// <summary>
 683    /// Adds a scalar to each component.
 684    /// </summary>
 685    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 686    public static Vector4d operator +(Vector4d v1, Fixed64 mag)
 2687    {
 2688        return new Vector4d(v1.x + mag, v1.y + mag, v1.z + mag, v1.w + mag);
 2689    }
 690
 691    /// <inheritdoc cref="operator +(Vector4d, Fixed64)"/>
 692    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 693    public static Vector4d operator +(Fixed64 mag, Vector4d v1)
 1694    {
 1695        return v1 + mag;
 1696    }
 697
 698    /// <summary>
 699    /// Adds a tuple to each component.
 700    /// </summary>
 701    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 702    public static Vector4d operator +(Vector4d v1, (int x, int y, int z, int w) v2)
 2703    {
 2704        return new Vector4d(v1.x + v2.x, v1.y + v2.y, v1.z + v2.z, v1.w + v2.w);
 2705    }
 706
 707    /// <summary>
 708    /// Adds a tuple to each component.
 709    /// </summary>
 710    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 711    public static Vector4d operator +((int x, int y, int z, int w) v2, Vector4d v1)
 1712    {
 1713        return v1 + v2;
 1714    }
 715
 716    /// <summary>
 717    /// Subtracts two vectors component-wise.
 718    /// </summary>
 719    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 720    public static Vector4d operator -(Vector4d v1, Vector4d v2)
 1721    {
 1722        return new Vector4d(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
 1723    }
 724
 725    /// <summary>
 726    /// Subtracts a scalar from each component.
 727    /// </summary>
 728    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 729    public static Vector4d operator -(Vector4d v1, Fixed64 mag)
 1730    {
 1731        return new Vector4d(v1.x - mag, v1.y - mag, v1.z - mag, v1.w - mag);
 1732    }
 733
 734    /// <inheritdoc cref="operator -(Vector4d, Fixed64)"/>
 735    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 736    public static Vector4d operator -(Fixed64 mag, Vector4d v1)
 1737    {
 1738        return new Vector4d(mag - v1.x, mag - v1.y, mag - v1.z, mag - v1.w);
 1739    }
 740
 741    /// <summary>
 742    /// Subtracts a tuple from each component.
 743    /// </summary>
 744    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 745    public static Vector4d operator -(Vector4d v1, (int x, int y, int z, int w) v2)
 1746    {
 1747        return new Vector4d(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
 1748    }
 749
 750    /// <summary>
 751    /// Subtracts each vector component from a tuple component.
 752    /// </summary>
 753    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 754    public static Vector4d operator -((int x, int y, int z, int w) v1, Vector4d v2)
 1755    {
 1756        return new Vector4d(v1.x - v2.x, v1.y - v2.y, v1.z - v2.z, v1.w - v2.w);
 1757    }
 758
 759    /// <summary>
 760    /// Negates the vector.
 761    /// </summary>
 762    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 763    public static Vector4d operator -(Vector4d v1)
 1764    {
 1765        return new Vector4d(-v1.x, -v1.y, -v1.z, -v1.w);
 1766    }
 767
 768    /// <summary>
 769    /// Multiplies each component by a scalar.
 770    /// </summary>
 771    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 772    public static Vector4d operator *(Vector4d v1, Fixed64 mag)
 4773    {
 4774        return new Vector4d(v1.x * mag, v1.y * mag, v1.z * mag, v1.w * mag);
 4775    }
 776
 777    /// <inheritdoc cref="operator *(Vector4d, Fixed64)"/>
 778    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 779    public static Vector4d operator *(Fixed64 mag, Vector4d v1)
 1780    {
 1781        return v1 * mag;
 1782    }
 783
 784    /// <summary>
 785    /// Multiplies each component by an integer scalar.
 786    /// </summary>
 787    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 788    public static Vector4d operator *(Vector4d v1, int mag)
 2789    {
 2790        return v1 * (Fixed64)mag;
 2791    }
 792
 793    /// <inheritdoc cref="operator *(Vector4d, int)"/>
 794    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 795    public static Vector4d operator *(int mag, Vector4d v1)
 1796    {
 1797        return v1 * mag;
 1798    }
 799
 800    /// <summary>
 801    /// Multiplies two vectors component-wise.
 802    /// </summary>
 803    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 804    public static Vector4d operator *(Vector4d v1, Vector4d v2)
 1805    {
 1806        return Scale(v1, v2);
 1807    }
 808
 809    /// <summary>
 810    /// Transforms a vector by a 4x4 matrix.
 811    /// </summary>
 812    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 813    public static Vector4d operator *(Fixed4x4 matrix, Vector4d vector)
 5814    {
 5815        return Transform(matrix, vector);
 5816    }
 817
 818    /// <inheritdoc cref="operator *(Fixed4x4, Vector4d)"/>
 819    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 820    public static Vector4d operator *(Vector4d vector, Fixed4x4 matrix)
 1821    {
 1822        return matrix * vector;
 1823    }
 824
 825    /// <summary>
 826    /// Divides each component by a scalar.
 827    /// </summary>
 828    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 829    public static Vector4d operator /(Vector4d v1, Fixed64 div)
 2830    {
 2831        return new Vector4d(v1.x / div, v1.y / div, v1.z / div, v1.w / div);
 2832    }
 833
 834    /// <summary>
 835    /// Divides each component by another vector's corresponding component.
 836    /// </summary>
 837    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 838    public static Vector4d operator /(Vector4d v1, Vector4d v2)
 1839    {
 1840        return new Vector4d(v1.x / v2.x, v1.y / v2.y, v1.z / v2.z, v1.w / v2.w);
 1841    }
 842
 843    /// <summary>
 844    /// Divides each component by an integer scalar.
 845    /// </summary>
 846    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 847    public static Vector4d operator /(Vector4d v1, int div)
 1848    {
 1849        return v1 / (Fixed64)div;
 1850    }
 851
 852    /// <summary>
 853    /// Compares two vectors for equality.
 854    /// </summary>
 855    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1856    public static bool operator ==(Vector4d left, Vector4d right) => left.Equals(right);
 857
 858    /// <summary>
 859    /// Compares two vectors for inequality.
 860    /// </summary>
 861    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 1862    public static bool operator !=(Vector4d left, Vector4d right) => !left.Equals(right);
 863
 864    /// <summary>
 865    /// Returns true when every component in the left vector is greater than the corresponding component in the right ve
 866    /// </summary>
 867    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 868    public static bool operator >(Vector4d left, Vector4d right)
 5869    {
 5870        return left.x > right.x && left.y > right.y && left.z > right.z && left.w > right.w;
 5871    }
 872
 873    /// <summary>
 874    /// Returns true when every component in the left vector is less than the corresponding component in the right vecto
 875    /// </summary>
 876    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 877    public static bool operator <(Vector4d left, Vector4d right)
 5878    {
 5879        return left.x < right.x && left.y < right.y && left.z < right.z && left.w < right.w;
 5880    }
 881
 882    /// <summary>
 883    /// Returns true when every component in the left vector is greater than or equal to the corresponding component in 
 884    /// </summary>
 885    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 886    public static bool operator >=(Vector4d left, Vector4d right)
 6887    {
 6888        return left.x >= right.x && left.y >= right.y && left.z >= right.z && left.w >= right.w;
 6889    }
 890
 891    /// <summary>
 892    /// Returns true when every component in the left vector is less than or equal to the corresponding component in the
 893    /// </summary>
 894    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 895    public static bool operator <=(Vector4d left, Vector4d right)
 6896    {
 6897        return left.x <= right.x && left.y <= right.y && left.z <= right.z && left.w <= right.w;
 6898    }
 899
 900    #endregion
 901
 902    #region Conversion and Formatting
 903
 904    /// <summary>
 905    /// Returns a string representation of this vector.
 906    /// </summary>
 907    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 908    public override readonly string ToString()
 1909    {
 1910        return string.Format(
 1911            "({0}, {1}, {2}, {3})",
 1912            x.ToFormattedDouble(),
 1913            y.ToFormattedDouble(),
 1914            z.ToFormattedDouble(),
 1915            w.ToFormattedDouble());
 1916    }
 917
 918    /// <summary>
 919    /// Deconstructs the vector into single-precision floating-point values.
 920    /// </summary>
 921    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 922    public readonly void Deconstruct(out float x, out float y, out float z, out float w)
 1923    {
 1924        x = this.x.ToPreciseFloat();
 1925        y = this.y.ToPreciseFloat();
 1926        z = this.z.ToPreciseFloat();
 1927        w = this.w.ToPreciseFloat();
 1928    }
 929
 930    /// <summary>
 931    /// Deconstructs the vector into rounded integer values.
 932    /// </summary>
 933    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 934    public readonly void Deconstruct(out int x, out int y, out int z, out int w)
 1935    {
 1936        x = this.x.RoundToInt();
 1937        y = this.y.RoundToInt();
 1938        z = this.z.RoundToInt();
 1939        w = this.w.RoundToInt();
 1940    }
 941
 942    #endregion
 943
 944    #region Equality and HashCode Overrides
 945
 946    /// <inheritdoc/>
 947    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2948    public override readonly bool Equals(object? obj) => obj is Vector4d other && Equals(other);
 949
 950    /// <inheritdoc/>
 951    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 952    public readonly bool Equals(Vector4d other)
 78953    {
 78954        return other.x == x && other.y == y && other.z == z && other.w == w;
 78955    }
 956
 957    /// <inheritdoc/>
 1958    public readonly bool Equals(Vector4d x, Vector4d y) => x.Equals(y);
 959
 960    /// <inheritdoc/>
 961    [MethodImpl(MethodImplOptions.AggressiveInlining)]
 2962    public override readonly int GetHashCode() => StateHash;
 963
 964    /// <inheritdoc/>
 1965    public readonly int GetHashCode(Vector4d obj) => obj.GetHashCode();
 966
 967    /// <summary>
 968    /// Compares the current Vector4d instance with another Vector4d based on squared magnitude.
 969    /// </summary>
 1970    public readonly int CompareTo(Vector4d other) => SqrMagnitude.CompareTo(other.SqrMagnitude);
 971
 972    #endregion
 973}

Methods/Properties

.ctor(System.Int32,System.Int32,System.Int32,System.Int32)
.ctor(System.Double,System.Double,System.Double,System.Double)
.ctor(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
.ctor(FixedMathSharp.Fixed64)
.ctor(FixedMathSharp.Vector2d,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
.ctor(FixedMathSharp.Vector3d,FixedMathSharp.Fixed64)
get_Normal()
get_Magnitude()
get_SqrMagnitude()
get_LongStateHash()
get_StateHash()
get_IsZero()
get_Item(System.Int32)
set_Item(System.Int32,FixedMathSharp.Fixed64)
Set(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
AddInPlace(FixedMathSharp.Vector4d)
SubtractInPlace(FixedMathSharp.Fixed64)
SubtractInPlace(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
SubtractInPlace(FixedMathSharp.Vector4d)
ScaleInPlace(FixedMathSharp.Fixed64)
ScaleInPlace(FixedMathSharp.Vector4d)
Normalize()
Normalize(FixedMathSharp.Fixed64&)
IsNormalized()
AllComponentsGreaterThanEpsilon()
SnapSmallComponentsToZero(System.Nullable`1<FixedMathSharp.Fixed64>)
Distance(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Distance(FixedMathSharp.Vector4d)
SqrDistance(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
SqrDistance(FixedMathSharp.Vector4d)
Dot(FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64,FixedMathSharp.Fixed64)
Dot(FixedMathSharp.Vector4d)
ToVector3d()
Lerp(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
UnclampedLerp(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
GetNormalized(FixedMathSharp.Vector4d)
GetMagnitude(FixedMathSharp.Vector4d)
Abs(FixedMathSharp.Vector4d)
Sign(FixedMathSharp.Vector4d)
Clamp(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Midpoint(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Distance(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
SqrDistance(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Dot(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Scale(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Max(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Min(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
Transform(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector4d)
op_Addition(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_Addition(FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
op_Addition(FixedMathSharp.Fixed64,FixedMathSharp.Vector4d)
op_Addition(FixedMathSharp.Vector4d,System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32>)
op_Addition(System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32>,FixedMathSharp.Vector4d)
op_Subtraction(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_Subtraction(FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
op_Subtraction(FixedMathSharp.Fixed64,FixedMathSharp.Vector4d)
op_Subtraction(FixedMathSharp.Vector4d,System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32>)
op_Subtraction(System.ValueTuple`4<System.Int32,System.Int32,System.Int32,System.Int32>,FixedMathSharp.Vector4d)
op_UnaryNegation(FixedMathSharp.Vector4d)
op_Multiply(FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
op_Multiply(FixedMathSharp.Fixed64,FixedMathSharp.Vector4d)
op_Multiply(FixedMathSharp.Vector4d,System.Int32)
op_Multiply(System.Int32,FixedMathSharp.Vector4d)
op_Multiply(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_Multiply(FixedMathSharp.Fixed4x4,FixedMathSharp.Vector4d)
op_Multiply(FixedMathSharp.Vector4d,FixedMathSharp.Fixed4x4)
op_Division(FixedMathSharp.Vector4d,FixedMathSharp.Fixed64)
op_Division(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_Division(FixedMathSharp.Vector4d,System.Int32)
op_Equality(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_Inequality(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_GreaterThan(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_LessThan(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_GreaterThanOrEqual(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
op_LessThanOrEqual(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
ToString()
Deconstruct(System.Single&,System.Single&,System.Single&,System.Single&)
Deconstruct(System.Int32&,System.Int32&,System.Int32&,System.Int32&)
Equals(System.Object)
Equals(FixedMathSharp.Vector4d)
Equals(FixedMathSharp.Vector4d,FixedMathSharp.Vector4d)
GetHashCode()
GetHashCode(FixedMathSharp.Vector4d)
CompareTo(FixedMathSharp.Vector4d)