|
| 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 Pressure<T> |
| 21 | +{ |
| 22 | + /// <summary> |
| 23 | + /// Compares two <see cref="Pressure{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> |
| 29 | + /// Returns a value that indicates the relative order of the values being compared. |
| 30 | + /// The return value is less than zero if <paramref name="left"/> is less than <paramref name="right"/>, |
| 31 | + /// zero if <paramref name="left"/> equals <paramref name="right"/>, |
| 32 | + /// or greater than zero if <paramref name="left"/> is greater than <paramref name="right"/>. |
| 33 | + /// </returns> |
| 34 | + public static int Compare(Pressure<T> left, Pressure<T> right) => left.QuectoPascals.CompareTo(right.QuectoPascals); |
| 35 | + |
| 36 | + /// <summary> |
| 37 | + /// Compares the current instance with another object of the same type and returns an integer that indicates |
| 38 | + /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the |
| 39 | + /// other object. |
| 40 | + /// </summary> |
| 41 | + /// <param name="other">An object to compare with this instance.</param> |
| 42 | + /// <returns> |
| 43 | + /// Returns a value that indicates the relative order of the values being compared. |
| 44 | + /// The return value is less than zero if the current instance is less than <paramref name="other"/>, |
| 45 | + /// zero if the current instance equals <paramref name="other"/>, |
| 46 | + /// or greater than zero if the current instance is greater than <paramref name="other"/>. |
| 47 | + /// </returns> |
| 48 | + public int CompareTo(Pressure<T> other) => Compare(this, other); |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Compares the current instance with another object of the same type and returns an integer that indicates |
| 52 | + /// whether the current instance precedes, follows, or occurs in the same position in the sort order as the |
| 53 | + /// other object. |
| 54 | + /// </summary> |
| 55 | + /// <param name="obj">An object to compare with this instance.</param> |
| 56 | + /// <returns>Returns a value that indicates the relative order of the objects being compared.</returns> |
| 57 | + // ReSharper disable once HeapView.BoxingAllocation |
| 58 | + public int CompareTo(object? obj) => this.CompareToObject(obj); |
| 59 | + |
| 60 | + /// <summary> |
| 61 | + /// Determines whether the left-hand value is greater than the right-hand value. |
| 62 | + /// </summary> |
| 63 | + /// <param name="left">The left-hand value to compare.</param> |
| 64 | + /// <param name="right">The right-hand value to compare.</param> |
| 65 | + /// <returns> |
| 66 | + /// Returns <see langword="true"/> if the left-hand value is greater than the right-hand value; |
| 67 | + /// otherwise, <see langword="false"/>. |
| 68 | + /// </returns> |
| 69 | + public static bool operator >(Pressure<T> left, Pressure<T> right) => Compare(left, right) is 1; |
| 70 | + |
| 71 | + /// <summary> |
| 72 | + /// Determines whether the left-hand value is greater than or equal to the right-hand value. |
| 73 | + /// </summary> |
| 74 | + /// <param name="left">The left-hand value to compare.</param> |
| 75 | + /// <param name="right">The right-hand value to compare.</param> |
| 76 | + /// <returns> |
| 77 | + /// Returns <see langword="true"/> if the left-hand value is greater than or equal to the right-hand value; |
| 78 | + /// otherwise, <see langword="false"/>. |
| 79 | + /// </returns> |
| 80 | + public static bool operator >=(Pressure<T> left, Pressure<T> right) => Compare(left, right) is 1 or 0; |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// Determines whether the left-hand value is less than the right-hand value. |
| 84 | + /// </summary> |
| 85 | + /// <param name="left">The left-hand value to compare.</param> |
| 86 | + /// <param name="right">The right-hand value to compare.</param> |
| 87 | + /// <returns> |
| 88 | + /// Returns <see langword="true"/> if the left-hand value is less than the right-hand value; |
| 89 | + /// otherwise, <see langword="false"/>. |
| 90 | + /// </returns> |
| 91 | + public static bool operator <(Pressure<T> left, Pressure<T> right) => Compare(left, right) is -1; |
| 92 | + |
| 93 | + /// <summary> |
| 94 | + /// Determines whether the left-hand value is less than or equal to the right-hand value. |
| 95 | + /// </summary> |
| 96 | + /// <param name="left">The left-hand value to compare.</param> |
| 97 | + /// <param name="right">The right-hand value to compare.</param> |
| 98 | + /// <returns> |
| 99 | + /// Returns <see langword="true"/> if the left-hand value is less than or equal to the right-hand value; |
| 100 | + /// otherwise, <see langword="false"/>. |
| 101 | + /// </returns> |
| 102 | + public static bool operator <=(Pressure<T> left, Pressure<T> right) => Compare(left, right) is -1 or 0; |
| 103 | +} |
0 commit comments