From aa272d2c3554fb70f6c9b9eec039883ff1e45374 Mon Sep 17 00:00:00 2001 From: Muximize Date: Thu, 23 Jul 2026 17:10:18 +0200 Subject: [PATCH] Simplify IArithmeticQuantity and put ILinearQuantity in its own file --- UnitsNet/IArithmeticQuantity.cs | 59 ++---------------------------- UnitsNet/ILinearQuantity.cs | 62 ++++++++++++++++++++++++++++++++ UnitsNet/ILogarithmicQuantity.cs | 2 +- 3 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 UnitsNet/ILinearQuantity.cs diff --git a/UnitsNet/IArithmeticQuantity.cs b/UnitsNet/IArithmeticQuantity.cs index bd044b2070..0e14ce6350 100644 --- a/UnitsNet/IArithmeticQuantity.cs +++ b/UnitsNet/IArithmeticQuantity.cs @@ -1,69 +1,14 @@ // Licensed under MIT No Attribution, see LICENSE file at the root. // Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. -#if NET +#if NET7_0_OR_GREATER using System.Numerics; #endif namespace UnitsNet; /// -/// Represents a quantity that has both magnitude and direction, supporting various arithmetic operations and -/// comparisons. -/// -/// -/// This interface defines standard linear arithmetic operations such as addition, subtraction, multiplication, and -/// division. -/// These types of quantities naturally support comparison operations with either absolute or relative tolerance, which -/// is useful for determining equality within a certain margin of error. -/// -/// For more information, see the Wikipedia page on -/// -/// Dimensional -/// Analysis -/// -/// . -/// -/// -/// The type that implements this interface. -public interface ILinearQuantity : IQuantityOfType, IArithmeticQuantity -#if NET7_0_OR_GREATER - , IAdditiveIdentity -#endif - where TSelf : ILinearQuantity -{ -#if NET7_0_OR_GREATER - /// - /// The zero value of this quantity. - /// - static abstract TSelf Zero { get; } - - static TSelf IAdditiveIdentity.AdditiveIdentity - { - get => TSelf.Zero; - } - -#endif -} - -/// -/// An with a strongly typed unit enum. -/// -/// -/// This interface represents linear quantities with known unit enum types, and (in .NET 7+) implements generic math -/// interfaces for arithmetic operations. -/// -/// The type itself, for the CRT pattern. -/// The underlying unit enum type. -public interface ILinearQuantity : IArithmeticQuantity, ILinearQuantity - where TSelf : ILinearQuantity - where TUnitType : struct, Enum -{ -} - -/// -/// An that (in .NET 7+) implements generic math interfaces for arithmetic -/// operations. +/// A quantity that (in .NET 7+) implements generic math interfaces for arithmetic operations. /// /// The type itself, for the CRT pattern. /// The underlying unit enum type. diff --git a/UnitsNet/ILinearQuantity.cs b/UnitsNet/ILinearQuantity.cs new file mode 100644 index 0000000000..983319f2b3 --- /dev/null +++ b/UnitsNet/ILinearQuantity.cs @@ -0,0 +1,62 @@ +// Licensed under MIT No Attribution, see LICENSE file at the root. +// Copyright 2013 Andreas Gullberg Larsen (andreas.larsen84@gmail.com). Maintained at https://github.com/angularsen/UnitsNet. + +#if NET7_0_OR_GREATER +using System.Numerics; +#endif + +namespace UnitsNet; + +/// +/// An with a strongly typed unit enum. +/// +/// +/// This interface represents linear quantities with known unit enum types, and (in .NET 7+) implements generic math +/// interfaces for arithmetic operations. +/// +/// The type itself, for the CRT pattern. +/// The underlying unit enum type. +public interface ILinearQuantity : IArithmeticQuantity, ILinearQuantity + where TSelf : ILinearQuantity + where TUnitType : struct, Enum +{ +} + +/// +/// Represents a quantity that has both magnitude and direction, supporting various arithmetic operations and +/// comparisons. +/// +/// +/// This interface defines standard linear arithmetic operations such as addition, subtraction, multiplication, and +/// division. +/// These types of quantities naturally support comparison operations with either absolute or relative tolerance, which +/// is useful for determining equality within a certain margin of error. +/// +/// For more information, see the Wikipedia page on +/// +/// Dimensional +/// Analysis +/// +/// . +/// +/// +/// The type that implements this interface. +public interface ILinearQuantity : IQuantityOfType, IArithmeticQuantity +#if NET7_0_OR_GREATER + , IAdditiveIdentity +#endif + where TSelf : ILinearQuantity +{ +#if NET7_0_OR_GREATER + /// + /// The zero value of this quantity. + /// + static abstract TSelf Zero { get; } + + static TSelf IAdditiveIdentity.AdditiveIdentity + { + get => TSelf.Zero; + } + +#endif +} diff --git a/UnitsNet/ILogarithmicQuantity.cs b/UnitsNet/ILogarithmicQuantity.cs index d350e5961c..e6d4b8d5a5 100644 --- a/UnitsNet/ILogarithmicQuantity.cs +++ b/UnitsNet/ILogarithmicQuantity.cs @@ -10,7 +10,7 @@ namespace UnitsNet; /// /// The type itself, for the CRT pattern. /// The underlying unit enum type. -public interface ILogarithmicQuantity : IQuantity, ILogarithmicQuantity +public interface ILogarithmicQuantity : IArithmeticQuantity, ILogarithmicQuantity where TSelf : ILogarithmicQuantity where TUnitType : struct, Enum {