diff --git a/X10D/src/Drawing/Sphere.cs b/X10D/src/Drawing/Sphere.cs index 8f609e8..7e7a1e7 100644 --- a/X10D/src/Drawing/Sphere.cs +++ b/X10D/src/Drawing/Sphere.cs @@ -1,11 +1,11 @@ -using System.Numerics; +using System.Numerics; namespace X10D.Drawing; /// /// Represents a sphere in 3D space, which uses single-precision floating-point numbers for its coordinates. /// -public readonly struct Sphere : IEquatable +public readonly struct Sphere : IEquatable, IComparable, IComparable { /// /// Initializes a new instance of the struct. @@ -57,7 +57,7 @@ public readonly struct Sphere : IEquatable } /// - /// Returns a value indicating whether two instances of are not equal. + /// Returns a value indicating whether two instances of are not equal. /// /// The first instance. /// The second instance. @@ -70,6 +70,156 @@ public readonly struct Sphere : IEquatable return !left.Equals(right); } + /// + /// Returns a value indicating whether the radius of one circle is less than that of another. + /// + /// The first instance. + /// The second instance. + /// + /// if the of is less than that of + /// ; otherwise, . + /// + public static bool operator <(Sphere left, Sphere right) + { + return left.CompareTo(right) < 0; + } + + /// + /// Returns a value indicating whether the radius of one circle is greater than to that of another. + /// + /// The first instance. + /// The second instance. + /// + /// if the of is greater than that of + /// ; otherwise, . + /// + public static bool operator >(Sphere left, Sphere right) + { + return left.CompareTo(right) > 0; + } + + /// + /// Returns a value indicating whether the radius of one circle is less than or equal to that of another. + /// + /// The first instance. + /// The second instance. + /// + /// if the of is less than or equal to that of + /// ; otherwise, . + /// + public static bool operator <=(Sphere left, Sphere right) + { + return left.CompareTo(right) <= 0; + } + + /// + /// Returns a value indicating whether the radius of one circle is greater than or equal to that of another. + /// + /// The first instance. + /// The second instance. + /// + /// if the of is greater than or equal to that of + /// ; otherwise, . + /// + public static bool operator >=(Sphere left, Sphere right) + { + return left.CompareTo(right) >= 0; + } + + /// + /// Compares this instance to another . + /// + /// The other object. + /// + /// A signed number indicating the relative values of this instance and . + /// + /// + /// + /// Return value + /// Meaning + /// + /// + /// + /// Less than zero + /// + /// The of this instance is less than that of . + /// + /// + /// + /// Zero + /// + /// This instance is equal to , or the of both this instance + /// and are not a number (), + /// , or . + /// + /// + /// + /// Greater than zero + /// + /// The of this instance is greater than that of , or + /// is . + /// + /// + /// + /// + /// Comparison only takes into consideration the . + /// is not an instance of . + public int CompareTo(object? obj) + { + if (ReferenceEquals(null, obj)) + { + return 1; + } + + if (obj is not Sphere other) + { + throw new ArgumentException($"Object must be of type {GetType()}"); + } + + return CompareTo(other); + } + + /// + /// Compares this instance to another . + /// + /// The other sphere. + /// + /// A signed number indicating the relative values of this instance and . + /// + /// + /// + /// Return value + /// Meaning + /// + /// + /// + /// Less than zero + /// + /// The of this instance is less than that of . + /// + /// + /// + /// Zero + /// + /// This instance is equal to , or the of both this instance + /// and are not a number (), + /// , or . + /// + /// + /// + /// Greater than zero + /// + /// The of this instance is greater than that of . + /// + /// + /// + /// + /// Comparison only takes into consideration the . + public int CompareTo(Sphere other) + { + return Radius.CompareTo(other.Radius); + } + /// public override bool Equals(object? obj) {