refactor: made equality operators consistent in primitives & added missing ones

This commit is contained in:
2025-06-27 12:00:46 +03:00
parent fa1614f238
commit da5f31f9d7
8 changed files with 29 additions and 11 deletions

View File

@@ -38,6 +38,9 @@ public readonly struct Circle(Vector2D center, float radius)
/// </summary>
public static readonly Circle UnitCircle = new(Vector2D.Zero, 1f);
public static bool operator ==(Circle left, Circle right) => left.Center == right.Center && left.Radius == right.Radius;
public static bool operator !=(Circle left, Circle right) => left.Center != right.Center || left.Radius != right.Radius;
/// <summary>
/// Sets the center of the <see cref="Circle"/>.
/// </summary>
@@ -83,7 +86,7 @@ public readonly struct Circle(Vector2D center, float radius)
/// </summary>
/// <param name="obj">The object to compare with the current <see cref="Circle"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Circle"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Circle circle && Center.Equals(circle.Center) && Radius.Equals(circle.Radius);
public override bool Equals(object? obj) => obj is Circle circle && this == circle;
/// <summary>
/// Generates a hash code for the <see cref="Circle"/>.