feat: added IEquatable interfaces to primitives

This commit is contained in:
2025-10-16 13:59:49 +03:00
parent 28bc022587
commit 69bc6573d1
14 changed files with 53 additions and 14 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
namespace Engine.Core;
@@ -11,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="AABB"/> struct with the specified lower and upper boundaries.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("LowerBoundary: {LowerBoundary.ToString(), nq}, UpperBoundary: {UpperBoundary.ToString(), nq}")]
public readonly struct AABB(Vector2D lowerBoundary, Vector2D upperBoundary)
public readonly struct AABB(Vector2D lowerBoundary, Vector2D upperBoundary) : IEquatable<AABB>
{
/// <summary>
/// The lower boundary of the <see cref="AABB"/>.
@@ -82,6 +83,7 @@ public readonly struct AABB(Vector2D lowerBoundary, Vector2D upperBoundary)
/// <param name="obj">The object to compare with the current <see cref="AABB"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="AABB"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is AABB aabb && this == aabb;
public bool Equals(AABB other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="AABB"/>.

View File

@@ -1,3 +1,4 @@
using System;
using System.Diagnostics;
namespace Engine.Core;
@@ -11,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Circle"/> struct with the specified center and radius.
/// </remarks>
[DebuggerDisplay("Center: {Center.ToString(),nq}, Radius: {Radius}")]
public readonly struct Circle(Vector2D center, float radius)
public readonly struct Circle(Vector2D center, float radius) : IEquatable<Circle>
{
/// <summary>
/// The center of the circle.
@@ -87,6 +88,7 @@ public readonly struct Circle(Vector2D center, float radius)
/// <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 && this == circle;
public bool Equals(Circle other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Circle"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -10,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="ColorHSV"/> struct with the specified values.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}")]
public readonly struct ColorHSV(float hue, float saturation, float value)
public readonly struct ColorHSV(float hue, float saturation, float value) : IEquatable<ColorHSV>
{
/// <summary>
/// The Hue value of the <see cref="ColorHSV"/>.
@@ -112,6 +114,7 @@ public readonly struct ColorHSV(float hue, float saturation, float value)
/// <param name="obj">The object to compare with the current <see cref="ColorHSV"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="ColorHSV"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is ColorHSV colorHSV && this == colorHSV;
public bool Equals(ColorHSV other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="ColorHSV"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -11,7 +13,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="ColorHSVA"/> struct with the specified values.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}")]
public readonly struct ColorHSVA(float hue, float saturation, float value, float alpha = 1)
public readonly struct ColorHSVA(float hue, float saturation, float value, float alpha = 1) : IEquatable<ColorHSVA>
{
/// <summary>
/// The Hue value of the <see cref="ColorHSVA"/>.
@@ -150,6 +152,7 @@ public readonly struct ColorHSVA(float hue, float saturation, float value, float
/// <param name="obj">The object to compare with the current <see cref="ColorHSVA"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="ColorHSVA"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is ColorHSVA colorHSVA && this == colorHSVA;
public bool Equals(ColorHSVA other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="ColorHSVA"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -10,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="ColorRGB"/> struct with the specified values.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}")]
public readonly struct ColorRGB(byte r, byte g, byte b)
public readonly struct ColorRGB(byte r, byte g, byte b) : IEquatable<ColorRGB>
{
/// <summary>
/// The Red value of the <see cref="ColorRGB"/>.
@@ -102,6 +104,7 @@ public readonly struct ColorRGB(byte r, byte g, byte b)
/// <param name="obj">The object to compare with the current <see cref="ColorRGB"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="ColorRGB"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is ColorRGB colorRGB && this == colorRGB;
public bool Equals(ColorRGB other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="ColorRGB"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -11,7 +13,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="ColorRGBA"/> struct with the specified values.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}")]
public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255)
public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255) : IEquatable<ColorRGBA>
{
/// <summary>
/// The Red value of the <see cref="ColorRGBA"/>.
@@ -132,6 +134,7 @@ public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255)
/// <param name="obj">The object to compare with the current <see cref="ColorRGBA"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="ColorRGBA"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is ColorRGBA colorRGBA && this == colorRGBA;
public bool Equals(ColorRGBA other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="ColorRGBA"/>.

View File

@@ -1,3 +1,4 @@
using System;
using System.Diagnostics.CodeAnalysis;
namespace Engine.Core;
@@ -11,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Line2D"/> struct with the specified endpoints.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("From: {From.ToString(),nq}, To: {To.ToString(),nq}, Direction: {Direction.ToString(),nq}, Length: {Length}")]
public readonly struct Line2D(Vector2D from, Vector2D to)
public readonly struct Line2D(Vector2D from, Vector2D to) : IEquatable<Line2D>
{
/// <summary>
/// The starting point of the <see cref="Line2D"/> segment.
@@ -196,6 +197,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to)
/// <param name="obj">The object to compare with the current <see cref="Line2D"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Line2D"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Line2D line2D && this == line2D;
public bool Equals(Line2D other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Line2D"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -9,7 +11,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Line2DEquation"/> struct with the specified slope and Y intercept.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("y = {Slope}x + {OffsetY}")]
public readonly struct Line2DEquation(float slope, float offsetY)
public readonly struct Line2DEquation(float slope, float offsetY) : IEquatable<Line2DEquation>
{
/// <summary>
/// The slope of the <see cref="Line2DEquation"/>.
@@ -48,6 +50,7 @@ public readonly struct Line2DEquation(float slope, float offsetY)
/// <param name="obj">The object to compare with the current <see cref="Line2DEquation"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Line2DEquation"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Line2DEquation lineEquation && this == lineEquation;
public bool Equals(Line2DEquation other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Line2DEquation"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -9,7 +11,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Projection1D"/> struct with the specified minimum and maximum values.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("Min: {Min}, Max: {Max}")]
public readonly struct Projection1D(float min, float max)
public readonly struct Projection1D(float min, float max) : IEquatable<Projection1D>
{
/// <summary>
/// Gets the minimum value of the projection.
@@ -90,6 +92,7 @@ public readonly struct Projection1D(float min, float max)
/// <param name="obj">The object to compare with the current <see cref="Projection1D"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Projection1D"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Projection1D projection1D && this == projection1D;
public bool Equals(Projection1D other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Projection1D"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -11,7 +13,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Quaternion"/> struct with the specified positions.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}, Length: {Magnitude}, LengthSquared: {MagnitudeSquared}, Normalized: {Normalized.ToString(),nq}")]
public readonly struct Quaternion(float x, float y, float z, float w)
public readonly struct Quaternion(float x, float y, float z, float w) : IEquatable<Quaternion>
{
/// <summary>
/// The X(i) imaginary of the <see cref="Quaternion"/>.
@@ -288,6 +290,7 @@ public readonly struct Quaternion(float x, float y, float z, float w)
/// <param name="obj">The object to compare with the current <see cref="Quaternion"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Quaternion"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Quaternion quaternion && this == quaternion;
public bool Equals(Quaternion other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Quaternion"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -5,7 +7,7 @@ namespace Engine.Core;
/// </summary>
/// <param name="Origin">The <see cref="Vector2D"/> in 2D space where the ray starts from.</param>
/// <param name="Direction">Normalized <see cref="Vector2D"/> indicating the ray's is direction.</param>
public readonly struct Ray2D(Vector2D Origin, Vector2D Direction)
public readonly struct Ray2D(Vector2D Origin, Vector2D Direction) : IEquatable<Ray2D>
{
/// <summary>
/// The starting point of the <see cref="Ray2D"/>.
@@ -72,6 +74,7 @@ public readonly struct Ray2D(Vector2D Origin, Vector2D Direction)
/// <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 && this == ray2D;
public bool Equals(Ray2D other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Ray2D"/>.

View File

@@ -1,7 +1,9 @@
using System;
namespace Engine.Core;
[System.Diagnostics.DebuggerDisplay("A: {A.ToString(), nq}, B: {B.ToString(), nq}, B: {C.ToString(), nq}")]
public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C)
public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C) : IEquatable<Triangle>
{
public readonly Vector2D A { get; init; } = A;
public readonly Vector2D B { get; init; } = B;
@@ -54,6 +56,7 @@ public readonly struct Triangle(Vector2D A, Vector2D B, Vector2D C)
/// <param name="obj">The object to compare with the current <see cref="Triangle"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Triangle"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Triangle triangle && this == triangle;
public bool Equals(Triangle other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Triangle"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -9,7 +11,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Vector2D"/> struct with the specified positions.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}, Length: {Magnitude}, LengthSquared: {MagnitudeSquared}, Normalized: {Normalized.ToString(),nq}")]
public readonly struct Vector2D(float x, float y)
public readonly struct Vector2D(float x, float y) : IEquatable<Vector2D>
{
/// <summary>
/// The X coordinate of the <see cref="Vector2D"/>.
@@ -308,6 +310,7 @@ public readonly struct Vector2D(float x, float y)
/// <param name="obj">The object to compare with the current <see cref="Vector2D"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Vector2D"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Vector2D vector2D && this == vector2D;
public bool Equals(Vector2D other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Vector2D"/>.

View File

@@ -1,3 +1,5 @@
using System;
namespace Engine.Core;
/// <summary>
@@ -10,7 +12,7 @@ namespace Engine.Core;
/// Initializes a new instance of the <see cref="Vector3D"/> struct with the specified positions.
/// </remarks>
[System.Diagnostics.DebuggerDisplay("{ToString(),nq}, Length: {Magnitude}, LengthSquared: {MagnitudeSquared}, Normalized: {Normalized.ToString(),nq}")]
public readonly struct Vector3D(float x, float y, float z)
public readonly struct Vector3D(float x, float y, float z) : IEquatable<Vector3D>
{
/// <summary>
/// The X coordinate of the <see cref="Vector3D"/>.
@@ -277,6 +279,7 @@ public readonly struct Vector3D(float x, float y, float z)
/// <param name="obj">The object to compare with the current <see cref="Vector3D"/>.</param>
/// <returns><see cref="true"/> if the specified object is equal to the current <see cref="Vector3D"/>; otherwise, <see cref="false"/>.</returns>
public override bool Equals(object? obj) => obj is Vector3D vector3D && this == vector3D;
public bool Equals(Vector3D other) => this == other;
/// <summary>
/// Generates a hash code for the <see cref="Vector3D"/>.