From 69bc6573d1ee62fd0028163335a55e2952543ed0 Mon Sep 17 00:00:00 2001 From: Syntriax Date: Thu, 16 Oct 2025 13:59:49 +0300 Subject: [PATCH] feat: added IEquatable interfaces to primitives --- Engine.Core/Primitives/AABB.cs | 4 +++- Engine.Core/Primitives/Circle.cs | 4 +++- Engine.Core/Primitives/ColorHSV.cs | 5 ++++- Engine.Core/Primitives/ColorHSVA.cs | 5 ++++- Engine.Core/Primitives/ColorRGB.cs | 5 ++++- Engine.Core/Primitives/ColorRGBA.cs | 5 ++++- Engine.Core/Primitives/Line2D.cs | 4 +++- Engine.Core/Primitives/Line2DEquation.cs | 5 ++++- Engine.Core/Primitives/Projection1D.cs | 5 ++++- Engine.Core/Primitives/Quaternion.cs | 5 ++++- Engine.Core/Primitives/Ray2D.cs | 5 ++++- Engine.Core/Primitives/Triangle.cs | 5 ++++- Engine.Core/Primitives/Vector2D.cs | 5 ++++- Engine.Core/Primitives/Vector3D.cs | 5 ++++- 14 files changed, 53 insertions(+), 14 deletions(-) diff --git a/Engine.Core/Primitives/AABB.cs b/Engine.Core/Primitives/AABB.cs index 3789526..15a2767 100644 --- a/Engine.Core/Primitives/AABB.cs +++ b/Engine.Core/Primitives/AABB.cs @@ -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 struct with the specified lower and upper boundaries. /// [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 { /// /// The lower boundary of the . @@ -82,6 +83,7 @@ public readonly struct AABB(Vector2D lowerBoundary, Vector2D upperBoundary) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is AABB aabb && this == aabb; + public bool Equals(AABB other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Circle.cs b/Engine.Core/Primitives/Circle.cs index bfd1632..2f516ef 100644 --- a/Engine.Core/Primitives/Circle.cs +++ b/Engine.Core/Primitives/Circle.cs @@ -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 struct with the specified center and radius. /// [DebuggerDisplay("Center: {Center.ToString(),nq}, Radius: {Radius}")] -public readonly struct Circle(Vector2D center, float radius) +public readonly struct Circle(Vector2D center, float radius) : IEquatable { /// /// The center of the circle. @@ -87,6 +88,7 @@ public readonly struct Circle(Vector2D center, float radius) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Circle circle && this == circle; + public bool Equals(Circle other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/ColorHSV.cs b/Engine.Core/Primitives/ColorHSV.cs index 8cc7b42..9090694 100644 --- a/Engine.Core/Primitives/ColorHSV.cs +++ b/Engine.Core/Primitives/ColorHSV.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -10,7 +12,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified values. /// [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 { /// /// The Hue value of the . @@ -112,6 +114,7 @@ public readonly struct ColorHSV(float hue, float saturation, float value) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is ColorHSV colorHSV && this == colorHSV; + public bool Equals(ColorHSV other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/ColorHSVA.cs b/Engine.Core/Primitives/ColorHSVA.cs index 3f073c8..cb3ffa9 100644 --- a/Engine.Core/Primitives/ColorHSVA.cs +++ b/Engine.Core/Primitives/ColorHSVA.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -11,7 +13,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified values. /// [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 { /// /// The Hue value of the . @@ -150,6 +152,7 @@ public readonly struct ColorHSVA(float hue, float saturation, float value, float /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is ColorHSVA colorHSVA && this == colorHSVA; + public bool Equals(ColorHSVA other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/ColorRGB.cs b/Engine.Core/Primitives/ColorRGB.cs index e7628cf..1fada67 100644 --- a/Engine.Core/Primitives/ColorRGB.cs +++ b/Engine.Core/Primitives/ColorRGB.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -10,7 +12,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified values. /// [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 { /// /// The Red value of the . @@ -102,6 +104,7 @@ public readonly struct ColorRGB(byte r, byte g, byte b) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is ColorRGB colorRGB && this == colorRGB; + public bool Equals(ColorRGB other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/ColorRGBA.cs b/Engine.Core/Primitives/ColorRGBA.cs index 3dcfe10..8163840 100644 --- a/Engine.Core/Primitives/ColorRGBA.cs +++ b/Engine.Core/Primitives/ColorRGBA.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -11,7 +13,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified values. /// [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 { /// /// The Red value of the . @@ -132,6 +134,7 @@ public readonly struct ColorRGBA(byte r, byte g, byte b, byte a = 255) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is ColorRGBA colorRGBA && this == colorRGBA; + public bool Equals(ColorRGBA other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Line2D.cs b/Engine.Core/Primitives/Line2D.cs index 171fa7c..753027b 100644 --- a/Engine.Core/Primitives/Line2D.cs +++ b/Engine.Core/Primitives/Line2D.cs @@ -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 struct with the specified endpoints. /// [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 { /// /// The starting point of the segment. @@ -196,6 +197,7 @@ public readonly struct Line2D(Vector2D from, Vector2D to) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Line2D line2D && this == line2D; + public bool Equals(Line2D other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Line2DEquation.cs b/Engine.Core/Primitives/Line2DEquation.cs index a6544d2..fc06e2a 100644 --- a/Engine.Core/Primitives/Line2DEquation.cs +++ b/Engine.Core/Primitives/Line2DEquation.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -9,7 +11,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified slope and Y intercept. /// [System.Diagnostics.DebuggerDisplay("y = {Slope}x + {OffsetY}")] -public readonly struct Line2DEquation(float slope, float offsetY) +public readonly struct Line2DEquation(float slope, float offsetY) : IEquatable { /// /// The slope of the . @@ -48,6 +50,7 @@ public readonly struct Line2DEquation(float slope, float offsetY) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Line2DEquation lineEquation && this == lineEquation; + public bool Equals(Line2DEquation other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Projection1D.cs b/Engine.Core/Primitives/Projection1D.cs index 2408228..e57eb33 100644 --- a/Engine.Core/Primitives/Projection1D.cs +++ b/Engine.Core/Primitives/Projection1D.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -9,7 +11,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified minimum and maximum values. /// [System.Diagnostics.DebuggerDisplay("Min: {Min}, Max: {Max}")] -public readonly struct Projection1D(float min, float max) +public readonly struct Projection1D(float min, float max) : IEquatable { /// /// Gets the minimum value of the projection. @@ -90,6 +92,7 @@ public readonly struct Projection1D(float min, float max) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Projection1D projection1D && this == projection1D; + public bool Equals(Projection1D other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Quaternion.cs b/Engine.Core/Primitives/Quaternion.cs index 68df8dc..0a4b957 100644 --- a/Engine.Core/Primitives/Quaternion.cs +++ b/Engine.Core/Primitives/Quaternion.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -11,7 +13,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified positions. /// [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 { /// /// The X(i) imaginary of the . @@ -288,6 +290,7 @@ public readonly struct Quaternion(float x, float y, float z, float w) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Quaternion quaternion && this == quaternion; + public bool Equals(Quaternion other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Ray2D.cs b/Engine.Core/Primitives/Ray2D.cs index ddc68c8..29884b7 100644 --- a/Engine.Core/Primitives/Ray2D.cs +++ b/Engine.Core/Primitives/Ray2D.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -5,7 +7,7 @@ namespace Engine.Core; /// /// The in 2D space where the ray starts from. /// Normalized indicating the ray's is direction. -public readonly struct Ray2D(Vector2D Origin, Vector2D Direction) +public readonly struct Ray2D(Vector2D Origin, Vector2D Direction) : IEquatable { /// /// The starting point of the . @@ -72,6 +74,7 @@ public readonly struct Ray2D(Vector2D Origin, Vector2D Direction) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Ray2D ray2D && this == ray2D; + public bool Equals(Ray2D other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Triangle.cs b/Engine.Core/Primitives/Triangle.cs index d959a63..96477cb 100644 --- a/Engine.Core/Primitives/Triangle.cs +++ b/Engine.Core/Primitives/Triangle.cs @@ -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 { 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) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Triangle triangle && this == triangle; + public bool Equals(Triangle other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Vector2D.cs b/Engine.Core/Primitives/Vector2D.cs index 624b9ca..751e1c1 100644 --- a/Engine.Core/Primitives/Vector2D.cs +++ b/Engine.Core/Primitives/Vector2D.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -9,7 +11,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified positions. /// [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 { /// /// The X coordinate of the . @@ -308,6 +310,7 @@ public readonly struct Vector2D(float x, float y) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Vector2D vector2D && this == vector2D; + public bool Equals(Vector2D other) => this == other; /// /// Generates a hash code for the . diff --git a/Engine.Core/Primitives/Vector3D.cs b/Engine.Core/Primitives/Vector3D.cs index dedbb37..b7d8c3f 100644 --- a/Engine.Core/Primitives/Vector3D.cs +++ b/Engine.Core/Primitives/Vector3D.cs @@ -1,3 +1,5 @@ +using System; + namespace Engine.Core; /// @@ -10,7 +12,7 @@ namespace Engine.Core; /// Initializes a new instance of the struct with the specified positions. /// [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 { /// /// The X coordinate of the . @@ -277,6 +279,7 @@ public readonly struct Vector3D(float x, float y, float z) /// The object to compare with the current . /// if the specified object is equal to the current ; otherwise, . public override bool Equals(object? obj) => obj is Vector3D vector3D && this == vector3D; + public bool Equals(Vector3D other) => this == other; /// /// Generates a hash code for the .