|
| 1 | +// Copyright 2020-2025 ONIXLabs |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +using OnixLabs.Core; |
| 16 | + |
| 17 | +namespace OnixLabs.Units; |
| 18 | + |
| 19 | +// ReSharper disable MemberCanBePrivate.Global |
| 20 | +public readonly partial struct Volume<T> |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Compares two <see cref="Volume{T}"/> values and returns an integer that indicates |
| 24 | + /// whether the left-hand value is less than, equal to, or greater than the right-hand value. |
| 25 | + /// </summary> |
| 26 | + /// <param name="left">The left-hand value to compare.</param> |
| 27 | + /// <param name="right">The right-hand value to compare.</param> |
| 28 | + /// <returns>Returns a value that indicates the relative order of the objects being compared.</returns> |
| 29 | + public static int Compare(Volume<T> left, Volume<T> right) => left.CubicYoctoMeters.CompareTo(right.CubicYoctoMeters); |
| 30 | + |
| 31 | + /// <summary> |
| 32 | + /// Compares the current instance with another object of the same type and returns an integer that indicates |
| 33 | + /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the |
| 34 | + /// other object. |
| 35 | + /// </summary> |
| 36 | + /// <param name="other">An object to compare with this instance.</param> |
| 37 | + /// <returns>Returns a value that indicates the relative order of the objects being compared.</returns> |
| 38 | + public int CompareTo(Volume<T> other) => Compare(this, other); |
| 39 | + |
| 40 | + /// <summary> |
| 41 | + /// Compares the current instance with another object of the same type and returns an integer that indicates |
| 42 | + /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the |
| 43 | + /// other object. |
| 44 | + /// </summary> |
| 45 | + /// <param name="obj">An object to compare with this instance.</param> |
| 46 | + /// <returns>Returns a value that indicates the relative order of the objects being compared.</returns> |
| 47 | +// ReSharper disable once HeapView.BoxingAllocation |
| 48 | + public int CompareTo(object? obj) => this.CompareToObject(obj); |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Determines whether the left-hand value is greater than the right-hand value. |
| 52 | + /// </summary> |
| 53 | + /// <param name="left">The left-hand value to compare.</param> |
| 54 | + /// <param name="right">The right-hand value to compare.</param> |
| 55 | + /// <returns>Returns <see langword="true"/> if the left-hand operand is greater than the right-hand operand; otherwise, <see langword="false"/>.</returns> |
| 56 | + public static bool operator >(Volume<T> left, Volume<T> right) => Compare(left, right) is 1; |
| 57 | + |
| 58 | + /// <summary> |
| 59 | + /// Determines whether the left-hand value is greater than or equal to the right-hand value. |
| 60 | + /// </summary> |
| 61 | + /// <param name="left">The left-hand value to compare.</param> |
| 62 | + /// <param name="right">The right-hand value to compare.</param> |
| 63 | + /// <returns>Returns <see langword="true"/> if the left-hand operand is greater than or equal to the right-hand operand; otherwise, <see langword="false"/>.</returns> |
| 64 | + public static bool operator >=(Volume<T> left, Volume<T> right) => Compare(left, right) is 1 or 0; |
| 65 | + |
| 66 | + /// <summary> |
| 67 | + /// Determines whether the left-hand value is less than the right-hand value. |
| 68 | + /// </summary> |
| 69 | + /// <param name="left">The left-hand value to compare.</param> |
| 70 | + /// <param name="right">The right-hand value to compare.</param> |
| 71 | + /// <returns>Returns <see langword="true"/> if the left-hand operand is less than the right-hand operand; otherwise, <see langword="false"/>.</returns> |
| 72 | + public static bool operator <(Volume<T> left, Volume<T> right) => Compare(left, right) is -1; |
| 73 | + |
| 74 | + /// <summary> |
| 75 | + /// Determines whether the left-hand value is less than or equal to the right-hand value. |
| 76 | + /// </summary> |
| 77 | + /// <param name="left">The left-hand value to compare.</param> |
| 78 | + /// <param name="right">The right-hand value to compare.</param> |
| 79 | + /// <returns>Returns <see langword="true"/> if the left-hand operand is less than or equal to the right-hand operand; otherwise, <see langword="false"/>.</returns> |
| 80 | + public static bool operator <=(Volume<T> left, Volume<T> right) => Compare(left, right) is -1 or 0; |
| 81 | +} |
0 commit comments