Skip to content

Commit 38024ba

Browse files
authored
Merge pull request #24 from mrdav30/develop
Develop to Main
2 parents 9f76a8f + d67a261 commit 38024ba

File tree

5 files changed

+196
-3
lines changed

5 files changed

+196
-3
lines changed

src/FixedMathSharp/Fixed64.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,23 @@ public static explicit operator decimal(Fixed64 value)
243243
}
244244

245245
/// <summary>
246-
/// Adds an int to a
246+
/// Adds an int to x
247247
/// </summary>
248248
[MethodImpl(MethodImplOptions.AggressiveInlining)]
249249
public static Fixed64 operator +(Fixed64 x, int y)
250250
{
251251
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) + y);
252252
}
253253

254+
/// <summary>
255+
/// Adds an int to y
256+
/// </summary>
257+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
258+
public static Fixed64 operator +(int x, Fixed64 y)
259+
{
260+
return y + x;
261+
}
262+
254263
/// <summary>
255264
/// Subtracts one Fixed64 number from another, with saturating behavior in case of overflow.
256265
/// </summary>
@@ -266,14 +275,23 @@ public static explicit operator decimal(Fixed64 value)
266275
}
267276

268277
/// <summary>
269-
/// Subtracts an int from a
278+
/// Subtracts an int from x
270279
/// </summary>
271280
[MethodImpl(MethodImplOptions.AggressiveInlining)]
272281
public static Fixed64 operator -(Fixed64 x, int y)
273282
{
274283
return new Fixed64((x.m_rawValue * FixedMath.SCALE_FACTOR_D) - y);
275284
}
276285

286+
/// <summary>
287+
/// Subtracts an int from y
288+
/// </summary>
289+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
290+
public static Fixed64 operator -(int x, Fixed64 y)
291+
{
292+
return y - x;
293+
}
294+
277295
/// <summary>
278296
/// Multiplies two Fixed64 numbers, handling overflow and rounding.
279297
/// </summary>

src/FixedMathSharp/Vector2d.Extensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ public static Vector2d Abs(this Vector2d value)
4646
return Vector2d.Abs(value);
4747
}
4848

49+
/// <inheritdoc cref="Vector2d.Sign(Vector2d)" />
50+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
51+
public static Vector2d Sign(this Vector2d value)
52+
{
53+
return Vector2d.Sign(value);
54+
}
55+
4956
#endregion
5057

5158
#region Conversion

src/FixedMathSharp/Vector2d.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,14 @@ public partial struct Vector2d : IEquatable<Vector2d>, IComparable<Vector2d>, IE
2424
{
2525
#region Fields and Constants
2626

27+
/// <summary>
28+
/// The X component of the vector.
29+
/// </summary>
2730
public Fixed64 x;
28-
31+
32+
/// <summary>
33+
/// The Y component of the vector.
34+
/// </summary>
2935
public Fixed64 y;
3036

3137
/// <summary>
@@ -128,12 +134,16 @@ public Vector2d LeftHandNormal
128134
get => new Vector2d(y, -x);
129135
}
130136

137+
/// <inheritdoc cref="GetNormalized(Vector2d)"/>
131138
public Vector2d Normal
132139
{
133140
[MethodImpl(MethodImplOptions.AggressiveInlining)]
134141
get => GetNormalized(this);
135142
}
136143

144+
/// <summary>
145+
/// Returns the actual length of this vector (RO).
146+
/// </summary>
137147
public Fixed64 Magnitude
138148
{
139149
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -234,6 +244,7 @@ public Vector2d AddInPlace(Fixed64 xAmount, Fixed64 yAmount)
234244
return this;
235245
}
236246

247+
/// <inheritdoc cref="AddInPlace(Fixed64, Fixed64)"/>
237248
[MethodImpl(MethodImplOptions.AggressiveInlining)]
238249
public Vector2d AddInPlace(Vector2d other)
239250
{
@@ -515,12 +526,19 @@ public Fixed64 Dot(Vector2d other)
515526
return Dot(other.x, other.y);
516527
}
517528

529+
/// <summary>
530+
/// Computes the cross product magnitude of this vector with another vector.
531+
/// </summary>
532+
/// <param name="otherX">The X component of the other vector.</param>
533+
/// <param name="otherY">The Y component of the other vector.</param>
534+
/// <returns>The cross product magnitude.</returns>
518535
[MethodImpl(MethodImplOptions.AggressiveInlining)]
519536
public Fixed64 CrossProduct(Fixed64 otherX, Fixed64 otherY)
520537
{
521538
return x * otherY - y * otherX;
522539
}
523540

541+
/// <inheritdoc cref="CrossProduct(Fixed64, Fixed64)"/>
524542
[MethodImpl(MethodImplOptions.AggressiveInlining)]
525543
public Fixed64 CrossProduct(Vector2d other)
526544
{
@@ -607,12 +625,28 @@ public static Fixed64 GetMagnitude(Vector2d vector)
607625
return temp1.Abs() > Fixed64.Zero ? FixedMath.Sqrt(temp1) : Fixed64.Zero;
608626
}
609627

628+
/// <summary>
629+
/// Returns a new <see cref="Vector2d"/> where each component is the absolute value of the corresponding input component.
630+
/// </summary>
631+
/// <param name="value">The input vector.</param>
632+
/// <returns>A vector with absolute values for each component.</returns>
610633
[MethodImpl(MethodImplOptions.AggressiveInlining)]
611634
public static Vector2d Abs(Vector2d value)
612635
{
613636
return new Vector2d(value.x.Abs(), value.y.Abs());
614637
}
615638

639+
/// <summary>
640+
/// Returns a new <see cref="Vector2d"/> where each component is the sign of the corresponding input component.
641+
/// </summary>
642+
/// <param name="value">The input vector.</param>
643+
/// <returns>A vector where each component is -1, 0, or 1 based on the sign of the input.</returns>
644+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
645+
public static Vector2d Sign(Vector2d value)
646+
{
647+
return new Vector2d(value.x.Sign(), value.y.Sign());
648+
}
649+
616650
/// <summary>
617651
/// Creates a vector from a given angle in radians.
618652
/// </summary>
@@ -633,6 +667,10 @@ public static Fixed64 Distance(Vector2d start, Vector2d end)
633667
return start.Distance(end);
634668
}
635669

670+
/// <summary>
671+
/// Calculates the squared distance between two vectors, avoiding the need for a square root operation.
672+
/// </summary>
673+
/// <returns>The squared distance between the two vectors.</returns>
636674
[MethodImpl(MethodImplOptions.AggressiveInlining)]
637675
public static Fixed64 SqrDistance(Vector2d start, Vector2d end)
638676
{
@@ -712,6 +750,15 @@ public override string ToString()
712750
return $"({Math.Round((double)x, 2)}, {Math.Round((double)y, 2)})";
713751
}
714752

753+
/// <summary>
754+
/// Converts this <see cref="Vector2d"/> to a <see cref="Vector3d"/>,
755+
/// mapping the Y component of this vector to the Z axis in the resulting vector.
756+
/// </summary>
757+
/// <param name="z">The value to assign to the Y axis of the resulting <see cref="Vector3d"/>.</param>
758+
/// <returns>
759+
/// A new <see cref="Vector3d"/> where (X, Y) from this <see cref="Vector2d"/>
760+
/// become (X, Z) in the resulting vector, with the provided Z parameter assigned to Y.
761+
/// </returns>
715762
[MethodImpl(MethodImplOptions.AggressiveInlining)]
716763
public Vector3d ToVector3d(Fixed64 z)
717764
{

src/FixedMathSharp/Vector3d.Extensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ public static Vector3d Abs(this Vector3d value)
7171
return Vector3d.Abs(value);
7272
}
7373

74+
/// <inheritdoc cref="Vector3d.Sign(Vector3d)" />
75+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
76+
public static Vector3d Sign(Vector3d value)
77+
{
78+
return Vector3d.Sign(value);
79+
}
80+
7481
#endregion
7582

7683
#region Equality

0 commit comments

Comments
 (0)