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

@@ -22,8 +22,8 @@ public readonly struct Ray2D(Vector2D Origin, Vector2D Direction)
/// </summary>
public readonly Ray2D Reversed => new(Origin, -Direction);
public static bool operator ==(Ray2D left, Ray2D right) => left.Origin == right.Origin;
public static bool operator !=(Ray2D left, Ray2D right) => left.Origin != right.Origin;
public static bool operator ==(Ray2D left, Ray2D right) => left.Origin == right.Origin && left.Direction == right.Direction;
public static bool operator !=(Ray2D left, Ray2D right) => left.Origin != right.Origin || left.Direction != right.Direction;
public static implicit operator Ray2D(Line2D line) => new(line.From, line.From.FromTo(line.To).Normalized);
/// <summary>
@@ -71,7 +71,7 @@ public readonly struct Ray2D(Vector2D Origin, Vector2D Direction)
/// </summary>
/// <param name="obj">The object to compare with the current <see cref="Ray2D"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Ray2D"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Ray2D ray2D && Origin.Equals(ray2D.Origin) && Direction.Equals(ray2D.Direction);
public override bool Equals(object? obj) => obj is Ray2D ray2D && this == ray2D;
/// <summary>
/// Generates a hash code for the <see cref="Ray2D"/>.