diff --git a/CLAUDE.md b/CLAUDE.md index 40b8ac74..ccd5bcb1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -42,7 +42,7 @@ The opt-in lives in `.sonarlint/sonar-local.props` (analyzer package) and `.sona | `Semantics.Paths` | Polymorphic file system path types (`IPath`, `IFilePath`, `IDirectoryPath`, …). | | `Semantics.Music` | Immutable musical value types (`Pitch`, `Interval`, `Scale`, `Chord`, `Key`, `Duration`, `TimeSignature`) plus an analysis aggregate layer (`Progression`, `Section`, `Arrangement`, `Form`) computing roman numerals, cadences, key inference, chromatic identification, and named forms. Targets `net8.0`–`net10.0` + `netstandard2.0`/`netstandard2.1`. | | `Semantics.Color` | Physically-grounded color types. Canonical linear-RGB `Color` hub plus color-space satellites (`Srgb`, `Hsl`, `Hsv`, `Oklab`, `Oklch`); every type converts to and from every other, routed through the nearest shared hub (`Srgb` within the sRGB family, `Oklab` within the perceptual family, linear `Color` across families) so no conversion takes a redundant gamma round-trip. Also WCAG accessibility tooling, HSL/perceptual adjustment operations (lighten/saturate/hue/invert), and `NamedColors`. Targets `net8.0`–`net10.0` + `netstandard2.0`/`netstandard2.1`. | -| `Semantics.Quantities` | Hand-written runtime types (`PhysicalQuantity`, `IVector0`..`IVector4`, `UnitSystem`) plus generator output under `Generated/`. | +| `Semantics.Quantities` | Hand-written runtime types (`IPhysicalQuantity`, `PhysicalQuantityCore`, `IVector0`..`IVector4`, `UnitSystem`) plus generator output under `Generated/`. Every generated quantity is a `readonly record struct`. | | `Semantics.SourceGenerators` | Roslyn incremental generators that emit quantity types, units, conversions, magnitudes, physical constants, and storage-type helpers from metadata. Only the physics-specific half lives here — `Models/`, `Metadata/`, `Generators/`, and the bindings in `SemanticsGenerator`/`SemanticsDiagnostics`/`Emit`. The C# syntax templates come from `ktsu.CodeBlocker.Templates`; the metadata-driven generator base, metadata loading and the diagnostic catalogue come from `ktsu.SourceGeneratorToolkit` (#181, #192). | | `Semantics.Quantities.{Double,Float,Decimal}` | Props-only satellite packages. Each ships a `buildTransitive` props file (generated by `scripts/Generate-AliasProps.ps1`) that injects global-using aliases binding every quantity to one storage type, so consumers write `Mass` instead of `Mass`. | | `Semantics.Test` | MSTest project covering all of the above. | diff --git a/Semantics.Quantities/AudioEngineering/Gain.cs b/Semantics.Quantities/AudioEngineering/Gain.cs index e29c9e4e..ebb54aec 100644 --- a/Semantics.Quantities/AudioEngineering/Gain.cs +++ b/Semantics.Quantities/AudioEngineering/Gain.cs @@ -15,7 +15,7 @@ namespace ktsu.Semantics.Quantities; /// using the amplitude (field) convention dB = 20·log10(gain). As a Vector0 /// magnitude, gain is non-negative — polarity inversion is a separate concern. /// -public partial record Gain +public readonly partial record struct Gain where T : struct, INumber { /// Gets unity gain (a factor of one). @@ -44,12 +44,7 @@ public partial record Gain [System.Diagnostics.CodeAnalysis.SuppressMessage( "Usage", "CA2225:Operator overloads have named alternates", Justification = "Multiply is provided as the named alternate.")] - public static Gain operator *(Gain left, Gain right) - { - ArgumentNullException.ThrowIfNull(left); - ArgumentNullException.ThrowIfNull(right); - return Create(left.Value * right.Value); - } + public static Gain operator *(Gain left, Gain right) => Create(left.Value * right.Value); /// Multiplies two gains (friendly alternate for operator *). /// The first gain. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AbsorbedDose.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AbsorbedDose.g.cs index b5b671de..5fc5c1ef 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AbsorbedDose.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AbsorbedDose.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AbsorbedDose dimension. /// /// The numeric storage type. -public partial record AbsorbedDose : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AbsorbedDose : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AbsorbedDose Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AbsorbedDose; + public DimensionInfo Dimension => PhysicalDimensions.AbsorbedDose; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AbsorbedDose Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AbsorbedDose operator +(AbsorbedDose left, AbsorbedDose right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AbsorbedDose operator -(AbsorbedDose value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AbsorbedDose operator *(AbsorbedDose left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AbsorbedDose operator *(T left, AbsorbedDose right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AbsorbedDose operator /(AbsorbedDose left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AbsorbedDose left, AbsorbedDose right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AbsorbedDose left, AbsorbedDose right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AbsorbedDose left, AbsorbedDose right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AbsorbedDose left, AbsorbedDose right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AbsorbedDose left, AbsorbedDose right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Gray. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration1D.g.cs index 10cb7301..52ab0bb6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Acceleration dimension. /// /// The numeric storage type. -public partial record Acceleration1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Acceleration1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Acceleration1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Acceleration; + public DimensionInfo Dimension => PhysicalDimensions.Acceleration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Acceleration1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator +(Acceleration1D left, Acceleration1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator -(Acceleration1D left, Acceleration1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator -(Acceleration1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator *(Acceleration1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator *(T left, Acceleration1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Acceleration1D operator /(Acceleration1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Acceleration1D left, Acceleration1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Acceleration1D left, Acceleration1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Acceleration1D left, Acceleration1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Acceleration1D left, Acceleration1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Acceleration1D left, Acceleration1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondSquared. @@ -50,12 +129,12 @@ public partial record Acceleration1D : PhysicalQuantity, T> /// Multiplies Acceleration1D by Duration to produce Velocity1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Velocity1D operator *(Acceleration1D left, Duration right) => Multiply>(left, right); + public static Velocity1D operator *(Acceleration1D left, Duration right) => Velocity1D.Create(left.Quantity * right.Quantity); /// /// Divides Acceleration1D by Duration to produce Jerk1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Jerk1D operator /(Acceleration1D left, Duration right) => Divide>(left, right); + public static Jerk1D operator /(Acceleration1D left, Duration right) => Jerk1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration2D.g.cs index 64edf760..65b5bfba 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Acceleration. /// /// The numeric component type. -public partial record Acceleration2D : IVector2, T> +public readonly partial record struct Acceleration2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration3D.g.cs index e64fe013..eaa4ed34 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Acceleration. /// /// The numeric component type. -public partial record Acceleration3D : IVector3, T> +public readonly partial record struct Acceleration3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration4D.g.cs index a0f4fb20..9706f114 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Acceleration4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Acceleration. /// /// The numeric component type. -public partial record Acceleration4D : IVector4, T> +public readonly partial record struct Acceleration4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AccelerationMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AccelerationMagnitude.g.cs index 7b656a16..afc475aa 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AccelerationMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AccelerationMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Acceleration dimension. /// /// The numeric storage type. -public partial record AccelerationMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AccelerationMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AccelerationMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Acceleration; + public DimensionInfo Dimension => PhysicalDimensions.Acceleration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AccelerationMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AccelerationMagnitude operator +(AccelerationMagnitude left, AccelerationMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AccelerationMagnitude operator -(AccelerationMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AccelerationMagnitude operator *(AccelerationMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AccelerationMagnitude operator *(T left, AccelerationMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AccelerationMagnitude operator /(AccelerationMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AccelerationMagnitude left, AccelerationMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AccelerationMagnitude left, AccelerationMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AccelerationMagnitude left, AccelerationMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AccelerationMagnitude left, AccelerationMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AccelerationMagnitude left, AccelerationMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondSquared. @@ -53,24 +128,24 @@ public partial record AccelerationMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(AccelerationMagnitude left, Mass right) => Multiply>(left, right); + public static ForceMagnitude operator *(AccelerationMagnitude left, Mass right) => ForceMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies AccelerationMagnitude by Duration to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator *(AccelerationMagnitude left, Duration right) => Multiply>(left, right); + public static Speed operator *(AccelerationMagnitude left, Duration right) => Speed.Create(left.Quantity * right.Quantity); /// /// Divides AccelerationMagnitude by Duration to produce JerkMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static JerkMagnitude operator /(AccelerationMagnitude left, Duration right) => Divide>(left, right); + public static JerkMagnitude operator /(AccelerationMagnitude left, Duration right) => JerkMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides AccelerationMagnitude by JerkMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(AccelerationMagnitude left, JerkMagnitude right) => Divide>(left, right); + public static Duration operator /(AccelerationMagnitude left, JerkMagnitude right) => Duration.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AcousticImpedance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AcousticImpedance.g.cs index 6d641f27..d1dd5526 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AcousticImpedance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AcousticImpedance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AcousticImpedance dimension. /// /// The numeric storage type. -public partial record AcousticImpedance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AcousticImpedance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AcousticImpedance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AcousticImpedance; + public DimensionInfo Dimension => PhysicalDimensions.AcousticImpedance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AcousticImpedance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AcousticImpedance operator +(AcousticImpedance left, AcousticImpedance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AcousticImpedance operator -(AcousticImpedance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AcousticImpedance operator *(AcousticImpedance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AcousticImpedance operator *(T left, AcousticImpedance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AcousticImpedance operator /(AcousticImpedance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AcousticImpedance left, AcousticImpedance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AcousticImpedance left, AcousticImpedance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AcousticImpedance left, AcousticImpedance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AcousticImpedance left, AcousticImpedance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AcousticImpedance left, AcousticImpedance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in PascalSecondPerMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ActivationEnergy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ActivationEnergy.g.cs index 73f7b013..be969b43 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ActivationEnergy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ActivationEnergy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ActivationEnergy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ActivationEnergy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ActivationEnergy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + public DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ActivationEnergy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ActivationEnergy operator +(ActivationEnergy left, ActivationEnergy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ActivationEnergy operator -(ActivationEnergy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ActivationEnergy operator *(ActivationEnergy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ActivationEnergy operator *(T left, ActivationEnergy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ActivationEnergy operator /(ActivationEnergy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ActivationEnergy left, ActivationEnergy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ActivationEnergy left, ActivationEnergy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ActivationEnergy left, ActivationEnergy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ActivationEnergy left, ActivationEnergy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ActivationEnergy left, ActivationEnergy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ActivationEnergy from a value in JoulePerMole. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Admittance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Admittance.g.cs index 2a74d8db..62d10837 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Admittance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Admittance.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Admittance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Admittance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Admittance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricConductance; + public DimensionInfo Dimension => PhysicalDimensions.ElectricConductance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Admittance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Admittance operator +(Admittance left, Admittance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Admittance operator -(Admittance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Admittance operator *(Admittance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Admittance operator *(T left, Admittance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Admittance operator /(Admittance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Admittance left, Admittance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Admittance left, Admittance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Admittance left, Admittance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Admittance left, Admittance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Admittance left, Admittance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Admittance from a value in Siemens. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Airspeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Airspeed.g.cs index f7bd8c5a..2e816a74 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Airspeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Airspeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Airspeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Airspeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Airspeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Airspeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Airspeed operator +(Airspeed left, Airspeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Airspeed operator -(Airspeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Airspeed operator *(Airspeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Airspeed operator *(T left, Airspeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Airspeed operator /(Airspeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Airspeed left, Airspeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Airspeed left, Airspeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Airspeed left, Airspeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Airspeed left, Airspeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Airspeed left, Airspeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Airspeed from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Altitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Altitude.g.cs index 5f516a0e..d2331365 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Altitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Altitude.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Altitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Altitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Altitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Altitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Altitude operator +(Altitude left, Altitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Altitude operator -(Altitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Altitude operator *(Altitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Altitude operator *(T left, Altitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Altitude operator /(Altitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Altitude left, Altitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Altitude left, Altitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Altitude left, Altitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Altitude left, Altitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Altitude left, Altitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Altitude from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AmountOfSubstance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AmountOfSubstance.g.cs index 5e21ca1b..a849b461 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AmountOfSubstance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AmountOfSubstance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AmountOfSubstance dimension. /// /// The numeric storage type. -public partial record AmountOfSubstance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AmountOfSubstance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AmountOfSubstance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AmountOfSubstance; + public DimensionInfo Dimension => PhysicalDimensions.AmountOfSubstance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AmountOfSubstance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AmountOfSubstance operator +(AmountOfSubstance left, AmountOfSubstance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AmountOfSubstance operator -(AmountOfSubstance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AmountOfSubstance operator *(AmountOfSubstance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AmountOfSubstance operator *(T left, AmountOfSubstance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AmountOfSubstance operator /(AmountOfSubstance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AmountOfSubstance left, AmountOfSubstance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AmountOfSubstance left, AmountOfSubstance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AmountOfSubstance left, AmountOfSubstance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AmountOfSubstance left, AmountOfSubstance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AmountOfSubstance left, AmountOfSubstance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Mole. @@ -61,36 +136,36 @@ public partial record AmountOfSubstance : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Concentration operator /(AmountOfSubstance left, Volume right) => Divide>(left, right); + public static Concentration operator /(AmountOfSubstance left, Volume right) => Concentration.Create(left.Quantity / right.Quantity); /// /// Divides AmountOfSubstance by Concentration to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator /(AmountOfSubstance left, Concentration right) => Divide>(left, right); + public static Volume operator /(AmountOfSubstance left, Concentration right) => Volume.Create(left.Quantity / right.Quantity); /// /// Multiplies AmountOfSubstance by MolarMass to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(AmountOfSubstance left, MolarMass right) => Multiply>(left, right); + public static Mass operator *(AmountOfSubstance left, MolarMass right) => Mass.Create(left.Quantity * right.Quantity); /// /// Divides AmountOfSubstance by Duration to produce CatalyticActivity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CatalyticActivity operator /(AmountOfSubstance left, Duration right) => Divide>(left, right); + public static CatalyticActivity operator /(AmountOfSubstance left, Duration right) => CatalyticActivity.Create(left.Quantity / right.Quantity); /// /// Divides AmountOfSubstance by CatalyticActivity to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(AmountOfSubstance left, CatalyticActivity right) => Divide>(left, right); + public static Duration operator /(AmountOfSubstance left, CatalyticActivity right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies AmountOfSubstance by MolarEnergy to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(AmountOfSubstance left, MolarEnergy right) => Multiply>(left, right); + public static Energy operator *(AmountOfSubstance left, MolarEnergy right) => Energy.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Angle.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Angle.g.cs index f7ea0051..c241248e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Angle.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Angle.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AngularDisplacement dimension. /// /// The numeric storage type. -public partial record Angle : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Angle : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Angle Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Angle Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Angle operator +(Angle left, Angle right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Angle operator -(Angle value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Angle operator *(Angle left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Angle operator *(T left, Angle right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Angle operator /(Angle left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Angle left, Angle right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Angle left, Angle right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Angle left, Angle right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Angle left, Angle right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Angle left, Angle right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Radian. @@ -77,18 +152,18 @@ public partial record Angle : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularSpeed operator /(Angle left, Duration right) => Divide>(left, right); + public static AngularSpeed operator /(Angle left, Duration right) => AngularSpeed.Create(left.Quantity / right.Quantity); /// /// Divides Angle by AngularSpeed to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Angle left, AngularSpeed right) => Divide>(left, right); + public static Duration operator /(Angle left, AngularSpeed right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies Angle by TorqueMagnitude to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Angle left, TorqueMagnitude right) => Multiply>(left, right); + public static Energy operator *(Angle left, TorqueMagnitude right) => Energy.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration1D.g.cs index a8f1c20d..737aa1cb 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the AngularAcceleration dimension. /// /// The numeric storage type. -public partial record AngularAcceleration1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct AngularAcceleration1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularAcceleration1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularAcceleration; + public DimensionInfo Dimension => PhysicalDimensions.AngularAcceleration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularAcceleration1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator +(AngularAcceleration1D left, AngularAcceleration1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator -(AngularAcceleration1D left, AngularAcceleration1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator -(AngularAcceleration1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator *(AngularAcceleration1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator *(T left, AngularAcceleration1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAcceleration1D operator /(AngularAcceleration1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularAcceleration1D left, AngularAcceleration1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularAcceleration1D left, AngularAcceleration1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularAcceleration1D left, AngularAcceleration1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularAcceleration1D left, AngularAcceleration1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularAcceleration1D left, AngularAcceleration1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecondSquared. @@ -43,12 +122,12 @@ public partial record AngularAcceleration1D : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularVelocity1D operator *(AngularAcceleration1D left, Duration right) => Multiply>(left, right); + public static AngularVelocity1D operator *(AngularAcceleration1D left, Duration right) => AngularVelocity1D.Create(left.Quantity * right.Quantity); /// /// Divides AngularAcceleration1D by Duration to produce AngularJerk1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularJerk1D operator /(AngularAcceleration1D left, Duration right) => Divide>(left, right); + public static AngularJerk1D operator /(AngularAcceleration1D left, Duration right) => AngularJerk1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration3D.g.cs index a4111169..4c3bd138 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAcceleration3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of AngularAcceleration. /// /// The numeric component type. -public partial record AngularAcceleration3D : IVector3, T> +public readonly partial record struct AngularAcceleration3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAccelerationMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAccelerationMagnitude.g.cs index f1d8c566..4083a9cf 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAccelerationMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularAccelerationMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AngularAcceleration dimension. /// /// The numeric storage type. -public partial record AngularAccelerationMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AngularAccelerationMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularAccelerationMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularAcceleration; + public DimensionInfo Dimension => PhysicalDimensions.AngularAcceleration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularAccelerationMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAccelerationMagnitude operator +(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAccelerationMagnitude operator -(AngularAccelerationMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAccelerationMagnitude operator *(AngularAccelerationMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAccelerationMagnitude operator *(T left, AngularAccelerationMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularAccelerationMagnitude operator /(AngularAccelerationMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecondSquared. @@ -45,24 +120,24 @@ public partial record AngularAccelerationMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularSpeed operator *(AngularAccelerationMagnitude left, Duration right) => Multiply>(left, right); + public static AngularSpeed operator *(AngularAccelerationMagnitude left, Duration right) => AngularSpeed.Create(left.Quantity * right.Quantity); /// /// Divides AngularAccelerationMagnitude by Duration to produce AngularJerkMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularJerkMagnitude operator /(AngularAccelerationMagnitude left, Duration right) => Divide>(left, right); + public static AngularJerkMagnitude operator /(AngularAccelerationMagnitude left, Duration right) => AngularJerkMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides AngularAccelerationMagnitude by AngularJerkMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(AngularAccelerationMagnitude left, AngularJerkMagnitude right) => Divide>(left, right); + public static Duration operator /(AngularAccelerationMagnitude left, AngularJerkMagnitude right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies AngularAccelerationMagnitude by MomentOfInertia to produce TorqueMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static TorqueMagnitude operator *(AngularAccelerationMagnitude left, MomentOfInertia right) => Multiply>(left, right); + public static TorqueMagnitude operator *(AngularAccelerationMagnitude left, MomentOfInertia right) => TorqueMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularDisplacement3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularDisplacement3D.g.cs index 1b49e47f..59f79fe9 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularDisplacement3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularDisplacement3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of AngularDisplacement. /// /// The numeric component type. -public partial record AngularDisplacement3D : IVector3, T> +public readonly partial record struct AngularDisplacement3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk1D.g.cs index f1ab6bd0..5597b898 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the AngularJerk dimension. /// /// The numeric storage type. -public partial record AngularJerk1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct AngularJerk1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularJerk1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularJerk; + public DimensionInfo Dimension => PhysicalDimensions.AngularJerk; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularJerk1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator +(AngularJerk1D left, AngularJerk1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator -(AngularJerk1D left, AngularJerk1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator -(AngularJerk1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator *(AngularJerk1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator *(T left, AngularJerk1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerk1D operator /(AngularJerk1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularJerk1D left, AngularJerk1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularJerk1D left, AngularJerk1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularJerk1D left, AngularJerk1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularJerk1D left, AngularJerk1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularJerk1D left, AngularJerk1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecondCubed. @@ -43,6 +122,6 @@ public partial record AngularJerk1D : PhysicalQuantity, T>, /// Multiplies AngularJerk1D by Duration to produce AngularAcceleration1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAcceleration1D operator *(AngularJerk1D left, Duration right) => Multiply>(left, right); + public static AngularAcceleration1D operator *(AngularJerk1D left, Duration right) => AngularAcceleration1D.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk3D.g.cs index bda7418f..40ceb035 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerk3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of AngularJerk. /// /// The numeric component type. -public partial record AngularJerk3D : IVector3, T> +public readonly partial record struct AngularJerk3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerkMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerkMagnitude.g.cs index 9916ad7c..dca935ec 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerkMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularJerkMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AngularJerk dimension. /// /// The numeric storage type. -public partial record AngularJerkMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AngularJerkMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularJerkMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularJerk; + public DimensionInfo Dimension => PhysicalDimensions.AngularJerk; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularJerkMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerkMagnitude operator +(AngularJerkMagnitude left, AngularJerkMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerkMagnitude operator -(AngularJerkMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerkMagnitude operator *(AngularJerkMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerkMagnitude operator *(T left, AngularJerkMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularJerkMagnitude operator /(AngularJerkMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularJerkMagnitude left, AngularJerkMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularJerkMagnitude left, AngularJerkMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularJerkMagnitude left, AngularJerkMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularJerkMagnitude left, AngularJerkMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularJerkMagnitude left, AngularJerkMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecondCubed. @@ -45,6 +120,6 @@ public partial record AngularJerkMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAccelerationMagnitude operator *(AngularJerkMagnitude left, Duration right) => Multiply>(left, right); + public static AngularAccelerationMagnitude operator *(AngularJerkMagnitude left, Duration right) => AngularAccelerationMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum1D.g.cs index d4383ff5..fa8004a7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the AngularMomentum dimension. /// /// The numeric storage type. -public partial record AngularMomentum1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct AngularMomentum1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularMomentum1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularMomentum; + public DimensionInfo Dimension => PhysicalDimensions.AngularMomentum; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularMomentum1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator +(AngularMomentum1D left, AngularMomentum1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator -(AngularMomentum1D left, AngularMomentum1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator -(AngularMomentum1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator *(AngularMomentum1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator *(T left, AngularMomentum1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentum1D operator /(AngularMomentum1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularMomentum1D left, AngularMomentum1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularMomentum1D left, AngularMomentum1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularMomentum1D left, AngularMomentum1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularMomentum1D left, AngularMomentum1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularMomentum1D left, AngularMomentum1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramMeterSquaredPerSecond. @@ -43,6 +122,6 @@ public partial record AngularMomentum1D : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Torque1D operator /(AngularMomentum1D left, Duration right) => Divide>(left, right); + public static Torque1D operator /(AngularMomentum1D left, Duration right) => Torque1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum3D.g.cs index 7e3bfd5b..bd2920c6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentum3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of AngularMomentum. /// /// The numeric component type. -public partial record AngularMomentum3D : IVector3, T> +public readonly partial record struct AngularMomentum3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentumMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentumMagnitude.g.cs index 9fa26ecb..c34a652a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentumMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularMomentumMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AngularMomentum dimension. /// /// The numeric storage type. -public partial record AngularMomentumMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AngularMomentumMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularMomentumMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularMomentum; + public DimensionInfo Dimension => PhysicalDimensions.AngularMomentum; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularMomentumMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentumMagnitude operator +(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentumMagnitude operator -(AngularMomentumMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentumMagnitude operator *(AngularMomentumMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentumMagnitude operator *(T left, AngularMomentumMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularMomentumMagnitude operator /(AngularMomentumMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramMeterSquaredPerSecond. @@ -45,18 +120,18 @@ public partial record AngularMomentumMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static TorqueMagnitude operator /(AngularMomentumMagnitude left, Duration right) => Divide>(left, right); + public static TorqueMagnitude operator /(AngularMomentumMagnitude left, Duration right) => TorqueMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides AngularMomentumMagnitude by AngularSpeed to produce MomentOfInertia. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentOfInertia operator /(AngularMomentumMagnitude left, AngularSpeed right) => Divide>(left, right); + public static MomentOfInertia operator /(AngularMomentumMagnitude left, AngularSpeed right) => MomentOfInertia.Create(left.Quantity / right.Quantity); /// /// Divides AngularMomentumMagnitude by MomentOfInertia to produce AngularSpeed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularSpeed operator /(AngularMomentumMagnitude left, MomentOfInertia right) => Divide>(left, right); + public static AngularSpeed operator /(AngularMomentumMagnitude left, MomentOfInertia right) => AngularSpeed.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularSpeed.g.cs index f139761a..e6e8cd13 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularSpeed.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the AngularVelocity dimension. /// /// The numeric storage type. -public partial record AngularSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AngularSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularVelocity; + public DimensionInfo Dimension => PhysicalDimensions.AngularVelocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularSpeed operator +(AngularSpeed left, AngularSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularSpeed operator -(AngularSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularSpeed operator *(AngularSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularSpeed operator *(T left, AngularSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularSpeed operator /(AngularSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularSpeed left, AngularSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularSpeed left, AngularSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularSpeed left, AngularSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularSpeed left, AngularSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularSpeed left, AngularSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecond. @@ -53,24 +128,24 @@ public partial record AngularSpeed : PhysicalQuantity, T>, IV /// Multiplies AngularSpeed by Duration to produce Angle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Angle operator *(AngularSpeed left, Duration right) => Multiply>(left, right); + public static Angle operator *(AngularSpeed left, Duration right) => Angle.Create(left.Quantity * right.Quantity); /// /// Divides AngularSpeed by Duration to produce AngularAccelerationMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAccelerationMagnitude operator /(AngularSpeed left, Duration right) => Divide>(left, right); + public static AngularAccelerationMagnitude operator /(AngularSpeed left, Duration right) => AngularAccelerationMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides AngularSpeed by AngularAccelerationMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(AngularSpeed left, AngularAccelerationMagnitude right) => Divide>(left, right); + public static Duration operator /(AngularSpeed left, AngularAccelerationMagnitude right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies AngularSpeed by MomentOfInertia to produce AngularMomentumMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentumMagnitude operator *(AngularSpeed left, MomentOfInertia right) => Multiply>(left, right); + public static AngularMomentumMagnitude operator *(AngularSpeed left, MomentOfInertia right) => AngularMomentumMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity1D.g.cs index 97295664..6913d2a1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the AngularVelocity dimension. /// /// The numeric storage type. -public partial record AngularVelocity1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct AngularVelocity1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AngularVelocity1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularVelocity; + public DimensionInfo Dimension => PhysicalDimensions.AngularVelocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AngularVelocity1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator +(AngularVelocity1D left, AngularVelocity1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator -(AngularVelocity1D left, AngularVelocity1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator -(AngularVelocity1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator *(AngularVelocity1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator *(T left, AngularVelocity1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AngularVelocity1D operator /(AngularVelocity1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AngularVelocity1D left, AngularVelocity1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AngularVelocity1D left, AngularVelocity1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AngularVelocity1D left, AngularVelocity1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AngularVelocity1D left, AngularVelocity1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AngularVelocity1D left, AngularVelocity1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in RadianPerSecond. @@ -50,12 +129,12 @@ public partial record AngularVelocity1D : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SignedAngle operator *(AngularVelocity1D left, Duration right) => Multiply>(left, right); + public static SignedAngle operator *(AngularVelocity1D left, Duration right) => SignedAngle.Create(left.Quantity * right.Quantity); /// /// Divides AngularVelocity1D by Duration to produce AngularAcceleration1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAcceleration1D operator /(AngularVelocity1D left, Duration right) => Divide>(left, right); + public static AngularAcceleration1D operator /(AngularVelocity1D left, Duration right) => AngularAcceleration1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity3D.g.cs index 61de2e44..738bfac5 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AngularVelocity3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of AngularVelocity. /// /// The numeric component type. -public partial record AngularVelocity3D : IVector3, T> +public readonly partial record struct AngularVelocity3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ApertureAngle.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ApertureAngle.g.cs index 7f065b70..e17ade2f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ApertureAngle.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ApertureAngle.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ApertureAngle : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ApertureAngle : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ApertureAngle Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ApertureAngle Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ApertureAngle operator +(ApertureAngle left, ApertureAngle right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ApertureAngle operator -(ApertureAngle value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ApertureAngle operator *(ApertureAngle left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ApertureAngle operator *(T left, ApertureAngle right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ApertureAngle operator /(ApertureAngle left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ApertureAngle left, ApertureAngle right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ApertureAngle left, ApertureAngle right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ApertureAngle left, ApertureAngle right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ApertureAngle left, ApertureAngle right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ApertureAngle left, ApertureAngle right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ApertureAngle from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Area.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Area.g.cs index 372f9db0..d99878da 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Area.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Area.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Area dimension. /// /// The numeric storage type. -public partial record Area : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Area : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Area Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Area; + public DimensionInfo Dimension => PhysicalDimensions.Area; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Area Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Area operator +(Area left, Area right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Area operator -(Area value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Area operator *(Area left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Area operator *(T left, Area right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Area operator /(Area left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Area left, Area right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Area left, Area right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Area left, Area right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Area left, Area right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Area left, Area right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in SquareMeter. @@ -101,48 +176,48 @@ public partial record Area : PhysicalQuantity, T>, IVector0, /// Divides Area by Length to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(Area left, Length right) => Divide>(left, right); + public static Length operator /(Area left, Length right) => Length.Create(left.Quantity / right.Quantity); /// /// Multiplies Area by Length to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator *(Area left, Length right) => Multiply>(left, right); + public static Volume operator *(Area left, Length right) => Volume.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by Pressure to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(Area left, Pressure right) => Multiply>(left, right); + public static ForceMagnitude operator *(Area left, Pressure right) => ForceMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by ElectricFieldMagnitude to produce ElectricFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricFlux operator *(Area left, ElectricFieldMagnitude right) => Multiply>(left, right); + public static ElectricFlux operator *(Area left, ElectricFieldMagnitude right) => ElectricFlux.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by Illuminance to produce LuminousFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static LuminousFlux operator *(Area left, Illuminance right) => Multiply>(left, right); + public static LuminousFlux operator *(Area left, Illuminance right) => LuminousFlux.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by MagneticFluxDensityMagnitude to produce MagneticFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(Area left, MagneticFluxDensityMagnitude right) => Multiply>(left, right); + public static MagneticFlux operator *(Area left, MagneticFluxDensityMagnitude right) => MagneticFlux.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by Irradiance to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(Area left, Irradiance right) => Multiply>(left, right); + public static Power operator *(Area left, Irradiance right) => Power.Create(left.Quantity * right.Quantity); /// /// Multiplies Area by Luminance to produce LuminousIntensity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static LuminousIntensity operator *(Area left, Luminance right) => Multiply>(left, right); + public static LuminousIntensity operator *(Area left, Luminance right) => LuminousIntensity.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtmosphericPressure.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtmosphericPressure.g.cs index 415f2923..5e951658 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtmosphericPressure.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtmosphericPressure.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record AtmosphericPressure : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AtmosphericPressure : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AtmosphericPressure Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AtmosphericPressure Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtmosphericPressure operator +(AtmosphericPressure left, AtmosphericPressure right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtmosphericPressure operator -(AtmosphericPressure value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtmosphericPressure operator *(AtmosphericPressure left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtmosphericPressure operator *(T left, AtmosphericPressure right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtmosphericPressure operator /(AtmosphericPressure left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AtmosphericPressure left, AtmosphericPressure right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AtmosphericPressure left, AtmosphericPressure right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AtmosphericPressure left, AtmosphericPressure right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AtmosphericPressure left, AtmosphericPressure right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AtmosphericPressure left, AtmosphericPressure right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new AtmosphericPressure from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtomicMass.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtomicMass.g.cs index 41f56c9f..9f475221 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtomicMass.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/AtomicMass.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record AtomicMass : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct AtomicMass : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static AtomicMass Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Mass; + public DimensionInfo Dimension => PhysicalDimensions.Mass; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static AtomicMass Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtomicMass operator +(AtomicMass left, AtomicMass right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtomicMass operator -(AtomicMass value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtomicMass operator *(AtomicMass left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtomicMass operator *(T left, AtomicMass right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static AtomicMass operator /(AtomicMass left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(AtomicMass left, AtomicMass right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(AtomicMass left, AtomicMass right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(AtomicMass left, AtomicMass right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(AtomicMass left, AtomicMass right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(AtomicMass left, AtomicMass right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new AtomicMass from a value in Kilogram. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bandwidth.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bandwidth.g.cs index 7d9e1b95..f4038bf1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bandwidth.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bandwidth.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Bandwidth : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Bandwidth : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Bandwidth Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Frequency; + public DimensionInfo Dimension => PhysicalDimensions.Frequency; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Bandwidth Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bandwidth operator +(Bandwidth left, Bandwidth right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bandwidth operator -(Bandwidth value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bandwidth operator *(Bandwidth left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bandwidth operator *(T left, Bandwidth right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bandwidth operator /(Bandwidth left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Bandwidth left, Bandwidth right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Bandwidth left, Bandwidth right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Bandwidth left, Bandwidth right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Bandwidth left, Bandwidth right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Bandwidth left, Bandwidth right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Bandwidth from a value in Hertz. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bearing.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bearing.g.cs index 12aa0ce9..7cf87aa5 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bearing.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Bearing.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Bearing : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Bearing : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Bearing Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Bearing Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator +(Bearing left, Bearing right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator -(Bearing left, Bearing right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator -(Bearing value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator *(Bearing left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator *(T left, Bearing right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Bearing operator /(Bearing left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Bearing left, Bearing right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Bearing left, Bearing right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Bearing left, Bearing right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Bearing left, Bearing right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Bearing left, Bearing right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Bearing from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/BulkModulus.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/BulkModulus.g.cs index 9dc8932f..8ca9ab6d 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/BulkModulus.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/BulkModulus.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record BulkModulus : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct BulkModulus : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static BulkModulus Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static BulkModulus Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static BulkModulus operator +(BulkModulus left, BulkModulus right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static BulkModulus operator -(BulkModulus value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static BulkModulus operator *(BulkModulus left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static BulkModulus operator *(T left, BulkModulus right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static BulkModulus operator /(BulkModulus left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(BulkModulus left, BulkModulus right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(BulkModulus left, BulkModulus right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(BulkModulus left, BulkModulus right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(BulkModulus left, BulkModulus right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(BulkModulus left, BulkModulus right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new BulkModulus from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacitance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacitance.g.cs index eccab1d8..b05ed0f5 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacitance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacitance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricCapacitance dimension. /// /// The numeric storage type. -public partial record Capacitance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Capacitance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Capacitance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricCapacitance; + public DimensionInfo Dimension => PhysicalDimensions.ElectricCapacitance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Capacitance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacitance operator +(Capacitance left, Capacitance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacitance operator -(Capacitance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacitance operator *(Capacitance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacitance operator *(T left, Capacitance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacitance operator /(Capacitance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Capacitance left, Capacitance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Capacitance left, Capacitance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Capacitance left, Capacitance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Capacitance left, Capacitance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Capacitance left, Capacitance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Farad. @@ -69,6 +144,6 @@ public partial record Capacitance : PhysicalQuantity, T>, IVec /// Multiplies Capacitance by VoltageMagnitude to produce ChargeMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ChargeMagnitude operator *(Capacitance left, VoltageMagnitude right) => Multiply>(left, right); + public static ChargeMagnitude operator *(Capacitance left, VoltageMagnitude right) => ChargeMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacity.g.cs index 22186762..392c87b7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Capacity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Capacity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Capacity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Capacity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Volume; + public DimensionInfo Dimension => PhysicalDimensions.Volume; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Capacity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacity operator +(Capacity left, Capacity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacity operator -(Capacity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacity operator *(Capacity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacity operator *(T left, Capacity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Capacity operator /(Capacity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Capacity left, Capacity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Capacity left, Capacity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Capacity left, Capacity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Capacity left, Capacity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Capacity left, Capacity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Capacity from a value in CubicMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CatalyticActivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CatalyticActivity.g.cs index d6252376..6136966b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CatalyticActivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CatalyticActivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the CatalyticActivity dimension. /// /// The numeric storage type. -public partial record CatalyticActivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct CatalyticActivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static CatalyticActivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.CatalyticActivity; + public DimensionInfo Dimension => PhysicalDimensions.CatalyticActivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static CatalyticActivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CatalyticActivity operator +(CatalyticActivity left, CatalyticActivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CatalyticActivity operator -(CatalyticActivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CatalyticActivity operator *(CatalyticActivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CatalyticActivity operator *(T left, CatalyticActivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CatalyticActivity operator /(CatalyticActivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(CatalyticActivity left, CatalyticActivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(CatalyticActivity left, CatalyticActivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(CatalyticActivity left, CatalyticActivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(CatalyticActivity left, CatalyticActivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(CatalyticActivity left, CatalyticActivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Katal. @@ -53,6 +128,6 @@ public partial record CatalyticActivity : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator *(CatalyticActivity left, Duration right) => Multiply>(left, right); + public static AmountOfSubstance operator *(CatalyticActivity left, Duration right) => AmountOfSubstance.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Charge.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Charge.g.cs index de8cb2cb..48148c16 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Charge.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Charge.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the ElectricCharge dimension. /// /// The numeric storage type. -public partial record Charge : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Charge : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Charge Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricCharge; + public DimensionInfo Dimension => PhysicalDimensions.ElectricCharge; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Charge Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator +(Charge left, Charge right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator -(Charge left, Charge right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator -(Charge value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator *(Charge left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator *(T left, Charge right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Charge operator /(Charge left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Charge left, Charge right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Charge left, Charge right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Charge left, Charge right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Charge left, Charge right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Charge left, Charge right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Coulomb. @@ -50,6 +129,6 @@ public partial record Charge : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Current1D operator /(Charge left, Duration right) => Divide>(left, right); + public static Current1D operator /(Charge left, Duration right) => Current1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ChargeMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ChargeMagnitude.g.cs index c761924d..39c11255 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ChargeMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ChargeMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricCharge dimension. /// /// The numeric storage type. -public partial record ChargeMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ChargeMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ChargeMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricCharge; + public DimensionInfo Dimension => PhysicalDimensions.ElectricCharge; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ChargeMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ChargeMagnitude operator +(ChargeMagnitude left, ChargeMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ChargeMagnitude operator -(ChargeMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ChargeMagnitude operator *(ChargeMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ChargeMagnitude operator *(T left, ChargeMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ChargeMagnitude operator /(ChargeMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ChargeMagnitude left, ChargeMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ChargeMagnitude left, ChargeMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ChargeMagnitude left, ChargeMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ChargeMagnitude left, ChargeMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ChargeMagnitude left, ChargeMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Coulomb. @@ -53,24 +128,24 @@ public partial record ChargeMagnitude : PhysicalQuantity, /// Divides ChargeMagnitude by Duration to produce CurrentMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator /(ChargeMagnitude left, Duration right) => Divide>(left, right); + public static CurrentMagnitude operator /(ChargeMagnitude left, Duration right) => CurrentMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides ChargeMagnitude by CurrentMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(ChargeMagnitude left, CurrentMagnitude right) => Divide>(left, right); + public static Duration operator /(ChargeMagnitude left, CurrentMagnitude right) => Duration.Create(left.Quantity / right.Quantity); /// /// Divides ChargeMagnitude by VoltageMagnitude to produce Capacitance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Capacitance operator /(ChargeMagnitude left, VoltageMagnitude right) => Divide>(left, right); + public static Capacitance operator /(ChargeMagnitude left, VoltageMagnitude right) => Capacitance.Create(left.Quantity / right.Quantity); /// /// Divides ChargeMagnitude by Capacitance to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator /(ChargeMagnitude left, Capacitance right) => Divide>(left, right); + public static VoltageMagnitude operator /(ChargeMagnitude left, Capacitance right) => VoltageMagnitude.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ClockSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ClockSpeed.g.cs index e803e1cf..60b8261a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ClockSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ClockSpeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ClockSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ClockSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ClockSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Frequency; + public DimensionInfo Dimension => PhysicalDimensions.Frequency; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ClockSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ClockSpeed operator +(ClockSpeed left, ClockSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ClockSpeed operator -(ClockSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ClockSpeed operator *(ClockSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ClockSpeed operator *(T left, ClockSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ClockSpeed operator /(ClockSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ClockSpeed left, ClockSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ClockSpeed left, ClockSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ClockSpeed left, ClockSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ClockSpeed left, ClockSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ClockSpeed left, ClockSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ClockSpeed from a value in Hertz. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Concentration.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Concentration.g.cs index 82247050..3568814e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Concentration.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Concentration.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Concentration dimension. /// /// The numeric storage type. -public partial record Concentration : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Concentration : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Concentration Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Concentration; + public DimensionInfo Dimension => PhysicalDimensions.Concentration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Concentration Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Concentration operator +(Concentration left, Concentration right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Concentration operator -(Concentration value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Concentration operator *(Concentration left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Concentration operator *(T left, Concentration right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Concentration operator /(Concentration left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Concentration left, Concentration right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Concentration left, Concentration right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Concentration left, Concentration right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Concentration left, Concentration right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Concentration left, Concentration right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MolePerCubicMeter. @@ -69,18 +144,18 @@ public partial record Concentration : PhysicalQuantity, T>, /// Multiplies Concentration by Volume to produce AmountOfSubstance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator *(Concentration left, Volume right) => Multiply>(left, right); + public static AmountOfSubstance operator *(Concentration left, Volume right) => AmountOfSubstance.Create(left.Quantity * right.Quantity); /// /// Divides Concentration by Duration to produce ReactionRate. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ReactionRate operator /(Concentration left, Duration right) => Divide>(left, right); + public static ReactionRate operator /(Concentration left, Duration right) => ReactionRate.Create(left.Quantity / right.Quantity); /// /// Divides Concentration by ReactionRate to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Concentration left, ReactionRate right) => Divide>(left, right); + public static Duration operator /(Concentration left, ReactionRate right) => Duration.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Conductance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Conductance.g.cs index 6603bb42..9a1db244 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Conductance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Conductance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricConductance dimension. /// /// The numeric storage type. -public partial record Conductance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Conductance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Conductance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricConductance; + public DimensionInfo Dimension => PhysicalDimensions.ElectricConductance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Conductance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Conductance operator +(Conductance left, Conductance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Conductance operator -(Conductance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Conductance operator *(Conductance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Conductance operator *(T left, Conductance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Conductance operator /(Conductance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Conductance left, Conductance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Conductance left, Conductance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Conductance left, Conductance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Conductance left, Conductance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Conductance left, Conductance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Siemens. @@ -45,6 +120,6 @@ public partial record Conductance : PhysicalQuantity, T>, IVec /// Multiplies Conductance by VoltageMagnitude to produce CurrentMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator *(Conductance left, VoltageMagnitude right) => Multiply>(left, right); + public static CurrentMagnitude operator *(Conductance left, VoltageMagnitude right) => CurrentMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CrossSectionalArea.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CrossSectionalArea.g.cs index 84f2b19a..e8697502 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CrossSectionalArea.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CrossSectionalArea.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record CrossSectionalArea : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct CrossSectionalArea : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static CrossSectionalArea Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Area; + public DimensionInfo Dimension => PhysicalDimensions.Area; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static CrossSectionalArea Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CrossSectionalArea operator +(CrossSectionalArea left, CrossSectionalArea right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CrossSectionalArea operator -(CrossSectionalArea value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CrossSectionalArea operator *(CrossSectionalArea left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CrossSectionalArea operator *(T left, CrossSectionalArea right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CrossSectionalArea operator /(CrossSectionalArea left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(CrossSectionalArea left, CrossSectionalArea right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(CrossSectionalArea left, CrossSectionalArea right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(CrossSectionalArea left, CrossSectionalArea right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(CrossSectionalArea left, CrossSectionalArea right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(CrossSectionalArea left, CrossSectionalArea right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new CrossSectionalArea from a value in SquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current1D.g.cs index eb60754e..c1febe34 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the ElectricCurrent dimension. /// /// The numeric storage type. -public partial record Current1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Current1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Current1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricCurrent; + public DimensionInfo Dimension => PhysicalDimensions.ElectricCurrent; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Current1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator +(Current1D left, Current1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator -(Current1D left, Current1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator -(Current1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator *(Current1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator *(T left, Current1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Current1D operator /(Current1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Current1D left, Current1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Current1D left, Current1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Current1D left, Current1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Current1D left, Current1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Current1D left, Current1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Ampere. @@ -57,12 +136,12 @@ public partial record Current1D : PhysicalQuantity, T>, IVector1 /// Multiplies Current1D by Duration to produce Charge. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Charge operator *(Current1D left, Duration right) => Multiply>(left, right); + public static Charge operator *(Current1D left, Duration right) => Charge.Create(left.Quantity * right.Quantity); /// /// Multiplies Current1D by Resistance to produce Voltage. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Voltage operator *(Current1D left, Resistance right) => Multiply>(left, right); + public static Voltage operator *(Current1D left, Resistance right) => Voltage.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current3D.g.cs index 87ed6ae9..e7a998bc 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Current3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of ElectricCurrent. /// /// The numeric component type. -public partial record Current3D : IVector3, T> +public readonly partial record struct Current3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CurrentMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CurrentMagnitude.g.cs index 363ebaf8..07b392c6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CurrentMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/CurrentMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricCurrent dimension. /// /// The numeric storage type. -public partial record CurrentMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct CurrentMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static CurrentMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricCurrent; + public DimensionInfo Dimension => PhysicalDimensions.ElectricCurrent; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static CurrentMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CurrentMagnitude operator +(CurrentMagnitude left, CurrentMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CurrentMagnitude operator -(CurrentMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CurrentMagnitude operator *(CurrentMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CurrentMagnitude operator *(T left, CurrentMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static CurrentMagnitude operator /(CurrentMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(CurrentMagnitude left, CurrentMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(CurrentMagnitude left, CurrentMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(CurrentMagnitude left, CurrentMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(CurrentMagnitude left, CurrentMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(CurrentMagnitude left, CurrentMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Ampere. @@ -61,36 +136,36 @@ public partial record CurrentMagnitude : PhysicalQuantity /// Multiplies CurrentMagnitude by Duration to produce ChargeMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ChargeMagnitude operator *(CurrentMagnitude left, Duration right) => Multiply>(left, right); + public static ChargeMagnitude operator *(CurrentMagnitude left, Duration right) => ChargeMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies CurrentMagnitude by Resistance to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(CurrentMagnitude left, Resistance right) => Multiply>(left, right); + public static VoltageMagnitude operator *(CurrentMagnitude left, Resistance right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies CurrentMagnitude by VoltageMagnitude to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(CurrentMagnitude left, VoltageMagnitude right) => Multiply>(left, right); + public static Power operator *(CurrentMagnitude left, VoltageMagnitude right) => Power.Create(left.Quantity * right.Quantity); /// /// Divides CurrentMagnitude by VoltageMagnitude to produce Conductance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Conductance operator /(CurrentMagnitude left, VoltageMagnitude right) => Divide>(left, right); + public static Conductance operator /(CurrentMagnitude left, VoltageMagnitude right) => Conductance.Create(left.Quantity / right.Quantity); /// /// Divides CurrentMagnitude by Conductance to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator /(CurrentMagnitude left, Conductance right) => Divide>(left, right); + public static VoltageMagnitude operator /(CurrentMagnitude left, Conductance right) => VoltageMagnitude.Create(left.Quantity / right.Quantity); /// /// Multiplies CurrentMagnitude by Inductance to produce MagneticFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(CurrentMagnitude left, Inductance right) => Multiply>(left, right); + public static MagneticFlux operator *(CurrentMagnitude left, Inductance right) => MagneticFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DecayTime.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DecayTime.g.cs index 45de94f4..db2afa3c 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DecayTime.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DecayTime.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record DecayTime : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct DecayTime : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static DecayTime Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static DecayTime Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DecayTime operator +(DecayTime left, DecayTime right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DecayTime operator -(DecayTime value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DecayTime operator *(DecayTime left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DecayTime operator *(T left, DecayTime right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DecayTime operator /(DecayTime left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(DecayTime left, DecayTime right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(DecayTime left, DecayTime right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(DecayTime left, DecayTime right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(DecayTime left, DecayTime right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(DecayTime left, DecayTime right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new DecayTime from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Density.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Density.g.cs index 261866b9..f69d5eec 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Density.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Density.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Density dimension. /// /// The numeric storage type. -public partial record Density : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Density : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Density Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Density; + public DimensionInfo Dimension => PhysicalDimensions.Density; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Density Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Density operator +(Density left, Density right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Density operator -(Density value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Density operator *(Density left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Density operator *(T left, Density right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Density operator /(Density left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Density left, Density right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Density left, Density right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Density left, Density right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Density left, Density right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Density left, Density right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramPerCubicMeter. @@ -61,12 +136,12 @@ public partial record Density : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(Density left, Volume right) => Multiply>(left, right); + public static Mass operator *(Density left, Volume right) => Mass.Create(left.Quantity * right.Quantity); /// /// Multiplies Density by KinematicViscosity to produce DynamicViscosity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static DynamicViscosity operator *(Density left, KinematicViscosity right) => Multiply>(left, right); + public static DynamicViscosity operator *(Density left, KinematicViscosity right) => DynamicViscosity.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Depth.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Depth.g.cs index e5a0a085..081c9320 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Depth.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Depth.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Depth : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Depth : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Depth Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Depth Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Depth operator +(Depth left, Depth right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Depth operator -(Depth value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Depth operator *(Depth left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Depth operator *(T left, Depth right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Depth operator /(Depth left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Depth left, Depth right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Depth left, Depth right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Depth left, Depth right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Depth left, Depth right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Depth left, Depth right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Depth from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Diameter.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Diameter.g.cs index 5eb612ec..8ec95079 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Diameter.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Diameter.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Diameter : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Diameter : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Diameter Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Diameter Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Diameter operator +(Diameter left, Diameter right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Diameter operator -(Diameter value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Diameter operator *(Diameter left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Diameter operator *(T left, Diameter right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Diameter operator /(Diameter left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Diameter left, Diameter right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Diameter left, Diameter right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Diameter left, Diameter right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Diameter left, Diameter right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Diameter left, Diameter right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Diameter from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement1D.g.cs index 29725f5f..a689a9bb 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Length dimension. /// /// The numeric storage type. -public partial record Displacement1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Displacement1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Displacement1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Displacement1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator +(Displacement1D left, Displacement1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator -(Displacement1D left, Displacement1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator -(Displacement1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator *(Displacement1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator *(T left, Displacement1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Displacement1D operator /(Displacement1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Displacement1D left, Displacement1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Displacement1D left, Displacement1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Displacement1D left, Displacement1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Displacement1D left, Displacement1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Displacement1D left, Displacement1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Meter. @@ -120,6 +199,6 @@ public partial record Displacement1D : PhysicalQuantity, T> /// Divides Displacement1D by Duration to produce Velocity1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Velocity1D operator /(Displacement1D left, Duration right) => Divide>(left, right); + public static Velocity1D operator /(Displacement1D left, Duration right) => Velocity1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement2D.g.cs index fa58977c..1933e360 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Length. /// /// The numeric component type. -public partial record Displacement2D : IVector2, T> +public readonly partial record struct Displacement2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement3D.g.cs index 3067a9a1..9fa8ddf2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Length. /// /// The numeric component type. -public partial record Displacement3D : IVector3, T> +public readonly partial record struct Displacement3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement4D.g.cs index 96eee408..f3e79191 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Displacement4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Length. /// /// The numeric component type. -public partial record Displacement4D : IVector4, T> +public readonly partial record struct Displacement4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Distance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Distance.g.cs index 975fef81..720e445e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Distance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Distance.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Distance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Distance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Distance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Distance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Distance operator +(Distance left, Distance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Distance operator -(Distance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Distance operator *(Distance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Distance operator *(T left, Distance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Distance operator /(Distance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Distance left, Distance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Distance left, Distance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Distance left, Distance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Distance left, Distance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Distance left, Distance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Distance from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Drag.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Drag.g.cs index bee778d8..0726839d 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Drag.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Drag.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Drag : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Drag : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Drag Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Drag Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Drag operator +(Drag left, Drag right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Drag operator -(Drag value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Drag operator *(Drag left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Drag operator *(T left, Drag right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Drag operator /(Drag left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Drag left, Drag right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Drag left, Drag right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Drag left, Drag right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Drag left, Drag right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Drag left, Drag right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Drag from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Duration.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Duration.g.cs index 699cf3da..8179d3d4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Duration.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Duration.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Time dimension. /// /// The numeric storage type. -public partial record Duration : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Duration : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Duration Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Duration Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Duration operator +(Duration left, Duration right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Duration operator -(Duration value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Duration operator *(Duration left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Duration operator *(T left, Duration right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Duration operator /(Duration left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Duration left, Duration right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Duration left, Duration right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Duration left, Duration right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Duration left, Duration right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Duration left, Duration right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Second. @@ -109,25 +184,25 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ChargeMagnitude operator *(Duration left, CurrentMagnitude right) => Multiply>(left, right); + public static ChargeMagnitude operator *(Duration left, CurrentMagnitude right) => ChargeMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Current1D to produce Charge. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Charge operator *(Duration left, Current1D right) => Multiply>(left, right); + public static Charge operator *(Duration left, Current1D right) => Charge.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Speed to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator *(Duration left, Speed right) => Multiply>(left, right); + public static Length operator *(Duration left, Speed right) => Length.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Velocity1D to produce Displacement1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Displacement1D operator *(Duration left, Velocity1D right) => Multiply>(left, right); + public static Displacement1D operator *(Duration left, Velocity1D right) => Displacement1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Velocity2D to produce Displacement2D. @@ -151,13 +226,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator *(Duration left, AccelerationMagnitude right) => Multiply>(left, right); + public static Speed operator *(Duration left, AccelerationMagnitude right) => Speed.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Acceleration1D to produce Velocity1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Velocity1D operator *(Duration left, Acceleration1D right) => Multiply>(left, right); + public static Velocity1D operator *(Duration left, Acceleration1D right) => Velocity1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Acceleration2D to produce Velocity2D. @@ -181,13 +256,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AccelerationMagnitude operator *(Duration left, JerkMagnitude right) => Multiply>(left, right); + public static AccelerationMagnitude operator *(Duration left, JerkMagnitude right) => AccelerationMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Jerk1D to produce Acceleration1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Acceleration1D operator *(Duration left, Jerk1D right) => Multiply>(left, right); + public static Acceleration1D operator *(Duration left, Jerk1D right) => Acceleration1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Jerk2D to produce Acceleration2D. @@ -211,13 +286,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static JerkMagnitude operator *(Duration left, SnapMagnitude right) => Multiply>(left, right); + public static JerkMagnitude operator *(Duration left, SnapMagnitude right) => JerkMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Snap1D to produce Jerk1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Jerk1D operator *(Duration left, Snap1D right) => Multiply>(left, right); + public static Jerk1D operator *(Duration left, Snap1D right) => Jerk1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Snap2D to produce Jerk2D. @@ -241,19 +316,19 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Ratio operator *(Duration left, Frequency right) => Multiply>(left, right); + public static Ratio operator *(Duration left, Frequency right) => Ratio.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularSpeed to produce Angle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Angle operator *(Duration left, AngularSpeed right) => Multiply>(left, right); + public static Angle operator *(Duration left, AngularSpeed right) => Angle.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularVelocity1D to produce SignedAngle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SignedAngle operator *(Duration left, AngularVelocity1D right) => Multiply>(left, right); + public static SignedAngle operator *(Duration left, AngularVelocity1D right) => SignedAngle.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularVelocity3D to produce AngularDisplacement3D. @@ -265,13 +340,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularSpeed operator *(Duration left, AngularAccelerationMagnitude right) => Multiply>(left, right); + public static AngularSpeed operator *(Duration left, AngularAccelerationMagnitude right) => AngularSpeed.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularAcceleration1D to produce AngularVelocity1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularVelocity1D operator *(Duration left, AngularAcceleration1D right) => Multiply>(left, right); + public static AngularVelocity1D operator *(Duration left, AngularAcceleration1D right) => AngularVelocity1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularAcceleration3D to produce AngularVelocity3D. @@ -283,13 +358,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAccelerationMagnitude operator *(Duration left, AngularJerkMagnitude right) => Multiply>(left, right); + public static AngularAccelerationMagnitude operator *(Duration left, AngularJerkMagnitude right) => AngularAccelerationMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularJerk1D to produce AngularAcceleration1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAcceleration1D operator *(Duration left, AngularJerk1D right) => Multiply>(left, right); + public static AngularAcceleration1D operator *(Duration left, AngularJerk1D right) => AngularAcceleration1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by AngularJerk3D to produce AngularAcceleration3D. @@ -301,13 +376,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentumMagnitude operator *(Duration left, TorqueMagnitude right) => Multiply>(left, right); + public static AngularMomentumMagnitude operator *(Duration left, TorqueMagnitude right) => AngularMomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Torque1D to produce AngularMomentum1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentum1D operator *(Duration left, Torque1D right) => Multiply>(left, right); + public static AngularMomentum1D operator *(Duration left, Torque1D right) => AngularMomentum1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Torque3D to produce AngularMomentum3D. @@ -319,13 +394,13 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentumMagnitude operator *(Duration left, ForceMagnitude right) => Multiply>(left, right); + public static MomentumMagnitude operator *(Duration left, ForceMagnitude right) => MomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Force1D to produce Momentum1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Momentum1D operator *(Duration left, Force1D right) => Multiply>(left, right); + public static Momentum1D operator *(Duration left, Force1D right) => Momentum1D.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by Force2D to produce Momentum2D. @@ -349,36 +424,36 @@ public partial record Duration : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Duration left, Power right) => Multiply>(left, right); + public static Energy operator *(Duration left, Power right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by VolumetricFlowRate to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator *(Duration left, VolumetricFlowRate right) => Multiply>(left, right); + public static Volume operator *(Duration left, VolumetricFlowRate right) => Volume.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by MassFlowRate to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(Duration left, MassFlowRate right) => Multiply>(left, right); + public static Mass operator *(Duration left, MassFlowRate right) => Mass.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by CatalyticActivity to produce AmountOfSubstance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator *(Duration left, CatalyticActivity right) => Multiply>(left, right); + public static AmountOfSubstance operator *(Duration left, CatalyticActivity right) => AmountOfSubstance.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by ReactionRate to produce Concentration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Concentration operator *(Duration left, ReactionRate right) => Multiply>(left, right); + public static Concentration operator *(Duration left, ReactionRate right) => Concentration.Create(left.Quantity * right.Quantity); /// /// Multiplies Duration by VoltageMagnitude to produce MagneticFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(Duration left, VoltageMagnitude right) => Multiply>(left, right); + public static MagneticFlux operator *(Duration left, VoltageMagnitude right) => MagneticFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DynamicViscosity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DynamicViscosity.g.cs index 910a720b..58b43a8a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DynamicViscosity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/DynamicViscosity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the DynamicViscosity dimension. /// /// The numeric storage type. -public partial record DynamicViscosity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct DynamicViscosity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static DynamicViscosity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.DynamicViscosity; + public DimensionInfo Dimension => PhysicalDimensions.DynamicViscosity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static DynamicViscosity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DynamicViscosity operator +(DynamicViscosity left, DynamicViscosity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DynamicViscosity operator -(DynamicViscosity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DynamicViscosity operator *(DynamicViscosity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DynamicViscosity operator *(T left, DynamicViscosity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static DynamicViscosity operator /(DynamicViscosity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(DynamicViscosity left, DynamicViscosity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(DynamicViscosity left, DynamicViscosity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(DynamicViscosity left, DynamicViscosity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(DynamicViscosity left, DynamicViscosity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(DynamicViscosity left, DynamicViscosity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in PascalSecond. @@ -61,6 +136,6 @@ public partial record DynamicViscosity : PhysicalQuantity /// Divides DynamicViscosity by Density to produce KinematicViscosity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static KinematicViscosity operator /(DynamicViscosity left, Density right) => Divide>(left, right); + public static KinematicViscosity operator /(DynamicViscosity left, Density right) => KinematicViscosity.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EMF.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EMF.g.cs index cf0135c7..c456f3a1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EMF.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EMF.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record EMF : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct EMF : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static EMF Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + public DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static EMF Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EMF operator +(EMF left, EMF right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EMF operator -(EMF value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EMF operator *(EMF left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EMF operator *(T left, EMF right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EMF operator /(EMF left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(EMF left, EMF right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(EMF left, EMF right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(EMF left, EMF right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(EMF left, EMF right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(EMF left, EMF right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new EMF from a value in Volt. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricConductivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricConductivity.g.cs index b42be543..418efd11 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricConductivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricConductivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricConductivity dimension. /// /// The numeric storage type. -public partial record ElectricConductivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ElectricConductivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ElectricConductivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricConductivity; + public DimensionInfo Dimension => PhysicalDimensions.ElectricConductivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ElectricConductivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricConductivity operator +(ElectricConductivity left, ElectricConductivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricConductivity operator -(ElectricConductivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricConductivity operator *(ElectricConductivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricConductivity operator *(T left, ElectricConductivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricConductivity operator /(ElectricConductivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ElectricConductivity left, ElectricConductivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ElectricConductivity left, ElectricConductivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ElectricConductivity left, ElectricConductivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ElectricConductivity left, ElectricConductivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ElectricConductivity left, ElectricConductivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in SiemensPerMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField1D.g.cs index 1a6fbc4f..272ff66e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the ElectricField dimension. /// /// The numeric storage type. -public partial record ElectricField1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct ElectricField1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ElectricField1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricField; + public DimensionInfo Dimension => PhysicalDimensions.ElectricField; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ElectricField1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator +(ElectricField1D left, ElectricField1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator -(ElectricField1D left, ElectricField1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator -(ElectricField1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator *(ElectricField1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator *(T left, ElectricField1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricField1D operator /(ElectricField1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ElectricField1D left, ElectricField1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ElectricField1D left, ElectricField1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ElectricField1D left, ElectricField1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ElectricField1D left, ElectricField1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ElectricField1D left, ElectricField1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in VoltPerMeter. @@ -43,6 +122,6 @@ public partial record ElectricField1D : PhysicalQuantity, /// Multiplies ElectricField1D by Length to produce Voltage. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Voltage operator *(ElectricField1D left, Length right) => Multiply>(left, right); + public static Voltage operator *(ElectricField1D left, Length right) => Voltage.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField2D.g.cs index 90ec148b..38b0d093 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of ElectricField. /// /// The numeric component type. -public partial record ElectricField2D : IVector2, T> +public readonly partial record struct ElectricField2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField3D.g.cs index c76b5a38..1a0058d8 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricField3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of ElectricField. /// /// The numeric component type. -public partial record ElectricField3D : IVector3, T> +public readonly partial record struct ElectricField3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFieldMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFieldMagnitude.g.cs index e4b43a93..67c97e3b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFieldMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFieldMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricField dimension. /// /// The numeric storage type. -public partial record ElectricFieldMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ElectricFieldMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ElectricFieldMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricField; + public DimensionInfo Dimension => PhysicalDimensions.ElectricField; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ElectricFieldMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFieldMagnitude operator +(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFieldMagnitude operator -(ElectricFieldMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFieldMagnitude operator *(ElectricFieldMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFieldMagnitude operator *(T left, ElectricFieldMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFieldMagnitude operator /(ElectricFieldMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in VoltPerMeter. @@ -45,12 +120,12 @@ public partial record ElectricFieldMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(ElectricFieldMagnitude left, Length right) => Multiply>(left, right); + public static VoltageMagnitude operator *(ElectricFieldMagnitude left, Length right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies ElectricFieldMagnitude by Area to produce ElectricFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricFlux operator *(ElectricFieldMagnitude left, Area right) => Multiply>(left, right); + public static ElectricFlux operator *(ElectricFieldMagnitude left, Area right) => ElectricFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFlux.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFlux.g.cs index 5257d802..10ce7ad4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFlux.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricFlux.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricFlux dimension. /// /// The numeric storage type. -public partial record ElectricFlux : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ElectricFlux : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ElectricFlux Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricFlux; + public DimensionInfo Dimension => PhysicalDimensions.ElectricFlux; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ElectricFlux Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFlux operator +(ElectricFlux left, ElectricFlux right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFlux operator -(ElectricFlux value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFlux operator *(ElectricFlux left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFlux operator *(T left, ElectricFlux right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricFlux operator /(ElectricFlux left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ElectricFlux left, ElectricFlux right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ElectricFlux left, ElectricFlux right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ElectricFlux left, ElectricFlux right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ElectricFlux left, ElectricFlux right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ElectricFlux left, ElectricFlux right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in VoltMeter. @@ -45,12 +120,12 @@ public partial record ElectricFlux : PhysicalQuantity, T>, IV /// Divides ElectricFlux by Area to produce ElectricFieldMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricFieldMagnitude operator /(ElectricFlux left, Area right) => Divide>(left, right); + public static ElectricFieldMagnitude operator /(ElectricFlux left, Area right) => ElectricFieldMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides ElectricFlux by ElectricFieldMagnitude to produce Area. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(ElectricFlux left, ElectricFieldMagnitude right) => Divide>(left, right); + public static Area operator /(ElectricFlux left, ElectricFieldMagnitude right) => Area.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricPowerDensity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricPowerDensity.g.cs index 691f17b9..fc87f0b1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricPowerDensity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ElectricPowerDensity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricPowerDensity dimension. /// /// The numeric storage type. -public partial record ElectricPowerDensity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ElectricPowerDensity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ElectricPowerDensity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricPowerDensity; + public DimensionInfo Dimension => PhysicalDimensions.ElectricPowerDensity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ElectricPowerDensity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricPowerDensity operator +(ElectricPowerDensity left, ElectricPowerDensity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricPowerDensity operator -(ElectricPowerDensity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricPowerDensity operator *(ElectricPowerDensity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricPowerDensity operator *(T left, ElectricPowerDensity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ElectricPowerDensity operator /(ElectricPowerDensity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ElectricPowerDensity left, ElectricPowerDensity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ElectricPowerDensity left, ElectricPowerDensity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ElectricPowerDensity left, ElectricPowerDensity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ElectricPowerDensity left, ElectricPowerDensity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ElectricPowerDensity left, ElectricPowerDensity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in WattPerCubicMeter. @@ -45,6 +120,6 @@ public partial record ElectricPowerDensity : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(ElectricPowerDensity left, Volume right) => Multiply>(left, right); + public static Power operator *(ElectricPowerDensity left, Volume right) => Power.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Energy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Energy.g.cs index 58982ab5..b27a3229 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Energy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Energy.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Energy dimension. /// /// The numeric storage type. -public partial record Energy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Energy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Energy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Energy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Energy operator +(Energy left, Energy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Energy operator -(Energy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Energy operator *(Energy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Energy operator *(T left, Energy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Energy operator /(Energy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Energy left, Energy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Energy left, Energy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Energy left, Energy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Energy left, Energy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Energy left, Energy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Joule. @@ -109,72 +184,72 @@ public partial record Energy : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static TorqueMagnitude operator /(Energy left, Angle right) => Divide>(left, right); + public static TorqueMagnitude operator /(Energy left, Angle right) => TorqueMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Energy by TorqueMagnitude to produce Angle. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Angle operator /(Energy left, TorqueMagnitude right) => Divide>(left, right); + public static Angle operator /(Energy left, TorqueMagnitude right) => Angle.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Length to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator /(Energy left, Length right) => Divide>(left, right); + public static ForceMagnitude operator /(Energy left, Length right) => ForceMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Energy by ForceMagnitude to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(Energy left, ForceMagnitude right) => Divide>(left, right); + public static Length operator /(Energy left, ForceMagnitude right) => Length.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Volume to produce Pressure. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Pressure operator /(Energy left, Volume right) => Divide>(left, right); + public static Pressure operator /(Energy left, Volume right) => Pressure.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Pressure to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator /(Energy left, Pressure right) => Divide>(left, right); + public static Volume operator /(Energy left, Pressure right) => Volume.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Duration to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator /(Energy left, Duration right) => Divide>(left, right); + public static Power operator /(Energy left, Duration right) => Power.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Power to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Energy left, Power right) => Divide>(left, right); + public static Duration operator /(Energy left, Power right) => Duration.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Temperature to produce Entropy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Entropy operator /(Energy left, Temperature right) => Divide>(left, right); + public static Entropy operator /(Energy left, Temperature right) => Entropy.Create(left.Quantity / right.Quantity); /// /// Divides Energy by Entropy to produce Temperature. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Temperature operator /(Energy left, Entropy right) => Divide>(left, right); + public static Temperature operator /(Energy left, Entropy right) => Temperature.Create(left.Quantity / right.Quantity); /// /// Divides Energy by AmountOfSubstance to produce MolarEnergy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MolarEnergy operator /(Energy left, AmountOfSubstance right) => Divide>(left, right); + public static MolarEnergy operator /(Energy left, AmountOfSubstance right) => MolarEnergy.Create(left.Quantity / right.Quantity); /// /// Divides Energy by MolarEnergy to produce AmountOfSubstance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator /(Energy left, MolarEnergy right) => Divide>(left, right); + public static AmountOfSubstance operator /(Energy left, MolarEnergy right) => AmountOfSubstance.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnergyFluxDensity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnergyFluxDensity.g.cs index e9d490e2..18bb1d7c 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnergyFluxDensity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnergyFluxDensity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record EnergyFluxDensity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct EnergyFluxDensity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static EnergyFluxDensity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Irradiance; + public DimensionInfo Dimension => PhysicalDimensions.Irradiance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static EnergyFluxDensity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnergyFluxDensity operator +(EnergyFluxDensity left, EnergyFluxDensity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnergyFluxDensity operator -(EnergyFluxDensity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnergyFluxDensity operator *(EnergyFluxDensity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnergyFluxDensity operator *(T left, EnergyFluxDensity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnergyFluxDensity operator /(EnergyFluxDensity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(EnergyFluxDensity left, EnergyFluxDensity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(EnergyFluxDensity left, EnergyFluxDensity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(EnergyFluxDensity left, EnergyFluxDensity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(EnergyFluxDensity left, EnergyFluxDensity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(EnergyFluxDensity left, EnergyFluxDensity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new EnergyFluxDensity from a value in WattPerSquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Entropy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Entropy.g.cs index c8f4ee96..6007a87e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Entropy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Entropy.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Entropy dimension. /// /// The numeric storage type. -public partial record Entropy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Entropy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Entropy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Entropy; + public DimensionInfo Dimension => PhysicalDimensions.Entropy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Entropy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Entropy operator +(Entropy left, Entropy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Entropy operator -(Entropy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Entropy operator *(Entropy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Entropy operator *(T left, Entropy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Entropy operator /(Entropy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Entropy left, Entropy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Entropy left, Entropy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Entropy left, Entropy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Entropy left, Entropy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Entropy left, Entropy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in JoulePerKelvin. @@ -45,18 +120,18 @@ public partial record Entropy : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Entropy left, Temperature right) => Multiply>(left, right); + public static Energy operator *(Entropy left, Temperature right) => Energy.Create(left.Quantity * right.Quantity); /// /// Divides Entropy by Mass to produce SpecificHeat. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SpecificHeat operator /(Entropy left, Mass right) => Divide>(left, right); + public static SpecificHeat operator /(Entropy left, Mass right) => SpecificHeat.Create(left.Quantity / right.Quantity); /// /// Divides Entropy by SpecificHeat to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator /(Entropy left, SpecificHeat right) => Divide>(left, right); + public static Mass operator /(Entropy left, SpecificHeat right) => Mass.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnzymeActivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnzymeActivity.g.cs index dda5f1f5..7e07dce8 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnzymeActivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EnzymeActivity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record EnzymeActivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct EnzymeActivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static EnzymeActivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.CatalyticActivity; + public DimensionInfo Dimension => PhysicalDimensions.CatalyticActivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static EnzymeActivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnzymeActivity operator +(EnzymeActivity left, EnzymeActivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnzymeActivity operator -(EnzymeActivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnzymeActivity operator *(EnzymeActivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnzymeActivity operator *(T left, EnzymeActivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EnzymeActivity operator /(EnzymeActivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(EnzymeActivity left, EnzymeActivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(EnzymeActivity left, EnzymeActivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(EnzymeActivity left, EnzymeActivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(EnzymeActivity left, EnzymeActivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(EnzymeActivity left, EnzymeActivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new EnzymeActivity from a value in Katal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EquivalentDose.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EquivalentDose.g.cs index 4c24ba26..9c1ecdd9 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EquivalentDose.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/EquivalentDose.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the EquivalentDose dimension. /// /// The numeric storage type. -public partial record EquivalentDose : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct EquivalentDose : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static EquivalentDose Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.EquivalentDose; + public DimensionInfo Dimension => PhysicalDimensions.EquivalentDose; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static EquivalentDose Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EquivalentDose operator +(EquivalentDose left, EquivalentDose right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EquivalentDose operator -(EquivalentDose value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EquivalentDose operator *(EquivalentDose left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EquivalentDose operator *(T left, EquivalentDose right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static EquivalentDose operator /(EquivalentDose left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(EquivalentDose left, EquivalentDose right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(EquivalentDose left, EquivalentDose right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(EquivalentDose left, EquivalentDose right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(EquivalentDose left, EquivalentDose right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(EquivalentDose left, EquivalentDose right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Sievert. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Exposure.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Exposure.g.cs index 382551f0..981e5c8a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Exposure.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Exposure.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Exposure dimension. /// /// The numeric storage type. -public partial record Exposure : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Exposure : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Exposure Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Exposure; + public DimensionInfo Dimension => PhysicalDimensions.Exposure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Exposure Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Exposure operator +(Exposure left, Exposure right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Exposure operator -(Exposure value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Exposure operator *(Exposure left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Exposure operator *(T left, Exposure right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Exposure operator /(Exposure left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Exposure left, Exposure right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Exposure left, Exposure right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Exposure left, Exposure right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Exposure left, Exposure right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Exposure left, Exposure right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in CoulombPerKilogram. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FieldOfView.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FieldOfView.g.cs index 95d79e51..9b92e594 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FieldOfView.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FieldOfView.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record FieldOfView : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct FieldOfView : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static FieldOfView Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static FieldOfView Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FieldOfView operator +(FieldOfView left, FieldOfView right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FieldOfView operator -(FieldOfView value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FieldOfView operator *(FieldOfView left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FieldOfView operator *(T left, FieldOfView right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FieldOfView operator /(FieldOfView left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(FieldOfView left, FieldOfView right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(FieldOfView left, FieldOfView right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(FieldOfView left, FieldOfView right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(FieldOfView left, FieldOfView right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(FieldOfView left, FieldOfView right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new FieldOfView from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FlowSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FlowSpeed.g.cs index a1b77b33..ae8ffd77 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FlowSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/FlowSpeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record FlowSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct FlowSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static FlowSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static FlowSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FlowSpeed operator +(FlowSpeed left, FlowSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FlowSpeed operator -(FlowSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FlowSpeed operator *(FlowSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FlowSpeed operator *(T left, FlowSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static FlowSpeed operator /(FlowSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(FlowSpeed left, FlowSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(FlowSpeed left, FlowSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(FlowSpeed left, FlowSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(FlowSpeed left, FlowSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(FlowSpeed left, FlowSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new FlowSpeed from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force1D.g.cs index fa1a261d..98807f3d 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Force dimension. /// /// The numeric storage type. -public partial record Force1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Force1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Force1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Force1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator +(Force1D left, Force1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator -(Force1D left, Force1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator -(Force1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator *(Force1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator *(T left, Force1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Force1D operator /(Force1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Force1D left, Force1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Force1D left, Force1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Force1D left, Force1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Force1D left, Force1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Force1D left, Force1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Newton. @@ -64,6 +143,6 @@ public partial record Force1D : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Momentum1D operator *(Force1D left, Duration right) => Multiply>(left, right); + public static Momentum1D operator *(Force1D left, Duration right) => Momentum1D.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force2D.g.cs index 2603dde4..fec75824 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Force. /// /// The numeric component type. -public partial record Force2D : IVector2, T> +public readonly partial record struct Force2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force3D.g.cs index 7dbb9f4c..6674e3a4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Force. /// /// The numeric component type. -public partial record Force3D : IVector3, T> +public readonly partial record struct Force3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force4D.g.cs index 682533e5..13f3e391 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Force4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Force. /// /// The numeric component type. -public partial record Force4D : IVector4, T> +public readonly partial record struct Force4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ForceMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ForceMagnitude.g.cs index 7214a84c..28e7d648 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ForceMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ForceMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Force dimension. /// /// The numeric storage type. -public partial record ForceMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ForceMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ForceMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ForceMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ForceMagnitude operator +(ForceMagnitude left, ForceMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ForceMagnitude operator -(ForceMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ForceMagnitude operator *(ForceMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ForceMagnitude operator *(T left, ForceMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ForceMagnitude operator /(ForceMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ForceMagnitude left, ForceMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ForceMagnitude left, ForceMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ForceMagnitude left, ForceMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ForceMagnitude left, ForceMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ForceMagnitude left, ForceMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Newton. @@ -69,48 +144,48 @@ public partial record ForceMagnitude : PhysicalQuantity, T> /// Divides ForceMagnitude by AccelerationMagnitude to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator /(ForceMagnitude left, AccelerationMagnitude right) => Divide>(left, right); + public static Mass operator /(ForceMagnitude left, AccelerationMagnitude right) => Mass.Create(left.Quantity / right.Quantity); /// /// Divides ForceMagnitude by Mass to produce AccelerationMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AccelerationMagnitude operator /(ForceMagnitude left, Mass right) => Divide>(left, right); + public static AccelerationMagnitude operator /(ForceMagnitude left, Mass right) => AccelerationMagnitude.Create(left.Quantity / right.Quantity); /// /// Multiplies ForceMagnitude by Length to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(ForceMagnitude left, Length right) => Multiply>(left, right); + public static Energy operator *(ForceMagnitude left, Length right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies ForceMagnitude by Duration to produce MomentumMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentumMagnitude operator *(ForceMagnitude left, Duration right) => Multiply>(left, right); + public static MomentumMagnitude operator *(ForceMagnitude left, Duration right) => MomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies ForceMagnitude by Speed to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(ForceMagnitude left, Speed right) => Multiply>(left, right); + public static Power operator *(ForceMagnitude left, Speed right) => Power.Create(left.Quantity * right.Quantity); /// /// Divides ForceMagnitude by Area to produce Pressure. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Pressure operator /(ForceMagnitude left, Area right) => Divide>(left, right); + public static Pressure operator /(ForceMagnitude left, Area right) => Pressure.Create(left.Quantity / right.Quantity); /// /// Divides ForceMagnitude by Length to produce SurfaceTension. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SurfaceTension operator /(ForceMagnitude left, Length right) => Divide>(left, right); + public static SurfaceTension operator /(ForceMagnitude left, Length right) => SurfaceTension.Create(left.Quantity / right.Quantity); /// /// Divides ForceMagnitude by SurfaceTension to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(ForceMagnitude left, SurfaceTension right) => Divide>(left, right); + public static Length operator /(ForceMagnitude left, SurfaceTension right) => Length.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Frequency.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Frequency.g.cs index 4129b5b9..c5007d09 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Frequency.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Frequency.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Frequency dimension. /// /// The numeric storage type. -public partial record Frequency : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Frequency : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Frequency Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Frequency; + public DimensionInfo Dimension => PhysicalDimensions.Frequency; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Frequency Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Frequency operator +(Frequency left, Frequency right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Frequency operator -(Frequency value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Frequency operator *(Frequency left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Frequency operator *(T left, Frequency right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Frequency operator /(Frequency left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Frequency left, Frequency right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Frequency left, Frequency right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Frequency left, Frequency right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Frequency left, Frequency right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Frequency left, Frequency right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Hertz. @@ -61,12 +136,12 @@ public partial record Frequency : PhysicalQuantity, T>, IVector0 /// Multiplies Frequency by Duration to produce Ratio. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Ratio operator *(Frequency left, Duration right) => Multiply>(left, right); + public static Ratio operator *(Frequency left, Duration right) => Ratio.Create(left.Quantity * right.Quantity); /// /// Multiplies Frequency by Length to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator *(Frequency left, Length right) => Multiply>(left, right); + public static Speed operator *(Frequency left, Length right) => Speed.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Friction.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Friction.g.cs index a56b7911..48c3a1d4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Friction.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Friction.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Friction : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Friction : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Friction Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Friction Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Friction operator +(Friction left, Friction right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Friction operator -(Friction value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Friction operator *(Friction left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Friction operator *(T left, Friction right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Friction operator /(Friction left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Friction left, Friction right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Friction left, Friction right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Friction left, Friction right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Friction left, Friction right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Friction left, Friction right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Friction from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Gain.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Gain.g.cs index 330b6319..3c017983 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Gain.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Gain.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Gain : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Gain : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Gain Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Gain Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Gain operator +(Gain left, Gain right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Gain operator -(Gain value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Gain operator *(Gain left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Gain operator *(T left, Gain right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Gain operator /(Gain left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Gain left, Gain right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Gain left, Gain right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Gain left, Gain right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Gain left, Gain right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Gain left, Gain right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Gain from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GaugePressure.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GaugePressure.g.cs index fb196ff8..216b091f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GaugePressure.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GaugePressure.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record GaugePressure : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct GaugePressure : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static GaugePressure Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static GaugePressure Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GaugePressure operator +(GaugePressure left, GaugePressure right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GaugePressure operator -(GaugePressure value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GaugePressure operator *(GaugePressure left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GaugePressure operator *(T left, GaugePressure right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GaugePressure operator /(GaugePressure left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(GaugePressure left, GaugePressure right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(GaugePressure left, GaugePressure right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(GaugePressure left, GaugePressure right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(GaugePressure left, GaugePressure right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(GaugePressure left, GaugePressure right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new GaugePressure from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalAcceleration.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalAcceleration.g.cs index a07969f5..15717497 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalAcceleration.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalAcceleration.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record GravitationalAcceleration : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct GravitationalAcceleration : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static GravitationalAcceleration Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Acceleration; + public DimensionInfo Dimension => PhysicalDimensions.Acceleration; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static GravitationalAcceleration Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GravitationalAcceleration operator +(GravitationalAcceleration left, GravitationalAcceleration right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GravitationalAcceleration operator -(GravitationalAcceleration value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GravitationalAcceleration operator *(GravitationalAcceleration left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GravitationalAcceleration operator *(T left, GravitationalAcceleration right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GravitationalAcceleration operator /(GravitationalAcceleration left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(GravitationalAcceleration left, GravitationalAcceleration right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(GravitationalAcceleration left, GravitationalAcceleration right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(GravitationalAcceleration left, GravitationalAcceleration right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(GravitationalAcceleration left, GravitationalAcceleration right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(GravitationalAcceleration left, GravitationalAcceleration right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new GravitationalAcceleration from a value in MeterPerSecondSquared. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalField3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalField3D.g.cs index c947cfd8..9b06832e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalField3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GravitationalField3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Gravitational acceleration field in 3D. /// Semantic overload of . /// -public partial record GravitationalField3D : IVector3, T> +public readonly partial record struct GravitationalField3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroundSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroundSpeed.g.cs index 7dbb5613..a1a5f573 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroundSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroundSpeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record GroundSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct GroundSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static GroundSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static GroundSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroundSpeed operator +(GroundSpeed left, GroundSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroundSpeed operator -(GroundSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroundSpeed operator *(GroundSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroundSpeed operator *(T left, GroundSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroundSpeed operator /(GroundSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(GroundSpeed left, GroundSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(GroundSpeed left, GroundSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(GroundSpeed left, GroundSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(GroundSpeed left, GroundSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(GroundSpeed left, GroundSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new GroundSpeed from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroupVelocity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroupVelocity.g.cs index 3a281582..27e7b39b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroupVelocity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/GroupVelocity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record GroupVelocity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct GroupVelocity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static GroupVelocity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static GroupVelocity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroupVelocity operator +(GroupVelocity left, GroupVelocity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroupVelocity operator -(GroupVelocity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroupVelocity operator *(GroupVelocity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroupVelocity operator *(T left, GroupVelocity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static GroupVelocity operator /(GroupVelocity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(GroupVelocity left, GroupVelocity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(GroupVelocity left, GroupVelocity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(GroupVelocity left, GroupVelocity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(GroupVelocity left, GroupVelocity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(GroupVelocity left, GroupVelocity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new GroupVelocity from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HalfLife.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HalfLife.g.cs index c01cd5bb..5a9bb37f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HalfLife.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HalfLife.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record HalfLife : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct HalfLife : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static HalfLife Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static HalfLife Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HalfLife operator +(HalfLife left, HalfLife right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HalfLife operator -(HalfLife value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HalfLife operator *(HalfLife left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HalfLife operator *(T left, HalfLife right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HalfLife operator /(HalfLife left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(HalfLife left, HalfLife right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(HalfLife left, HalfLife right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(HalfLife left, HalfLife right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(HalfLife left, HalfLife right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(HalfLife left, HalfLife right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new HalfLife from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heading.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heading.g.cs index 794535fb..1cde47ff 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heading.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heading.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Heading : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Heading : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Heading Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Heading Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator +(Heading left, Heading right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator -(Heading left, Heading right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator -(Heading value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator *(Heading left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator *(T left, Heading right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heading operator /(Heading left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Heading left, Heading right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Heading left, Heading right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Heading left, Heading right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Heading left, Heading right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Heading left, Heading right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Heading from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heat.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heat.g.cs index 33333d18..4db7494e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heat.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Heat.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Heat : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Heat : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Heat Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Heat Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heat operator +(Heat left, Heat right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heat operator -(Heat value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heat operator *(Heat left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heat operator *(T left, Heat right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Heat operator /(Heat left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Heat left, Heat right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Heat left, Heat right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Heat left, Heat right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Heat left, Heat right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Heat left, Heat right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Heat from a value in Joule. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatCapacity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatCapacity.g.cs index 24b3e03d..5414eea3 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatCapacity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatCapacity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record HeatCapacity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct HeatCapacity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static HeatCapacity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Entropy; + public DimensionInfo Dimension => PhysicalDimensions.Entropy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static HeatCapacity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatCapacity operator +(HeatCapacity left, HeatCapacity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatCapacity operator -(HeatCapacity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatCapacity operator *(HeatCapacity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatCapacity operator *(T left, HeatCapacity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatCapacity operator /(HeatCapacity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(HeatCapacity left, HeatCapacity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(HeatCapacity left, HeatCapacity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(HeatCapacity left, HeatCapacity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(HeatCapacity left, HeatCapacity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(HeatCapacity left, HeatCapacity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new HeatCapacity from a value in JoulePerKelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlowRate.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlowRate.g.cs index 237cd993..6723adfc 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlowRate.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlowRate.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record HeatFlowRate : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct HeatFlowRate : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static HeatFlowRate Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Power; + public DimensionInfo Dimension => PhysicalDimensions.Power; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static HeatFlowRate Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlowRate operator +(HeatFlowRate left, HeatFlowRate right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlowRate operator -(HeatFlowRate value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlowRate operator *(HeatFlowRate left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlowRate operator *(T left, HeatFlowRate right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlowRate operator /(HeatFlowRate left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(HeatFlowRate left, HeatFlowRate right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(HeatFlowRate left, HeatFlowRate right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(HeatFlowRate left, HeatFlowRate right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(HeatFlowRate left, HeatFlowRate right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(HeatFlowRate left, HeatFlowRate right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new HeatFlowRate from a value in Watt. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlux.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlux.g.cs index e80848f1..41c811e7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlux.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatFlux.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record HeatFlux : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct HeatFlux : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static HeatFlux Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Irradiance; + public DimensionInfo Dimension => PhysicalDimensions.Irradiance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static HeatFlux Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlux operator +(HeatFlux left, HeatFlux right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlux operator -(HeatFlux value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlux operator *(HeatFlux left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlux operator *(T left, HeatFlux right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatFlux operator /(HeatFlux left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(HeatFlux left, HeatFlux right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(HeatFlux left, HeatFlux right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(HeatFlux left, HeatFlux right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(HeatFlux left, HeatFlux right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(HeatFlux left, HeatFlux right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new HeatFlux from a value in WattPerSquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatTransferCoefficient.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatTransferCoefficient.g.cs index e3d1ad69..8aed95fb 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatTransferCoefficient.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/HeatTransferCoefficient.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the HeatTransferCoefficient dimension. /// /// The numeric storage type. -public partial record HeatTransferCoefficient : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct HeatTransferCoefficient : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static HeatTransferCoefficient Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.HeatTransferCoefficient; + public DimensionInfo Dimension => PhysicalDimensions.HeatTransferCoefficient; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static HeatTransferCoefficient Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatTransferCoefficient operator +(HeatTransferCoefficient left, HeatTransferCoefficient right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatTransferCoefficient operator -(HeatTransferCoefficient value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatTransferCoefficient operator *(HeatTransferCoefficient left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatTransferCoefficient operator *(T left, HeatTransferCoefficient right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static HeatTransferCoefficient operator /(HeatTransferCoefficient left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(HeatTransferCoefficient left, HeatTransferCoefficient right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(HeatTransferCoefficient left, HeatTransferCoefficient right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(HeatTransferCoefficient left, HeatTransferCoefficient right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(HeatTransferCoefficient left, HeatTransferCoefficient right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(HeatTransferCoefficient left, HeatTransferCoefficient right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in WattPerSquareMeterKelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Height.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Height.g.cs index 0bb0eee3..b64cd8f4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Height.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Height.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Height : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Height : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Height Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Height Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Height operator +(Height left, Height right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Height operator -(Height value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Height operator *(Height left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Height operator *(T left, Height right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Height operator /(Height left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Height left, Height right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Height left, Height right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Height left, Height right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Height left, Height right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Height left, Height right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Height from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Illuminance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Illuminance.g.cs index ec92d7ab..bdaaae93 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Illuminance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Illuminance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Illuminance dimension. /// /// The numeric storage type. -public partial record Illuminance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Illuminance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Illuminance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Illuminance; + public DimensionInfo Dimension => PhysicalDimensions.Illuminance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Illuminance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Illuminance operator +(Illuminance left, Illuminance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Illuminance operator -(Illuminance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Illuminance operator *(Illuminance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Illuminance operator *(T left, Illuminance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Illuminance operator /(Illuminance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Illuminance left, Illuminance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Illuminance left, Illuminance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Illuminance left, Illuminance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Illuminance left, Illuminance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Illuminance left, Illuminance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Lux. @@ -53,6 +128,6 @@ public partial record Illuminance : PhysicalQuantity, T>, IVec /// Multiplies Illuminance by Area to produce LuminousFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static LuminousFlux operator *(Illuminance left, Area right) => Multiply>(left, right); + public static LuminousFlux operator *(Illuminance left, Area right) => LuminousFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Impedance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Impedance.g.cs index ef8904d9..77505c72 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Impedance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Impedance.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Impedance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Impedance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Impedance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricResistance; + public DimensionInfo Dimension => PhysicalDimensions.ElectricResistance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Impedance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Impedance operator +(Impedance left, Impedance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Impedance operator -(Impedance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Impedance operator *(Impedance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Impedance operator *(T left, Impedance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Impedance operator /(Impedance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Impedance left, Impedance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Impedance left, Impedance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Impedance left, Impedance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Impedance left, Impedance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Impedance left, Impedance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Impedance from a value in Ohm. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Inductance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Inductance.g.cs index c58a7812..c67bbb16 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Inductance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Inductance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Inductance dimension. /// /// The numeric storage type. -public partial record Inductance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Inductance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Inductance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Inductance; + public DimensionInfo Dimension => PhysicalDimensions.Inductance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Inductance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Inductance operator +(Inductance left, Inductance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Inductance operator -(Inductance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Inductance operator *(Inductance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Inductance operator *(T left, Inductance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Inductance operator /(Inductance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Inductance left, Inductance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Inductance left, Inductance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Inductance left, Inductance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Inductance left, Inductance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Inductance left, Inductance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Henry. @@ -45,6 +120,6 @@ public partial record Inductance : PhysicalQuantity, T>, IVecto /// Multiplies Inductance by CurrentMagnitude to produce MagneticFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(Inductance left, CurrentMagnitude right) => Multiply>(left, right); + public static MagneticFlux operator *(Inductance left, CurrentMagnitude right) => MagneticFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Irradiance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Irradiance.g.cs index 397f3f12..588a9552 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Irradiance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Irradiance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Irradiance dimension. /// /// The numeric storage type. -public partial record Irradiance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Irradiance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Irradiance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Irradiance; + public DimensionInfo Dimension => PhysicalDimensions.Irradiance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Irradiance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Irradiance operator +(Irradiance left, Irradiance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Irradiance operator -(Irradiance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Irradiance operator *(Irradiance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Irradiance operator *(T left, Irradiance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Irradiance operator /(Irradiance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Irradiance left, Irradiance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Irradiance left, Irradiance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Irradiance left, Irradiance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Irradiance left, Irradiance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Irradiance left, Irradiance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in WattPerSquareMeter. @@ -45,6 +120,6 @@ public partial record Irradiance : PhysicalQuantity, T>, IVecto /// Multiplies Irradiance by Area to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(Irradiance left, Area right) => Multiply>(left, right); + public static Power operator *(Irradiance left, Area right) => Power.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk1D.g.cs index 3c023d5d..79757f9a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Jerk dimension. /// /// The numeric storage type. -public partial record Jerk1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Jerk1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Jerk1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Jerk; + public DimensionInfo Dimension => PhysicalDimensions.Jerk; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Jerk1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator +(Jerk1D left, Jerk1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator -(Jerk1D left, Jerk1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator -(Jerk1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator *(Jerk1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator *(T left, Jerk1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Jerk1D operator /(Jerk1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Jerk1D left, Jerk1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Jerk1D left, Jerk1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Jerk1D left, Jerk1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Jerk1D left, Jerk1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Jerk1D left, Jerk1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondCubed. @@ -43,12 +122,12 @@ public partial record Jerk1D : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Acceleration1D operator *(Jerk1D left, Duration right) => Multiply>(left, right); + public static Acceleration1D operator *(Jerk1D left, Duration right) => Acceleration1D.Create(left.Quantity * right.Quantity); /// /// Divides Jerk1D by Duration to produce Snap1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Snap1D operator /(Jerk1D left, Duration right) => Divide>(left, right); + public static Snap1D operator /(Jerk1D left, Duration right) => Snap1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk2D.g.cs index 3b658d44..c3deb629 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Jerk. /// /// The numeric component type. -public partial record Jerk2D : IVector2, T> +public readonly partial record struct Jerk2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk3D.g.cs index 9013a2df..e5da5a25 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Jerk. /// /// The numeric component type. -public partial record Jerk3D : IVector3, T> +public readonly partial record struct Jerk3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk4D.g.cs index 715b90e4..4eb43e08 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Jerk4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Jerk. /// /// The numeric component type. -public partial record Jerk4D : IVector4, T> +public readonly partial record struct Jerk4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/JerkMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/JerkMagnitude.g.cs index dca9ea3c..e1239d85 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/JerkMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/JerkMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Jerk dimension. /// /// The numeric storage type. -public partial record JerkMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct JerkMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static JerkMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Jerk; + public DimensionInfo Dimension => PhysicalDimensions.Jerk; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static JerkMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static JerkMagnitude operator +(JerkMagnitude left, JerkMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static JerkMagnitude operator -(JerkMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static JerkMagnitude operator *(JerkMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static JerkMagnitude operator *(T left, JerkMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static JerkMagnitude operator /(JerkMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(JerkMagnitude left, JerkMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(JerkMagnitude left, JerkMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(JerkMagnitude left, JerkMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(JerkMagnitude left, JerkMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(JerkMagnitude left, JerkMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondCubed. @@ -45,18 +120,18 @@ public partial record JerkMagnitude : PhysicalQuantity, T>, /// Multiplies JerkMagnitude by Duration to produce AccelerationMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AccelerationMagnitude operator *(JerkMagnitude left, Duration right) => Multiply>(left, right); + public static AccelerationMagnitude operator *(JerkMagnitude left, Duration right) => AccelerationMagnitude.Create(left.Quantity * right.Quantity); /// /// Divides JerkMagnitude by Duration to produce SnapMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SnapMagnitude operator /(JerkMagnitude left, Duration right) => Divide>(left, right); + public static SnapMagnitude operator /(JerkMagnitude left, Duration right) => SnapMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides JerkMagnitude by SnapMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(JerkMagnitude left, SnapMagnitude right) => Divide>(left, right); + public static Duration operator /(JerkMagnitude left, SnapMagnitude right) => Duration.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KinematicViscosity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KinematicViscosity.g.cs index 70f066f9..199479d0 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KinematicViscosity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KinematicViscosity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the KinematicViscosity dimension. /// /// The numeric storage type. -public partial record KinematicViscosity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct KinematicViscosity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static KinematicViscosity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.KinematicViscosity; + public DimensionInfo Dimension => PhysicalDimensions.KinematicViscosity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static KinematicViscosity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KinematicViscosity operator +(KinematicViscosity left, KinematicViscosity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KinematicViscosity operator -(KinematicViscosity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KinematicViscosity operator *(KinematicViscosity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KinematicViscosity operator *(T left, KinematicViscosity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KinematicViscosity operator /(KinematicViscosity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(KinematicViscosity left, KinematicViscosity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(KinematicViscosity left, KinematicViscosity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(KinematicViscosity left, KinematicViscosity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(KinematicViscosity left, KinematicViscosity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(KinematicViscosity left, KinematicViscosity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in SquareMeterPerSecond. @@ -53,6 +128,6 @@ public partial record KinematicViscosity : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static DynamicViscosity operator *(KinematicViscosity left, Density right) => Multiply>(left, right); + public static DynamicViscosity operator *(KinematicViscosity left, Density right) => DynamicViscosity.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KineticEnergy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KineticEnergy.g.cs index 0f8f19c7..4127e732 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KineticEnergy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/KineticEnergy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record KineticEnergy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct KineticEnergy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static KineticEnergy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static KineticEnergy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KineticEnergy operator +(KineticEnergy left, KineticEnergy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KineticEnergy operator -(KineticEnergy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KineticEnergy operator *(KineticEnergy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KineticEnergy operator *(T left, KineticEnergy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static KineticEnergy operator /(KineticEnergy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(KineticEnergy left, KineticEnergy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(KineticEnergy left, KineticEnergy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(KineticEnergy left, KineticEnergy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(KineticEnergy left, KineticEnergy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(KineticEnergy left, KineticEnergy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new KineticEnergy from a value in Joule. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Latency.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Latency.g.cs index ee090178..0db0bed2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Latency.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Latency.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Latency : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Latency : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Latency Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Latency Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Latency operator +(Latency left, Latency right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Latency operator -(Latency value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Latency operator *(Latency left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Latency operator *(T left, Latency right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Latency operator /(Latency left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Latency left, Latency right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Latency left, Latency right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Latency left, Latency right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Latency left, Latency right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Latency left, Latency right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Latency from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Length.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Length.g.cs index 66842dd2..8f01cb65 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Length.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Length.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Length dimension. /// /// The numeric storage type. -public partial record Length : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Length : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Length Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Length Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Length operator +(Length left, Length right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Length operator -(Length value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Length operator *(Length left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Length operator *(T left, Length right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Length operator /(Length left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Length left, Length right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Length left, Length right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Length left, Length right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Length left, Length right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Length left, Length right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Meter. @@ -133,54 +208,54 @@ public partial record Length : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator *(Length left, Length right) => Multiply>(left, right); + public static Area operator *(Length left, Length right) => Area.Create(left.Quantity * right.Quantity); /// /// Multiplies Length by Area to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator *(Length left, Area right) => Multiply>(left, right); + public static Volume operator *(Length left, Area right) => Volume.Create(left.Quantity * right.Quantity); /// /// Divides Length by Duration to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator /(Length left, Duration right) => Divide>(left, right); + public static Speed operator /(Length left, Duration right) => Speed.Create(left.Quantity / right.Quantity); /// /// Divides Length by Speed to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Length left, Speed right) => Divide>(left, right); + public static Duration operator /(Length left, Speed right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies Length by Frequency to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator *(Length left, Frequency right) => Multiply>(left, right); + public static Speed operator *(Length left, Frequency right) => Speed.Create(left.Quantity * right.Quantity); /// /// Multiplies Length by ForceMagnitude to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Length left, ForceMagnitude right) => Multiply>(left, right); + public static Energy operator *(Length left, ForceMagnitude right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies Length by ElectricFieldMagnitude to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(Length left, ElectricFieldMagnitude right) => Multiply>(left, right); + public static VoltageMagnitude operator *(Length left, ElectricFieldMagnitude right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Length by ElectricField1D to produce Voltage. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Voltage operator *(Length left, ElectricField1D right) => Multiply>(left, right); + public static Voltage operator *(Length left, ElectricField1D right) => Voltage.Create(left.Quantity * right.Quantity); /// /// Multiplies Length by SurfaceTension to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(Length left, SurfaceTension right) => Multiply>(left, right); + public static ForceMagnitude operator *(Length left, SurfaceTension right) => ForceMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Lift.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Lift.g.cs index 40e4a802..ec1d7cf1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Lift.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Lift.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Lift : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Lift : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Lift Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Lift Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Lift operator +(Lift left, Lift right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Lift operator -(Lift value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Lift operator *(Lift left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Lift operator *(T left, Lift right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Lift operator /(Lift left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Lift left, Lift right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Lift left, Lift right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Lift left, Lift right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Lift left, Lift right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Lift left, Lift right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Lift from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Loudness.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Loudness.g.cs index 90d30cfa..d6979d5e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Loudness.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Loudness.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Loudness dimension. /// /// The numeric storage type. -public partial record Loudness : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Loudness : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Loudness Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Loudness; + public DimensionInfo Dimension => PhysicalDimensions.Loudness; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Loudness Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Loudness operator +(Loudness left, Loudness right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Loudness operator -(Loudness value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Loudness operator *(Loudness left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Loudness operator *(T left, Loudness right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Loudness operator /(Loudness left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Loudness left, Loudness right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Loudness left, Loudness right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Loudness left, Loudness right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Loudness left, Loudness right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Loudness left, Loudness right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Sone. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Luminance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Luminance.g.cs index 815ac77e..f66a7125 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Luminance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Luminance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Luminance dimension. /// /// The numeric storage type. -public partial record Luminance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Luminance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Luminance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Luminance; + public DimensionInfo Dimension => PhysicalDimensions.Luminance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Luminance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Luminance operator +(Luminance left, Luminance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Luminance operator -(Luminance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Luminance operator *(Luminance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Luminance operator *(T left, Luminance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Luminance operator /(Luminance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Luminance left, Luminance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Luminance left, Luminance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Luminance left, Luminance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Luminance left, Luminance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Luminance left, Luminance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in CandelaPerSquareMeter. @@ -61,6 +136,6 @@ public partial record Luminance : PhysicalQuantity, T>, IVector0 /// Multiplies Luminance by Area to produce LuminousIntensity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static LuminousIntensity operator *(Luminance left, Area right) => Multiply>(left, right); + public static LuminousIntensity operator *(Luminance left, Area right) => LuminousIntensity.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousFlux.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousFlux.g.cs index d762a7eb..8ca42f43 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousFlux.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousFlux.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the LuminousFlux dimension. /// /// The numeric storage type. -public partial record LuminousFlux : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct LuminousFlux : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static LuminousFlux Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.LuminousFlux; + public DimensionInfo Dimension => PhysicalDimensions.LuminousFlux; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static LuminousFlux Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousFlux operator +(LuminousFlux left, LuminousFlux right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousFlux operator -(LuminousFlux value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousFlux operator *(LuminousFlux left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousFlux operator *(T left, LuminousFlux right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousFlux operator /(LuminousFlux left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(LuminousFlux left, LuminousFlux right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(LuminousFlux left, LuminousFlux right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(LuminousFlux left, LuminousFlux right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(LuminousFlux left, LuminousFlux right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(LuminousFlux left, LuminousFlux right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Lumen. @@ -45,12 +120,12 @@ public partial record LuminousFlux : PhysicalQuantity, T>, IV /// Divides LuminousFlux by Area to produce Illuminance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Illuminance operator /(LuminousFlux left, Area right) => Divide>(left, right); + public static Illuminance operator /(LuminousFlux left, Area right) => Illuminance.Create(left.Quantity / right.Quantity); /// /// Divides LuminousFlux by Illuminance to produce Area. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(LuminousFlux left, Illuminance right) => Divide>(left, right); + public static Area operator /(LuminousFlux left, Illuminance right) => Area.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousIntensity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousIntensity.g.cs index fc68cf7e..7049ca68 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousIntensity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/LuminousIntensity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the LuminousIntensity dimension. /// /// The numeric storage type. -public partial record LuminousIntensity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct LuminousIntensity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static LuminousIntensity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.LuminousIntensity; + public DimensionInfo Dimension => PhysicalDimensions.LuminousIntensity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static LuminousIntensity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousIntensity operator +(LuminousIntensity left, LuminousIntensity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousIntensity operator -(LuminousIntensity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousIntensity operator *(LuminousIntensity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousIntensity operator *(T left, LuminousIntensity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static LuminousIntensity operator /(LuminousIntensity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(LuminousIntensity left, LuminousIntensity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(LuminousIntensity left, LuminousIntensity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(LuminousIntensity left, LuminousIntensity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(LuminousIntensity left, LuminousIntensity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(LuminousIntensity left, LuminousIntensity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Candela. @@ -53,12 +128,12 @@ public partial record LuminousIntensity : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Luminance operator /(LuminousIntensity left, Area right) => Divide>(left, right); + public static Luminance operator /(LuminousIntensity left, Area right) => Luminance.Create(left.Quantity / right.Quantity); /// /// Divides LuminousIntensity by Luminance to produce Area. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(LuminousIntensity left, Luminance right) => Divide>(left, right); + public static Area operator /(LuminousIntensity left, Luminance right) => Area.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MachNumber.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MachNumber.g.cs index 16e030c3..6f6a7da7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MachNumber.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MachNumber.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record MachNumber : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MachNumber : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MachNumber Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MachNumber Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MachNumber operator +(MachNumber left, MachNumber right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MachNumber operator -(MachNumber value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MachNumber operator *(MachNumber left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MachNumber operator *(T left, MachNumber right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MachNumber operator /(MachNumber left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MachNumber left, MachNumber right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MachNumber left, MachNumber right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MachNumber left, MachNumber right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MachNumber left, MachNumber right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MachNumber left, MachNumber right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new MachNumber from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFlux.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFlux.g.cs index c9b498bd..3b7db79f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFlux.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFlux.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MagneticFlux dimension. /// /// The numeric storage type. -public partial record MagneticFlux : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MagneticFlux : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MagneticFlux Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MagneticFlux; + public DimensionInfo Dimension => PhysicalDimensions.MagneticFlux; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MagneticFlux Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFlux operator +(MagneticFlux left, MagneticFlux right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFlux operator -(MagneticFlux value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFlux operator *(MagneticFlux left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFlux operator *(T left, MagneticFlux right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFlux operator /(MagneticFlux left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MagneticFlux left, MagneticFlux right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MagneticFlux left, MagneticFlux right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MagneticFlux left, MagneticFlux right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MagneticFlux left, MagneticFlux right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MagneticFlux left, MagneticFlux right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Weber. @@ -45,30 +120,30 @@ public partial record MagneticFlux : PhysicalQuantity, T>, IV /// Divides MagneticFlux by Area to produce MagneticFluxDensityMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFluxDensityMagnitude operator /(MagneticFlux left, Area right) => Divide>(left, right); + public static MagneticFluxDensityMagnitude operator /(MagneticFlux left, Area right) => MagneticFluxDensityMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides MagneticFlux by MagneticFluxDensityMagnitude to produce Area. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(MagneticFlux left, MagneticFluxDensityMagnitude right) => Divide>(left, right); + public static Area operator /(MagneticFlux left, MagneticFluxDensityMagnitude right) => Area.Create(left.Quantity / right.Quantity); /// /// Divides MagneticFlux by Duration to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator /(MagneticFlux left, Duration right) => Divide>(left, right); + public static VoltageMagnitude operator /(MagneticFlux left, Duration right) => VoltageMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides MagneticFlux by CurrentMagnitude to produce Inductance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Inductance operator /(MagneticFlux left, CurrentMagnitude right) => Divide>(left, right); + public static Inductance operator /(MagneticFlux left, CurrentMagnitude right) => Inductance.Create(left.Quantity / right.Quantity); /// /// Divides MagneticFlux by Inductance to produce CurrentMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator /(MagneticFlux left, Inductance right) => Divide>(left, right); + public static CurrentMagnitude operator /(MagneticFlux left, Inductance right) => CurrentMagnitude.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensity3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensity3D.g.cs index ba854e38..f5d7bb0b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensity3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensity3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of MagneticFluxDensity. /// /// The numeric component type. -public partial record MagneticFluxDensity3D : IVector3, T> +public readonly partial record struct MagneticFluxDensity3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensityMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensityMagnitude.g.cs index 04c174f1..24b78780 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensityMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MagneticFluxDensityMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MagneticFluxDensity dimension. /// /// The numeric storage type. -public partial record MagneticFluxDensityMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MagneticFluxDensityMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MagneticFluxDensityMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MagneticFluxDensity; + public DimensionInfo Dimension => PhysicalDimensions.MagneticFluxDensity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MagneticFluxDensityMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFluxDensityMagnitude operator +(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFluxDensityMagnitude operator -(MagneticFluxDensityMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFluxDensityMagnitude operator *(MagneticFluxDensityMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFluxDensityMagnitude operator *(T left, MagneticFluxDensityMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MagneticFluxDensityMagnitude operator /(MagneticFluxDensityMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Tesla. @@ -53,6 +128,6 @@ public partial record MagneticFluxDensityMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(MagneticFluxDensityMagnitude left, Area right) => Multiply>(left, right); + public static MagneticFlux operator *(MagneticFluxDensityMagnitude left, Area right) => MagneticFlux.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Mass.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Mass.g.cs index 9adb0fca..eda6e446 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Mass.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Mass.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Mass dimension. /// /// The numeric storage type. -public partial record Mass : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Mass : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Mass Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Mass; + public DimensionInfo Dimension => PhysicalDimensions.Mass; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Mass Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Mass operator +(Mass left, Mass right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Mass operator -(Mass value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Mass operator *(Mass left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Mass operator *(T left, Mass right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Mass operator /(Mass left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Mass left, Mass right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Mass left, Mass right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Mass left, Mass right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Mass left, Mass right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Mass left, Mass right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Kilogram. @@ -101,54 +176,54 @@ public partial record Mass : PhysicalQuantity, T>, IVector0, /// Multiplies Mass by AccelerationMagnitude to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(Mass left, AccelerationMagnitude right) => Multiply>(left, right); + public static ForceMagnitude operator *(Mass left, AccelerationMagnitude right) => ForceMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Mass by Speed to produce MomentumMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentumMagnitude operator *(Mass left, Speed right) => Multiply>(left, right); + public static MomentumMagnitude operator *(Mass left, Speed right) => MomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Divides Mass by Volume to produce Density. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Density operator /(Mass left, Volume right) => Divide>(left, right); + public static Density operator /(Mass left, Volume right) => Density.Create(left.Quantity / right.Quantity); /// /// Divides Mass by Density to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator /(Mass left, Density right) => Divide>(left, right); + public static Volume operator /(Mass left, Density right) => Volume.Create(left.Quantity / right.Quantity); /// /// Multiplies Mass by SpecificHeat to produce Entropy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Entropy operator *(Mass left, SpecificHeat right) => Multiply>(left, right); + public static Entropy operator *(Mass left, SpecificHeat right) => Entropy.Create(left.Quantity * right.Quantity); /// /// Divides Mass by Duration to produce MassFlowRate. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MassFlowRate operator /(Mass left, Duration right) => Divide>(left, right); + public static MassFlowRate operator /(Mass left, Duration right) => MassFlowRate.Create(left.Quantity / right.Quantity); /// /// Divides Mass by MassFlowRate to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Mass left, MassFlowRate right) => Divide>(left, right); + public static Duration operator /(Mass left, MassFlowRate right) => Duration.Create(left.Quantity / right.Quantity); /// /// Divides Mass by AmountOfSubstance to produce MolarMass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MolarMass operator /(Mass left, AmountOfSubstance right) => Divide>(left, right); + public static MolarMass operator /(Mass left, AmountOfSubstance right) => MolarMass.Create(left.Quantity / right.Quantity); /// /// Divides Mass by MolarMass to produce AmountOfSubstance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator /(Mass left, MolarMass right) => Divide>(left, right); + public static AmountOfSubstance operator /(Mass left, MolarMass right) => AmountOfSubstance.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MassFlowRate.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MassFlowRate.g.cs index 8b67bc84..5228eedf 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MassFlowRate.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MassFlowRate.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MassFlowRate dimension. /// /// The numeric storage type. -public partial record MassFlowRate : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MassFlowRate : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MassFlowRate Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MassFlowRate; + public DimensionInfo Dimension => PhysicalDimensions.MassFlowRate; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MassFlowRate Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MassFlowRate operator +(MassFlowRate left, MassFlowRate right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MassFlowRate operator -(MassFlowRate value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MassFlowRate operator *(MassFlowRate left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MassFlowRate operator *(T left, MassFlowRate right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MassFlowRate operator /(MassFlowRate left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MassFlowRate left, MassFlowRate right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MassFlowRate left, MassFlowRate right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MassFlowRate left, MassFlowRate right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MassFlowRate left, MassFlowRate right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MassFlowRate left, MassFlowRate right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramPerSecond. @@ -45,6 +120,6 @@ public partial record MassFlowRate : PhysicalQuantity, T>, IV /// Multiplies MassFlowRate by Duration to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(MassFlowRate left, Duration right) => Multiply>(left, right); + public static Mass operator *(MassFlowRate left, Duration right) => Mass.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnergy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnergy.g.cs index 406ae72f..c65f3980 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnergy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnergy.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MolarEnergy dimension. /// /// The numeric storage type. -public partial record MolarEnergy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MolarEnergy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MolarEnergy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + public DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MolarEnergy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnergy operator +(MolarEnergy left, MolarEnergy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnergy operator -(MolarEnergy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnergy operator *(MolarEnergy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnergy operator *(T left, MolarEnergy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnergy operator /(MolarEnergy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MolarEnergy left, MolarEnergy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MolarEnergy left, MolarEnergy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MolarEnergy left, MolarEnergy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MolarEnergy left, MolarEnergy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MolarEnergy left, MolarEnergy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in JoulePerMole. @@ -61,6 +136,6 @@ public partial record MolarEnergy : PhysicalQuantity, T>, IVec /// Multiplies MolarEnergy by AmountOfSubstance to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(MolarEnergy left, AmountOfSubstance right) => Multiply>(left, right); + public static Energy operator *(MolarEnergy left, AmountOfSubstance right) => Energy.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnthalpy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnthalpy.g.cs index ae79fe74..abf47f0c 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnthalpy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarEnthalpy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record MolarEnthalpy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MolarEnthalpy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MolarEnthalpy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + public DimensionInfo Dimension => PhysicalDimensions.MolarEnergy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MolarEnthalpy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnthalpy operator +(MolarEnthalpy left, MolarEnthalpy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnthalpy operator -(MolarEnthalpy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnthalpy operator *(MolarEnthalpy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnthalpy operator *(T left, MolarEnthalpy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarEnthalpy operator /(MolarEnthalpy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MolarEnthalpy left, MolarEnthalpy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MolarEnthalpy left, MolarEnthalpy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MolarEnthalpy left, MolarEnthalpy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MolarEnthalpy left, MolarEnthalpy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MolarEnthalpy left, MolarEnthalpy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new MolarEnthalpy from a value in JoulePerMole. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarMass.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarMass.g.cs index 37ad7236..eb0b6849 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarMass.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MolarMass.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MolarMass dimension. /// /// The numeric storage type. -public partial record MolarMass : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MolarMass : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MolarMass Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MolarMass; + public DimensionInfo Dimension => PhysicalDimensions.MolarMass; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MolarMass Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarMass operator +(MolarMass left, MolarMass right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarMass operator -(MolarMass value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarMass operator *(MolarMass left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarMass operator *(T left, MolarMass right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MolarMass operator /(MolarMass left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MolarMass left, MolarMass right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MolarMass left, MolarMass right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MolarMass left, MolarMass right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MolarMass left, MolarMass right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MolarMass left, MolarMass right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramPerMole. @@ -61,6 +136,6 @@ public partial record MolarMass : PhysicalQuantity, T>, IVector0 /// Multiplies MolarMass by AmountOfSubstance to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(MolarMass left, AmountOfSubstance right) => Multiply>(left, right); + public static Mass operator *(MolarMass left, AmountOfSubstance right) => Mass.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentOfInertia.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentOfInertia.g.cs index 33c28c24..26ccccdd 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentOfInertia.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentOfInertia.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the MomentOfInertia dimension. /// /// The numeric storage type. -public partial record MomentOfInertia : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MomentOfInertia : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MomentOfInertia Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.MomentOfInertia; + public DimensionInfo Dimension => PhysicalDimensions.MomentOfInertia; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MomentOfInertia Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentOfInertia operator +(MomentOfInertia left, MomentOfInertia right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentOfInertia operator -(MomentOfInertia value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentOfInertia operator *(MomentOfInertia left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentOfInertia operator *(T left, MomentOfInertia right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentOfInertia operator /(MomentOfInertia left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MomentOfInertia left, MomentOfInertia right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MomentOfInertia left, MomentOfInertia right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MomentOfInertia left, MomentOfInertia right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MomentOfInertia left, MomentOfInertia right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MomentOfInertia left, MomentOfInertia right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KilogramMeterSquared. @@ -45,12 +120,12 @@ public partial record MomentOfInertia : PhysicalQuantity, /// Multiplies MomentOfInertia by AngularSpeed to produce AngularMomentumMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentumMagnitude operator *(MomentOfInertia left, AngularSpeed right) => Multiply>(left, right); + public static AngularMomentumMagnitude operator *(MomentOfInertia left, AngularSpeed right) => AngularMomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies MomentOfInertia by AngularAccelerationMagnitude to produce TorqueMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static TorqueMagnitude operator *(MomentOfInertia left, AngularAccelerationMagnitude right) => Multiply>(left, right); + public static TorqueMagnitude operator *(MomentOfInertia left, AngularAccelerationMagnitude right) => TorqueMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum1D.g.cs index 1958483c..96208902 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Momentum dimension. /// /// The numeric storage type. -public partial record Momentum1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Momentum1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Momentum1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Momentum; + public DimensionInfo Dimension => PhysicalDimensions.Momentum; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Momentum1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator +(Momentum1D left, Momentum1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator -(Momentum1D left, Momentum1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator -(Momentum1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator *(Momentum1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator *(T left, Momentum1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Momentum1D operator /(Momentum1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Momentum1D left, Momentum1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Momentum1D left, Momentum1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Momentum1D left, Momentum1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Momentum1D left, Momentum1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Momentum1D left, Momentum1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in NewtonSecond. @@ -43,6 +122,6 @@ public partial record Momentum1D : PhysicalQuantity, T>, IVecto /// Divides Momentum1D by Duration to produce Force1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Force1D operator /(Momentum1D left, Duration right) => Divide>(left, right); + public static Force1D operator /(Momentum1D left, Duration right) => Force1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum2D.g.cs index 800585b8..1e54744a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Momentum. /// /// The numeric component type. -public partial record Momentum2D : IVector2, T> +public readonly partial record struct Momentum2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum3D.g.cs index 9ec7de96..50014cee 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Momentum. /// /// The numeric component type. -public partial record Momentum3D : IVector3, T> +public readonly partial record struct Momentum3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum4D.g.cs index fb04ade7..7eb818f9 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Momentum4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Momentum. /// /// The numeric component type. -public partial record Momentum4D : IVector4, T> +public readonly partial record struct Momentum4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentumMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentumMagnitude.g.cs index 59c69108..f39c5ab3 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentumMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/MomentumMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Momentum dimension. /// /// The numeric storage type. -public partial record MomentumMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct MomentumMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static MomentumMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Momentum; + public DimensionInfo Dimension => PhysicalDimensions.Momentum; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static MomentumMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentumMagnitude operator +(MomentumMagnitude left, MomentumMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentumMagnitude operator -(MomentumMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentumMagnitude operator *(MomentumMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentumMagnitude operator *(T left, MomentumMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static MomentumMagnitude operator /(MomentumMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(MomentumMagnitude left, MomentumMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(MomentumMagnitude left, MomentumMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(MomentumMagnitude left, MomentumMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(MomentumMagnitude left, MomentumMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(MomentumMagnitude left, MomentumMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in NewtonSecond. @@ -45,24 +120,24 @@ public partial record MomentumMagnitude : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator /(MomentumMagnitude left, Speed right) => Divide>(left, right); + public static Mass operator /(MomentumMagnitude left, Speed right) => Mass.Create(left.Quantity / right.Quantity); /// /// Divides MomentumMagnitude by Mass to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator /(MomentumMagnitude left, Mass right) => Divide>(left, right); + public static Speed operator /(MomentumMagnitude left, Mass right) => Speed.Create(left.Quantity / right.Quantity); /// /// Divides MomentumMagnitude by Duration to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator /(MomentumMagnitude left, Duration right) => Divide>(left, right); + public static ForceMagnitude operator /(MomentumMagnitude left, Duration right) => ForceMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides MomentumMagnitude by ForceMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(MomentumMagnitude left, ForceMagnitude right) => Divide>(left, right); + public static Duration operator /(MomentumMagnitude left, ForceMagnitude right) => Duration.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NoiseReductionCoefficient.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NoiseReductionCoefficient.g.cs index 69f67dbb..c8aef8c4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NoiseReductionCoefficient.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NoiseReductionCoefficient.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record NoiseReductionCoefficient : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct NoiseReductionCoefficient : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static NoiseReductionCoefficient Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static NoiseReductionCoefficient Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NoiseReductionCoefficient operator +(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NoiseReductionCoefficient operator -(NoiseReductionCoefficient value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NoiseReductionCoefficient operator *(NoiseReductionCoefficient left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NoiseReductionCoefficient operator *(T left, NoiseReductionCoefficient right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NoiseReductionCoefficient operator /(NoiseReductionCoefficient left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(NoiseReductionCoefficient left, NoiseReductionCoefficient right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new NoiseReductionCoefficient from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NormalForce.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NormalForce.g.cs index e5807f1a..6a76fbde 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NormalForce.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NormalForce.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record NormalForce : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct NormalForce : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static NormalForce Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static NormalForce Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NormalForce operator +(NormalForce left, NormalForce right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NormalForce operator -(NormalForce value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NormalForce operator *(NormalForce left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NormalForce operator *(T left, NormalForce right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NormalForce operator /(NormalForce left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(NormalForce left, NormalForce right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(NormalForce left, NormalForce right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(NormalForce left, NormalForce right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(NormalForce left, NormalForce right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(NormalForce left, NormalForce right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new NormalForce from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NuclearCrossSection.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NuclearCrossSection.g.cs index d6be05ad..a884fb4b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NuclearCrossSection.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/NuclearCrossSection.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the NuclearCrossSection dimension. /// /// The numeric storage type. -public partial record NuclearCrossSection : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct NuclearCrossSection : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static NuclearCrossSection Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.NuclearCrossSection; + public DimensionInfo Dimension => PhysicalDimensions.NuclearCrossSection; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static NuclearCrossSection Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NuclearCrossSection operator +(NuclearCrossSection left, NuclearCrossSection right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NuclearCrossSection operator -(NuclearCrossSection value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NuclearCrossSection operator *(NuclearCrossSection left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NuclearCrossSection operator *(T left, NuclearCrossSection right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static NuclearCrossSection operator /(NuclearCrossSection left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(NuclearCrossSection left, NuclearCrossSection right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(NuclearCrossSection left, NuclearCrossSection right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(NuclearCrossSection left, NuclearCrossSection right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(NuclearCrossSection left, NuclearCrossSection right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(NuclearCrossSection left, NuclearCrossSection right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in SquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Offset.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Offset.g.cs index 5b82fb65..56d3a088 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Offset.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Offset.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Offset : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Offset : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Offset Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Offset Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator +(Offset left, Offset right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator -(Offset left, Offset right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator -(Offset value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator *(Offset left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator *(T left, Offset right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Offset operator /(Offset left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Offset left, Offset right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Offset left, Offset right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Offset left, Offset right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Offset left, Offset right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Offset left, Offset right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Offset from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/OpticalPower.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/OpticalPower.g.cs index 6c03357f..f4cf849e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/OpticalPower.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/OpticalPower.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the OpticalPower dimension. /// /// The numeric storage type. -public partial record OpticalPower : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct OpticalPower : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static OpticalPower Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.OpticalPower; + public DimensionInfo Dimension => PhysicalDimensions.OpticalPower; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static OpticalPower Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static OpticalPower operator +(OpticalPower left, OpticalPower right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static OpticalPower operator -(OpticalPower value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static OpticalPower operator *(OpticalPower left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static OpticalPower operator *(T left, OpticalPower right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static OpticalPower operator /(OpticalPower left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(OpticalPower left, OpticalPower right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(OpticalPower left, OpticalPower right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(OpticalPower left, OpticalPower right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(OpticalPower left, OpticalPower right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(OpticalPower left, OpticalPower right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Diopter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Perimeter.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Perimeter.g.cs index 2942b986..27a1fe60 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Perimeter.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Perimeter.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Perimeter : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Perimeter : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Perimeter Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Perimeter Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Perimeter operator +(Perimeter left, Perimeter right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Perimeter operator -(Perimeter value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Perimeter operator *(Perimeter left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Perimeter operator *(T left, Perimeter right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Perimeter operator /(Perimeter left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Perimeter left, Perimeter right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Perimeter left, Perimeter right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Perimeter left, Perimeter right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Perimeter left, Perimeter right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Perimeter left, Perimeter right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Perimeter from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Period.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Period.g.cs index ac85e8d3..4698e263 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Period.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Period.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Period : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Period : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Period Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Period Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Period operator +(Period left, Period right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Period operator -(Period value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Period operator *(Period left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Period operator *(T left, Period right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Period operator /(Period left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Period left, Period right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Period left, Period right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Period left, Period right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Period left, Period right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Period left, Period right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Period from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Permittivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Permittivity.g.cs index 5adc8675..77e29f00 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Permittivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Permittivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Permittivity dimension. /// /// The numeric storage type. -public partial record Permittivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Permittivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Permittivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Permittivity; + public DimensionInfo Dimension => PhysicalDimensions.Permittivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Permittivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Permittivity operator +(Permittivity left, Permittivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Permittivity operator -(Permittivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Permittivity operator *(Permittivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Permittivity operator *(T left, Permittivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Permittivity operator /(Permittivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Permittivity left, Permittivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Permittivity left, Permittivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Permittivity left, Permittivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Permittivity left, Permittivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Permittivity left, Permittivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in FaradPerMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Phase.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Phase.g.cs index fb50e237..170b3b07 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Phase.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Phase.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Phase : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Phase : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Phase Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Phase Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator +(Phase left, Phase right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator -(Phase left, Phase right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator -(Phase value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator *(Phase left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator *(T left, Phase right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Phase operator /(Phase left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Phase left, Phase right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Phase left, Phase right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Phase left, Phase right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Phase left, Phase right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Phase left, Phase right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Phase from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PhaseVelocity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PhaseVelocity.g.cs index c79a8de6..1444d5cf 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PhaseVelocity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PhaseVelocity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record PhaseVelocity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct PhaseVelocity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static PhaseVelocity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static PhaseVelocity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PhaseVelocity operator +(PhaseVelocity left, PhaseVelocity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PhaseVelocity operator -(PhaseVelocity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PhaseVelocity operator *(PhaseVelocity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PhaseVelocity operator *(T left, PhaseVelocity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PhaseVelocity operator /(PhaseVelocity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(PhaseVelocity left, PhaseVelocity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(PhaseVelocity left, PhaseVelocity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(PhaseVelocity left, PhaseVelocity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(PhaseVelocity left, PhaseVelocity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(PhaseVelocity left, PhaseVelocity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new PhaseVelocity from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pitch.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pitch.g.cs index e62b5832..d1a0121e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pitch.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pitch.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Pitch : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Pitch : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Pitch Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Frequency; + public DimensionInfo Dimension => PhysicalDimensions.Frequency; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Pitch Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pitch operator +(Pitch left, Pitch right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pitch operator -(Pitch value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pitch operator *(Pitch left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pitch operator *(T left, Pitch right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pitch operator /(Pitch left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Pitch left, Pitch right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Pitch left, Pitch right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Pitch left, Pitch right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Pitch left, Pitch right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Pitch left, Pitch right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Pitch from a value in Hertz. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Position3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Position3D.g.cs index 1c9ac42b..eb1cd7a2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Position3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Position3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Location in 3D space relative to an origin. /// Semantic overload of . /// -public partial record Position3D : IVector3, T> +public readonly partial record struct Position3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PotentialEnergy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PotentialEnergy.g.cs index 61aa44ba..276a7607 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PotentialEnergy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/PotentialEnergy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record PotentialEnergy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct PotentialEnergy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static PotentialEnergy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static PotentialEnergy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PotentialEnergy operator +(PotentialEnergy left, PotentialEnergy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PotentialEnergy operator -(PotentialEnergy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PotentialEnergy operator *(PotentialEnergy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PotentialEnergy operator *(T left, PotentialEnergy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static PotentialEnergy operator /(PotentialEnergy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(PotentialEnergy left, PotentialEnergy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(PotentialEnergy left, PotentialEnergy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(PotentialEnergy left, PotentialEnergy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(PotentialEnergy left, PotentialEnergy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(PotentialEnergy left, PotentialEnergy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new PotentialEnergy from a value in Joule. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Power.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Power.g.cs index 0671b1be..28fcc7b8 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Power.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Power.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Power dimension. /// /// The numeric storage type. -public partial record Power : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Power : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Power Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Power; + public DimensionInfo Dimension => PhysicalDimensions.Power; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Power Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Power operator +(Power left, Power right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Power operator -(Power value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Power operator *(Power left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Power operator *(T left, Power right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Power operator /(Power left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Power left, Power right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Power left, Power right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Power left, Power right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Power left, Power right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Power left, Power right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Watt. @@ -69,54 +144,54 @@ public partial record Power : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator /(Power left, VoltageMagnitude right) => Divide>(left, right); + public static CurrentMagnitude operator /(Power left, VoltageMagnitude right) => CurrentMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Power by CurrentMagnitude to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator /(Power left, CurrentMagnitude right) => Divide>(left, right); + public static VoltageMagnitude operator /(Power left, CurrentMagnitude right) => VoltageMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Power by Speed to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator /(Power left, Speed right) => Divide>(left, right); + public static ForceMagnitude operator /(Power left, Speed right) => ForceMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Power by ForceMagnitude to produce Speed. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Speed operator /(Power left, ForceMagnitude right) => Divide>(left, right); + public static Speed operator /(Power left, ForceMagnitude right) => Speed.Create(left.Quantity / right.Quantity); /// /// Multiplies Power by Duration to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Power left, Duration right) => Multiply>(left, right); + public static Energy operator *(Power left, Duration right) => Energy.Create(left.Quantity * right.Quantity); /// /// Divides Power by Area to produce Irradiance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Irradiance operator /(Power left, Area right) => Divide>(left, right); + public static Irradiance operator /(Power left, Area right) => Irradiance.Create(left.Quantity / right.Quantity); /// /// Divides Power by Irradiance to produce Area. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(Power left, Irradiance right) => Divide>(left, right); + public static Area operator /(Power left, Irradiance right) => Area.Create(left.Quantity / right.Quantity); /// /// Divides Power by Volume to produce ElectricPowerDensity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricPowerDensity operator /(Power left, Volume right) => Divide>(left, right); + public static ElectricPowerDensity operator /(Power left, Volume right) => ElectricPowerDensity.Create(left.Quantity / right.Quantity); /// /// Divides Power by ElectricPowerDensity to produce Volume. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator /(Power left, ElectricPowerDensity right) => Divide>(left, right); + public static Volume operator /(Power left, ElectricPowerDensity right) => Volume.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pressure.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pressure.g.cs index a5c7c9ef..ab48b62e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pressure.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Pressure.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Pressure dimension. /// /// The numeric storage type. -public partial record Pressure : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Pressure : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Pressure Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Pressure Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pressure operator +(Pressure left, Pressure right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pressure operator -(Pressure value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pressure operator *(Pressure left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pressure operator *(T left, Pressure right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Pressure operator /(Pressure left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Pressure left, Pressure right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Pressure left, Pressure right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Pressure left, Pressure right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Pressure left, Pressure right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Pressure left, Pressure right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Pascal. @@ -85,18 +160,18 @@ public partial record Pressure : PhysicalQuantity, T>, IVector0

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(Pressure left, Area right) => Multiply>(left, right); + public static ForceMagnitude operator *(Pressure left, Area right) => ForceMagnitude.Create(left.Quantity * right.Quantity); ///

/// Multiplies Pressure by Volume to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Pressure left, Volume right) => Multiply>(left, right); + public static Energy operator *(Pressure left, Volume right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies Pressure by Sensitivity to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(Pressure left, Sensitivity right) => Multiply>(left, right); + public static VoltageMagnitude operator *(Pressure left, Sensitivity right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RadioactiveActivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RadioactiveActivity.g.cs index 8f16d6c1..46cecf22 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RadioactiveActivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RadioactiveActivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the RadioactiveActivity dimension. ///
/// The numeric storage type. -public partial record RadioactiveActivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct RadioactiveActivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static RadioactiveActivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.RadioactiveActivity; + public DimensionInfo Dimension => PhysicalDimensions.RadioactiveActivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static RadioactiveActivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RadioactiveActivity operator +(RadioactiveActivity left, RadioactiveActivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RadioactiveActivity operator -(RadioactiveActivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RadioactiveActivity operator *(RadioactiveActivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RadioactiveActivity operator *(T left, RadioactiveActivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RadioactiveActivity operator /(RadioactiveActivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(RadioactiveActivity left, RadioactiveActivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(RadioactiveActivity left, RadioactiveActivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(RadioactiveActivity left, RadioactiveActivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(RadioactiveActivity left, RadioactiveActivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(RadioactiveActivity left, RadioactiveActivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Becquerel. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Radius.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Radius.g.cs index 7e275f30..f660f576 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Radius.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Radius.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Radius : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Radius : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Radius Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Radius Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Radius operator +(Radius left, Radius right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Radius operator -(Radius value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Radius operator *(Radius left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Radius operator *(T left, Radius right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Radius operator /(Radius left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Radius left, Radius right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Radius left, Radius right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Radius left, Radius right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Radius left, Radius right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Radius left, Radius right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Radius from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RateConstant.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RateConstant.g.cs index 80c8ac7a..8ebc5067 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RateConstant.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RateConstant.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the RateConstant dimension. /// /// The numeric storage type. -public partial record RateConstant : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct RateConstant : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static RateConstant Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.RateConstant; + public DimensionInfo Dimension => PhysicalDimensions.RateConstant; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static RateConstant Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RateConstant operator +(RateConstant left, RateConstant right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RateConstant operator -(RateConstant value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RateConstant operator *(RateConstant left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RateConstant operator *(T left, RateConstant right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RateConstant operator /(RateConstant left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(RateConstant left, RateConstant right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(RateConstant left, RateConstant right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(RateConstant left, RateConstant right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(RateConstant left, RateConstant right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(RateConstant left, RateConstant right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in PerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Ratio.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Ratio.g.cs index df50e427..121932c0 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Ratio.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Ratio.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Dimensionless dimension. /// /// The numeric storage type. -public partial record Ratio : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Ratio : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Ratio Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Ratio Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Ratio operator +(Ratio left, Ratio right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Ratio operator -(Ratio value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Ratio operator *(Ratio left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Ratio operator *(T left, Ratio right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Ratio operator /(Ratio left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Ratio left, Ratio right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Ratio left, Ratio right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Ratio left, Ratio right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Ratio left, Ratio right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Ratio left, Ratio right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Dimensionless. @@ -117,36 +192,36 @@ public partial record Ratio : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Ratio operator *(Ratio left, Ratio right) => Multiply>(left, right); + public static Ratio operator *(Ratio left, Ratio right) => Ratio.Create(left.Quantity * right.Quantity); /// /// Multiplies Ratio by SignedRatio to produce SignedRatio. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SignedRatio operator *(Ratio left, SignedRatio right) => Multiply>(left, right); + public static SignedRatio operator *(Ratio left, SignedRatio right) => SignedRatio.Create(left.Quantity * right.Quantity); /// /// Divides Ratio by Duration to produce Frequency. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Frequency operator /(Ratio left, Duration right) => Divide>(left, right); + public static Frequency operator /(Ratio left, Duration right) => Frequency.Create(left.Quantity / right.Quantity); /// /// Divides Ratio by Frequency to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Ratio left, Frequency right) => Divide>(left, right); + public static Duration operator /(Ratio left, Frequency right) => Duration.Create(left.Quantity / right.Quantity); /// /// Divides Ratio by Temperature to produce ThermalExpansionCoefficient. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ThermalExpansionCoefficient operator /(Ratio left, Temperature right) => Divide>(left, right); + public static ThermalExpansionCoefficient operator /(Ratio left, Temperature right) => ThermalExpansionCoefficient.Create(left.Quantity / right.Quantity); /// /// Divides Ratio by ThermalExpansionCoefficient to produce Temperature. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Temperature operator /(Ratio left, ThermalExpansionCoefficient right) => Divide>(left, right); + public static Temperature operator /(Ratio left, ThermalExpansionCoefficient right) => Temperature.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReactionRate.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReactionRate.g.cs index 5687e7e2..fb42734b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReactionRate.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReactionRate.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ReactionRate dimension. /// /// The numeric storage type. -public partial record ReactionRate : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ReactionRate : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ReactionRate Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ReactionRate; + public DimensionInfo Dimension => PhysicalDimensions.ReactionRate; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ReactionRate Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReactionRate operator +(ReactionRate left, ReactionRate right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReactionRate operator -(ReactionRate value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReactionRate operator *(ReactionRate left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReactionRate operator *(T left, ReactionRate right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReactionRate operator /(ReactionRate left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ReactionRate left, ReactionRate right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ReactionRate left, ReactionRate right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ReactionRate left, ReactionRate right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ReactionRate left, ReactionRate right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ReactionRate left, ReactionRate right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MolePerCubicMeterSecond. @@ -45,6 +120,6 @@ public partial record ReactionRate : PhysicalQuantity, T>, IV /// Multiplies ReactionRate by Duration to produce Concentration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Concentration operator *(ReactionRate left, Duration right) => Multiply>(left, right); + public static Concentration operator *(ReactionRate left, Duration right) => Concentration.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReflectionCoefficient.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReflectionCoefficient.g.cs index 346d04b6..f304be97 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReflectionCoefficient.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReflectionCoefficient.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ReflectionCoefficient : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct ReflectionCoefficient : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ReflectionCoefficient Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ReflectionCoefficient Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator +(ReflectionCoefficient left, ReflectionCoefficient right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator -(ReflectionCoefficient left, ReflectionCoefficient right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator -(ReflectionCoefficient value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator *(ReflectionCoefficient left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator *(T left, ReflectionCoefficient right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReflectionCoefficient operator /(ReflectionCoefficient left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ReflectionCoefficient left, ReflectionCoefficient right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ReflectionCoefficient left, ReflectionCoefficient right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ReflectionCoefficient left, ReflectionCoefficient right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ReflectionCoefficient left, ReflectionCoefficient right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ReflectionCoefficient left, ReflectionCoefficient right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ReflectionCoefficient from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RefractiveIndex.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RefractiveIndex.g.cs index 976c0980..d6e42898 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RefractiveIndex.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/RefractiveIndex.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record RefractiveIndex : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct RefractiveIndex : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static RefractiveIndex Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static RefractiveIndex Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RefractiveIndex operator +(RefractiveIndex left, RefractiveIndex right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RefractiveIndex operator -(RefractiveIndex value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RefractiveIndex operator *(RefractiveIndex left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RefractiveIndex operator *(T left, RefractiveIndex right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static RefractiveIndex operator /(RefractiveIndex left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(RefractiveIndex left, RefractiveIndex right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(RefractiveIndex left, RefractiveIndex right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(RefractiveIndex left, RefractiveIndex right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(RefractiveIndex left, RefractiveIndex right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(RefractiveIndex left, RefractiveIndex right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new RefractiveIndex from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Resistance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Resistance.g.cs index 5dcbe0f4..d5103a79 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Resistance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Resistance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricResistance dimension. /// /// The numeric storage type. -public partial record Resistance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Resistance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Resistance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricResistance; + public DimensionInfo Dimension => PhysicalDimensions.ElectricResistance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Resistance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Resistance operator +(Resistance left, Resistance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Resistance operator -(Resistance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Resistance operator *(Resistance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Resistance operator *(T left, Resistance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Resistance operator /(Resistance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Resistance left, Resistance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Resistance left, Resistance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Resistance left, Resistance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Resistance left, Resistance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Resistance left, Resistance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Ohm. @@ -61,12 +136,12 @@ public partial record Resistance : PhysicalQuantity, T>, IVecto /// Multiplies Resistance by CurrentMagnitude to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(Resistance left, CurrentMagnitude right) => Multiply>(left, right); + public static VoltageMagnitude operator *(Resistance left, CurrentMagnitude right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Resistance by Current1D to produce Voltage. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Voltage operator *(Resistance left, Current1D right) => Multiply>(left, right); + public static Voltage operator *(Resistance left, Current1D right) => Voltage.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReverberationTime.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReverberationTime.g.cs index 9d49783b..7d5e9bf0 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReverberationTime.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReverberationTime.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ReverberationTime : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ReverberationTime : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ReverberationTime Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ReverberationTime Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReverberationTime operator +(ReverberationTime left, ReverberationTime right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReverberationTime operator -(ReverberationTime value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReverberationTime operator *(ReverberationTime left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReverberationTime operator *(T left, ReverberationTime right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReverberationTime operator /(ReverberationTime left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ReverberationTime left, ReverberationTime right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ReverberationTime left, ReverberationTime right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ReverberationTime left, ReverberationTime right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ReverberationTime left, ReverberationTime right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ReverberationTime left, ReverberationTime right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ReverberationTime from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReynoldsNumber.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReynoldsNumber.g.cs index e8440c4a..a4afe75b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReynoldsNumber.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ReynoldsNumber.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ReynoldsNumber : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ReynoldsNumber : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ReynoldsNumber Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ReynoldsNumber Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReynoldsNumber operator +(ReynoldsNumber left, ReynoldsNumber right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReynoldsNumber operator -(ReynoldsNumber value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReynoldsNumber operator *(ReynoldsNumber left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReynoldsNumber operator *(T left, ReynoldsNumber right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ReynoldsNumber operator /(ReynoldsNumber left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ReynoldsNumber left, ReynoldsNumber right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ReynoldsNumber left, ReynoldsNumber right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ReynoldsNumber left, ReynoldsNumber right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ReynoldsNumber left, ReynoldsNumber right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ReynoldsNumber left, ReynoldsNumber right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ReynoldsNumber from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Rotation.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Rotation.g.cs index a0c851c1..c4ab4b2a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Rotation.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Rotation.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Rotation : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Rotation : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Rotation Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Rotation Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator +(Rotation left, Rotation right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator -(Rotation left, Rotation right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator -(Rotation value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator *(Rotation left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator *(T left, Rotation right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Rotation operator /(Rotation left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Rotation left, Rotation right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Rotation left, Rotation right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Rotation left, Rotation right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Rotation left, Rotation right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Rotation left, Rotation right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Rotation from a value in Radian. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SamplingRate.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SamplingRate.g.cs index fe146725..f15dd159 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SamplingRate.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SamplingRate.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SamplingRate : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SamplingRate : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SamplingRate Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Frequency; + public DimensionInfo Dimension => PhysicalDimensions.Frequency; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SamplingRate Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SamplingRate operator +(SamplingRate left, SamplingRate right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SamplingRate operator -(SamplingRate value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SamplingRate operator *(SamplingRate left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SamplingRate operator *(T left, SamplingRate right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SamplingRate operator /(SamplingRate left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SamplingRate left, SamplingRate right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SamplingRate left, SamplingRate right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SamplingRate left, SamplingRate right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SamplingRate left, SamplingRate right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SamplingRate left, SamplingRate right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SamplingRate from a value in Hertz. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sensitivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sensitivity.g.cs index aa5cfc17..2039d2a7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sensitivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sensitivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Sensitivity dimension. /// /// The numeric storage type. -public partial record Sensitivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Sensitivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Sensitivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Sensitivity; + public DimensionInfo Dimension => PhysicalDimensions.Sensitivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Sensitivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sensitivity operator +(Sensitivity left, Sensitivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sensitivity operator -(Sensitivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sensitivity operator *(Sensitivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sensitivity operator *(T left, Sensitivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sensitivity operator /(Sensitivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Sensitivity left, Sensitivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Sensitivity left, Sensitivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Sensitivity left, Sensitivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Sensitivity left, Sensitivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Sensitivity left, Sensitivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in VoltPerPascal. @@ -45,6 +120,6 @@ public partial record Sensitivity : PhysicalQuantity, T>, IVec /// Multiplies Sensitivity by Pressure to produce VoltageMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VoltageMagnitude operator *(Sensitivity left, Pressure right) => Multiply>(left, right); + public static VoltageMagnitude operator *(Sensitivity left, Pressure right) => VoltageMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sharpness.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sharpness.g.cs index 49377b8a..beafdd9f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sharpness.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Sharpness.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Sharpness dimension. /// /// The numeric storage type. -public partial record Sharpness : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Sharpness : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Sharpness Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Sharpness; + public DimensionInfo Dimension => PhysicalDimensions.Sharpness; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Sharpness Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sharpness operator +(Sharpness left, Sharpness right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sharpness operator -(Sharpness value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sharpness operator *(Sharpness left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sharpness operator *(T left, Sharpness right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Sharpness operator /(Sharpness left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Sharpness left, Sharpness right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Sharpness left, Sharpness right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Sharpness left, Sharpness right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Sharpness left, Sharpness right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Sharpness left, Sharpness right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Acum. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ShearModulus.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ShearModulus.g.cs index 779b4201..5bd55f68 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ShearModulus.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ShearModulus.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ShearModulus : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ShearModulus : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ShearModulus Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ShearModulus Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ShearModulus operator +(ShearModulus left, ShearModulus right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ShearModulus operator -(ShearModulus value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ShearModulus operator *(ShearModulus left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ShearModulus operator *(T left, ShearModulus right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ShearModulus operator /(ShearModulus left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ShearModulus left, ShearModulus right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ShearModulus left, ShearModulus right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ShearModulus left, ShearModulus right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ShearModulus left, ShearModulus right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ShearModulus left, ShearModulus right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ShearModulus from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedAngle.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedAngle.g.cs index 0f0c69ba..3f9f4ce0 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedAngle.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedAngle.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the AngularDisplacement dimension. /// /// The numeric storage type. -public partial record SignedAngle : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct SignedAngle : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SignedAngle Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + public DimensionInfo Dimension => PhysicalDimensions.AngularDisplacement; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SignedAngle Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator +(SignedAngle left, SignedAngle right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator -(SignedAngle left, SignedAngle right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator -(SignedAngle value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator *(SignedAngle left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator *(T left, SignedAngle right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedAngle operator /(SignedAngle left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SignedAngle left, SignedAngle right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SignedAngle left, SignedAngle right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SignedAngle left, SignedAngle right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SignedAngle left, SignedAngle right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SignedAngle left, SignedAngle right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Radian. @@ -71,6 +150,6 @@ public partial record SignedAngle : PhysicalQuantity, T>, IVec /// Divides SignedAngle by Duration to produce AngularVelocity1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularVelocity1D operator /(SignedAngle left, Duration right) => Divide>(left, right); + public static AngularVelocity1D operator /(SignedAngle left, Duration right) => AngularVelocity1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedRatio.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedRatio.g.cs index 7f7467dd..76b5abfe 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedRatio.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SignedRatio.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Dimensionless dimension. /// /// The numeric storage type. -public partial record SignedRatio : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct SignedRatio : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SignedRatio Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SignedRatio Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator +(SignedRatio left, SignedRatio right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator -(SignedRatio left, SignedRatio right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator -(SignedRatio value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator *(SignedRatio left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator *(T left, SignedRatio right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SignedRatio operator /(SignedRatio left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SignedRatio left, SignedRatio right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SignedRatio left, SignedRatio right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SignedRatio left, SignedRatio right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SignedRatio left, SignedRatio right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SignedRatio left, SignedRatio right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Dimensionless. @@ -106,12 +185,12 @@ public partial record SignedRatio : PhysicalQuantity, T>, IVec /// Multiplies SignedRatio by Ratio to produce SignedRatio. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SignedRatio operator *(SignedRatio left, Ratio right) => Multiply>(left, right); + public static SignedRatio operator *(SignedRatio left, Ratio right) => SignedRatio.Create(left.Quantity * right.Quantity); /// /// Divides SignedRatio by Ratio to produce SignedRatio. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static SignedRatio operator /(SignedRatio left, Ratio right) => Divide>(left, right); + public static SignedRatio operator /(SignedRatio left, Ratio right) => SignedRatio.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap1D.g.cs index 41d86fc9..a0b05e00 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Snap dimension. /// /// The numeric storage type. -public partial record Snap1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Snap1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Snap1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Snap; + public DimensionInfo Dimension => PhysicalDimensions.Snap; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Snap1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator +(Snap1D left, Snap1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator -(Snap1D left, Snap1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator -(Snap1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator *(Snap1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator *(T left, Snap1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Snap1D operator /(Snap1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Snap1D left, Snap1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Snap1D left, Snap1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Snap1D left, Snap1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Snap1D left, Snap1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Snap1D left, Snap1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondQuartic. @@ -43,6 +122,6 @@ public partial record Snap1D : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Jerk1D operator *(Snap1D left, Duration right) => Multiply>(left, right); + public static Jerk1D operator *(Snap1D left, Duration right) => Jerk1D.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap2D.g.cs index a7251ac1..71d4aa68 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Snap. /// /// The numeric component type. -public partial record Snap2D : IVector2, T> +public readonly partial record struct Snap2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap3D.g.cs index 5c1c52f7..57e95148 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Snap. /// /// The numeric component type. -public partial record Snap3D : IVector3, T> +public readonly partial record struct Snap3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap4D.g.cs index d99cf1db..459e8a37 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Snap4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Snap. /// /// The numeric component type. -public partial record Snap4D : IVector4, T> +public readonly partial record struct Snap4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SnapMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SnapMagnitude.g.cs index 20ed3cb7..fb515ec7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SnapMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SnapMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Snap dimension. /// /// The numeric storage type. -public partial record SnapMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SnapMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SnapMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Snap; + public DimensionInfo Dimension => PhysicalDimensions.Snap; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SnapMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SnapMagnitude operator +(SnapMagnitude left, SnapMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SnapMagnitude operator -(SnapMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SnapMagnitude operator *(SnapMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SnapMagnitude operator *(T left, SnapMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SnapMagnitude operator /(SnapMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SnapMagnitude left, SnapMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SnapMagnitude left, SnapMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SnapMagnitude left, SnapMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SnapMagnitude left, SnapMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SnapMagnitude left, SnapMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecondQuartic. @@ -45,6 +120,6 @@ public partial record SnapMagnitude : PhysicalQuantity, T>, /// Multiplies SnapMagnitude by Duration to produce JerkMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static JerkMagnitude operator *(SnapMagnitude left, Duration right) => Multiply>(left, right); + public static JerkMagnitude operator *(SnapMagnitude left, Duration right) => JerkMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundAbsorption.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundAbsorption.g.cs index ada4b32c..87c2ee96 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundAbsorption.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundAbsorption.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundAbsorption : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundAbsorption : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundAbsorption Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundAbsorption Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundAbsorption operator +(SoundAbsorption left, SoundAbsorption right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundAbsorption operator -(SoundAbsorption value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundAbsorption operator *(SoundAbsorption left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundAbsorption operator *(T left, SoundAbsorption right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundAbsorption operator /(SoundAbsorption left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundAbsorption left, SoundAbsorption right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundAbsorption left, SoundAbsorption right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundAbsorption left, SoundAbsorption right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundAbsorption left, SoundAbsorption right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundAbsorption left, SoundAbsorption right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundAbsorption from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundIntensity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundIntensity.g.cs index fbbba5d0..bee82a88 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundIntensity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundIntensity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundIntensity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundIntensity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundIntensity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Irradiance; + public DimensionInfo Dimension => PhysicalDimensions.Irradiance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundIntensity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundIntensity operator +(SoundIntensity left, SoundIntensity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundIntensity operator -(SoundIntensity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundIntensity operator *(SoundIntensity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundIntensity operator *(T left, SoundIntensity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundIntensity operator /(SoundIntensity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundIntensity left, SoundIntensity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundIntensity left, SoundIntensity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundIntensity left, SoundIntensity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundIntensity left, SoundIntensity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundIntensity left, SoundIntensity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundIntensity from a value in WattPerSquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPower.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPower.g.cs index f73df78b..5ca93c84 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPower.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPower.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundPower : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundPower : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundPower Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Power; + public DimensionInfo Dimension => PhysicalDimensions.Power; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundPower Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPower operator +(SoundPower left, SoundPower right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPower operator -(SoundPower value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPower operator *(SoundPower left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPower operator *(T left, SoundPower right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPower operator /(SoundPower left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundPower left, SoundPower right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundPower left, SoundPower right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundPower left, SoundPower right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundPower left, SoundPower right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundPower left, SoundPower right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundPower from a value in Watt. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPressure.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPressure.g.cs index 6221a366..f1d8a0e7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPressure.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundPressure.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundPressure : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundPressure : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundPressure Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundPressure Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPressure operator +(SoundPressure left, SoundPressure right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPressure operator -(SoundPressure value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPressure operator *(SoundPressure left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPressure operator *(T left, SoundPressure right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundPressure operator /(SoundPressure left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundPressure left, SoundPressure right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundPressure left, SoundPressure right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundPressure left, SoundPressure right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundPressure left, SoundPressure right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundPressure left, SoundPressure right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundPressure from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundSpeed.g.cs index f5a5da7d..1dfbd117 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundSpeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundSpeed operator +(SoundSpeed left, SoundSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundSpeed operator -(SoundSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundSpeed operator *(SoundSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundSpeed operator *(T left, SoundSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundSpeed operator /(SoundSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundSpeed left, SoundSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundSpeed left, SoundSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundSpeed left, SoundSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundSpeed left, SoundSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundSpeed left, SoundSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundSpeed from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundTransmissionClass.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundTransmissionClass.g.cs index 968a469b..70e33538 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundTransmissionClass.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SoundTransmissionClass.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SoundTransmissionClass : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SoundTransmissionClass : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SoundTransmissionClass Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SoundTransmissionClass Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundTransmissionClass operator +(SoundTransmissionClass left, SoundTransmissionClass right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundTransmissionClass operator -(SoundTransmissionClass value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundTransmissionClass operator *(SoundTransmissionClass left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundTransmissionClass operator *(T left, SoundTransmissionClass right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SoundTransmissionClass operator /(SoundTransmissionClass left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SoundTransmissionClass left, SoundTransmissionClass right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SoundTransmissionClass left, SoundTransmissionClass right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SoundTransmissionClass left, SoundTransmissionClass right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SoundTransmissionClass left, SoundTransmissionClass right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SoundTransmissionClass left, SoundTransmissionClass right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SoundTransmissionClass from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificEntropy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificEntropy.g.cs index 0da7523c..9e661fa7 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificEntropy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificEntropy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SpecificEntropy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SpecificEntropy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SpecificEntropy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.SpecificHeat; + public DimensionInfo Dimension => PhysicalDimensions.SpecificHeat; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SpecificEntropy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificEntropy operator +(SpecificEntropy left, SpecificEntropy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificEntropy operator -(SpecificEntropy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificEntropy operator *(SpecificEntropy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificEntropy operator *(T left, SpecificEntropy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificEntropy operator /(SpecificEntropy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SpecificEntropy left, SpecificEntropy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SpecificEntropy left, SpecificEntropy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SpecificEntropy left, SpecificEntropy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SpecificEntropy left, SpecificEntropy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SpecificEntropy left, SpecificEntropy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SpecificEntropy from a value in JoulePerKilogramKelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificGravity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificGravity.g.cs index a15c73fd..1e6d437f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificGravity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificGravity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SpecificGravity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SpecificGravity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SpecificGravity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + public DimensionInfo Dimension => PhysicalDimensions.Dimensionless; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SpecificGravity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificGravity operator +(SpecificGravity left, SpecificGravity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificGravity operator -(SpecificGravity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificGravity operator *(SpecificGravity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificGravity operator *(T left, SpecificGravity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificGravity operator /(SpecificGravity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SpecificGravity left, SpecificGravity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SpecificGravity left, SpecificGravity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SpecificGravity left, SpecificGravity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SpecificGravity left, SpecificGravity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SpecificGravity left, SpecificGravity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SpecificGravity from a value in Dimensionless. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificHeat.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificHeat.g.cs index 7622b0b9..930bcb6a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificHeat.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SpecificHeat.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the SpecificHeat dimension. /// /// The numeric storage type. -public partial record SpecificHeat : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SpecificHeat : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SpecificHeat Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.SpecificHeat; + public DimensionInfo Dimension => PhysicalDimensions.SpecificHeat; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SpecificHeat Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificHeat operator +(SpecificHeat left, SpecificHeat right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificHeat operator -(SpecificHeat value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificHeat operator *(SpecificHeat left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificHeat operator *(T left, SpecificHeat right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SpecificHeat operator /(SpecificHeat left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SpecificHeat left, SpecificHeat right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SpecificHeat left, SpecificHeat right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SpecificHeat left, SpecificHeat right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SpecificHeat left, SpecificHeat right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SpecificHeat left, SpecificHeat right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in JoulePerKilogramKelvin. @@ -45,6 +120,6 @@ public partial record SpecificHeat : PhysicalQuantity, T>, IV /// Multiplies SpecificHeat by Mass to produce Entropy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Entropy operator *(SpecificHeat left, Mass right) => Multiply>(left, right); + public static Entropy operator *(SpecificHeat left, Mass right) => Entropy.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Speed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Speed.g.cs index deb83208..94c81b05 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Speed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Speed.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Velocity dimension. /// /// The numeric storage type. -public partial record Speed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Speed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Speed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Speed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Speed operator +(Speed left, Speed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Speed operator -(Speed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Speed operator *(Speed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Speed operator *(T left, Speed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Speed operator /(Speed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Speed left, Speed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Speed left, Speed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Speed left, Speed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Speed left, Speed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Speed left, Speed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecond. @@ -77,42 +152,42 @@ public partial record Speed : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentumMagnitude operator *(Speed left, Mass right) => Multiply>(left, right); + public static MomentumMagnitude operator *(Speed left, Mass right) => MomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies Speed by Duration to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator *(Speed left, Duration right) => Multiply>(left, right); + public static Length operator *(Speed left, Duration right) => Length.Create(left.Quantity * right.Quantity); /// /// Divides Speed by Duration to produce AccelerationMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AccelerationMagnitude operator /(Speed left, Duration right) => Divide>(left, right); + public static AccelerationMagnitude operator /(Speed left, Duration right) => AccelerationMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides Speed by AccelerationMagnitude to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Speed left, AccelerationMagnitude right) => Divide>(left, right); + public static Duration operator /(Speed left, AccelerationMagnitude right) => Duration.Create(left.Quantity / right.Quantity); /// /// Divides Speed by Length to produce Frequency. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Frequency operator /(Speed left, Length right) => Divide>(left, right); + public static Frequency operator /(Speed left, Length right) => Frequency.Create(left.Quantity / right.Quantity); /// /// Divides Speed by Frequency to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(Speed left, Frequency right) => Divide>(left, right); + public static Length operator /(Speed left, Frequency right) => Length.Create(left.Quantity / right.Quantity); /// /// Multiplies Speed by ForceMagnitude to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(Speed left, ForceMagnitude right) => Multiply>(left, right); + public static Power operator *(Speed left, ForceMagnitude right) => Power.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Stress.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Stress.g.cs index 04590150..3f2165de 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Stress.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Stress.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Stress : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Stress : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Stress Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Stress Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Stress operator +(Stress left, Stress right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Stress operator -(Stress value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Stress operator *(Stress left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Stress operator *(T left, Stress right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Stress operator /(Stress left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Stress left, Stress right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Stress left, Stress right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Stress left, Stress right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Stress left, Stress right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Stress left, Stress right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Stress from a value in Pascal. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceArea.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceArea.g.cs index aec49e8d..38b09e1f 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceArea.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceArea.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record SurfaceArea : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SurfaceArea : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SurfaceArea Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Area; + public DimensionInfo Dimension => PhysicalDimensions.Area; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SurfaceArea Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceArea operator +(SurfaceArea left, SurfaceArea right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceArea operator -(SurfaceArea value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceArea operator *(SurfaceArea left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceArea operator *(T left, SurfaceArea right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceArea operator /(SurfaceArea left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SurfaceArea left, SurfaceArea right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SurfaceArea left, SurfaceArea right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SurfaceArea left, SurfaceArea right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SurfaceArea left, SurfaceArea right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SurfaceArea left, SurfaceArea right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new SurfaceArea from a value in SquareMeter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceTension.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceTension.g.cs index 462db0e9..f41a1100 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceTension.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/SurfaceTension.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the SurfaceTension dimension. /// /// The numeric storage type. -public partial record SurfaceTension : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct SurfaceTension : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static SurfaceTension Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.SurfaceTension; + public DimensionInfo Dimension => PhysicalDimensions.SurfaceTension; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static SurfaceTension Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceTension operator +(SurfaceTension left, SurfaceTension right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceTension operator -(SurfaceTension value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceTension operator *(SurfaceTension left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceTension operator *(T left, SurfaceTension right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static SurfaceTension operator /(SurfaceTension left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(SurfaceTension left, SurfaceTension right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(SurfaceTension left, SurfaceTension right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(SurfaceTension left, SurfaceTension right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(SurfaceTension left, SurfaceTension right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(SurfaceTension left, SurfaceTension right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in NewtonPerMeter. @@ -53,6 +128,6 @@ public partial record SurfaceTension : PhysicalQuantity, T> /// Multiplies SurfaceTension by Length to produce ForceMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ForceMagnitude operator *(SurfaceTension left, Length right) => Multiply>(left, right); + public static ForceMagnitude operator *(SurfaceTension left, Length right) => ForceMagnitude.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Temperature.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Temperature.g.cs index f2e545e2..83ed8af2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Temperature.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Temperature.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Temperature dimension. /// /// The numeric storage type. -public partial record Temperature : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Temperature : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Temperature Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Temperature; + public DimensionInfo Dimension => PhysicalDimensions.Temperature; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Temperature Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Temperature operator +(Temperature left, Temperature right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Temperature operator -(Temperature value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Temperature operator *(Temperature left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Temperature operator *(T left, Temperature right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Temperature operator /(Temperature left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Temperature left, Temperature right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Temperature left, Temperature right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Temperature left, Temperature right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Temperature left, Temperature right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Temperature left, Temperature right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Kelvin. @@ -69,12 +144,12 @@ public partial record Temperature : PhysicalQuantity, T>, IVec /// Multiplies Temperature by Entropy to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Temperature left, Entropy right) => Multiply>(left, right); + public static Energy operator *(Temperature left, Entropy right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies Temperature by ThermalExpansionCoefficient to produce Ratio. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Ratio operator *(Temperature left, ThermalExpansionCoefficient right) => Multiply>(left, right); + public static Ratio operator *(Temperature left, ThermalExpansionCoefficient right) => Ratio.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDelta.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDelta.g.cs index 60f49517..08f0d3a6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDelta.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDelta.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Temperature dimension. /// /// The numeric storage type. -public partial record TemperatureDelta : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct TemperatureDelta : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static TemperatureDelta Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Temperature; + public DimensionInfo Dimension => PhysicalDimensions.Temperature; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static TemperatureDelta Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator +(TemperatureDelta left, TemperatureDelta right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator -(TemperatureDelta left, TemperatureDelta right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator -(TemperatureDelta value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator *(TemperatureDelta left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator *(T left, TemperatureDelta right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDelta operator /(TemperatureDelta left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(TemperatureDelta left, TemperatureDelta right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(TemperatureDelta left, TemperatureDelta right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(TemperatureDelta left, TemperatureDelta right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(TemperatureDelta left, TemperatureDelta right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(TemperatureDelta left, TemperatureDelta right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Kelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDrop.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDrop.g.cs index 647e383c..84a13008 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDrop.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureDrop.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record TemperatureDrop : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct TemperatureDrop : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static TemperatureDrop Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Temperature; + public DimensionInfo Dimension => PhysicalDimensions.Temperature; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static TemperatureDrop Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator +(TemperatureDrop left, TemperatureDrop right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator -(TemperatureDrop left, TemperatureDrop right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator -(TemperatureDrop value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator *(TemperatureDrop left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator *(T left, TemperatureDrop right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureDrop operator /(TemperatureDrop left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(TemperatureDrop left, TemperatureDrop right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(TemperatureDrop left, TemperatureDrop right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(TemperatureDrop left, TemperatureDrop right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(TemperatureDrop left, TemperatureDrop right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(TemperatureDrop left, TemperatureDrop right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new TemperatureDrop from a value in Kelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureRise.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureRise.g.cs index faff8c4a..7fafb250 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureRise.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TemperatureRise.g.cs @@ -10,14 +10,93 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record TemperatureRise : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct TemperatureRise : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static TemperatureRise Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Temperature; + public DimensionInfo Dimension => PhysicalDimensions.Temperature; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static TemperatureRise Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator +(TemperatureRise left, TemperatureRise right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator -(TemperatureRise left, TemperatureRise right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator -(TemperatureRise value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator *(TemperatureRise left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator *(T left, TemperatureRise right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TemperatureRise operator /(TemperatureRise left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(TemperatureRise left, TemperatureRise right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(TemperatureRise left, TemperatureRise right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(TemperatureRise left, TemperatureRise right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(TemperatureRise left, TemperatureRise right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(TemperatureRise left, TemperatureRise right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new TemperatureRise from a value in Kelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Tension.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Tension.g.cs index f9182325..3874a419 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Tension.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Tension.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Tension : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Tension : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Tension Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Tension Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Tension operator +(Tension left, Tension right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Tension operator -(Tension value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Tension operator *(Tension left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Tension operator *(T left, Tension right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Tension operator /(Tension left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Tension left, Tension right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Tension left, Tension right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Tension left, Tension right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Tension left, Tension right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Tension left, Tension right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Tension from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalConductivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalConductivity.g.cs index 711f1942..cb462502 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalConductivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalConductivity.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ThermalConductivity dimension. /// /// The numeric storage type. -public partial record ThermalConductivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ThermalConductivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ThermalConductivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ThermalConductivity; + public DimensionInfo Dimension => PhysicalDimensions.ThermalConductivity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ThermalConductivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalConductivity operator +(ThermalConductivity left, ThermalConductivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalConductivity operator -(ThermalConductivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalConductivity operator *(ThermalConductivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalConductivity operator *(T left, ThermalConductivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalConductivity operator /(ThermalConductivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ThermalConductivity left, ThermalConductivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ThermalConductivity left, ThermalConductivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ThermalConductivity left, ThermalConductivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ThermalConductivity left, ThermalConductivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ThermalConductivity left, ThermalConductivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in WattPerMeterKelvin. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalDiffusivity.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalDiffusivity.g.cs index 11219363..1c644413 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalDiffusivity.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalDiffusivity.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ThermalDiffusivity : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ThermalDiffusivity : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ThermalDiffusivity Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.KinematicViscosity; + public DimensionInfo Dimension => PhysicalDimensions.KinematicViscosity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ThermalDiffusivity Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalDiffusivity operator +(ThermalDiffusivity left, ThermalDiffusivity right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalDiffusivity operator -(ThermalDiffusivity value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalDiffusivity operator *(ThermalDiffusivity left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalDiffusivity operator *(T left, ThermalDiffusivity right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalDiffusivity operator /(ThermalDiffusivity left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ThermalDiffusivity left, ThermalDiffusivity right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ThermalDiffusivity left, ThermalDiffusivity right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ThermalDiffusivity left, ThermalDiffusivity right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ThermalDiffusivity left, ThermalDiffusivity right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ThermalDiffusivity left, ThermalDiffusivity right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ThermalDiffusivity from a value in SquareMeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalEnergy.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalEnergy.g.cs index a4a372e1..655dcc76 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalEnergy.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalEnergy.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record ThermalEnergy : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ThermalEnergy : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ThermalEnergy Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ThermalEnergy Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalEnergy operator +(ThermalEnergy left, ThermalEnergy right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalEnergy operator -(ThermalEnergy value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalEnergy operator *(ThermalEnergy left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalEnergy operator *(T left, ThermalEnergy right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalEnergy operator /(ThermalEnergy left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ThermalEnergy left, ThermalEnergy right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ThermalEnergy left, ThermalEnergy right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ThermalEnergy left, ThermalEnergy right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ThermalEnergy left, ThermalEnergy right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ThermalEnergy left, ThermalEnergy right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new ThermalEnergy from a value in Joule. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalExpansionCoefficient.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalExpansionCoefficient.g.cs index 8cd493c5..d71b0a77 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalExpansionCoefficient.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalExpansionCoefficient.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ThermalExpansion dimension. /// /// The numeric storage type. -public partial record ThermalExpansionCoefficient : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ThermalExpansionCoefficient : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ThermalExpansionCoefficient Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ThermalExpansion; + public DimensionInfo Dimension => PhysicalDimensions.ThermalExpansion; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ThermalExpansionCoefficient Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalExpansionCoefficient operator +(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalExpansionCoefficient operator -(ThermalExpansionCoefficient value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalExpansionCoefficient operator *(ThermalExpansionCoefficient left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalExpansionCoefficient operator *(T left, ThermalExpansionCoefficient right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalExpansionCoefficient operator /(ThermalExpansionCoefficient left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in PerKelvin. @@ -45,6 +120,6 @@ public partial record ThermalExpansionCoefficient : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Ratio operator *(ThermalExpansionCoefficient left, Temperature right) => Multiply>(left, right); + public static Ratio operator *(ThermalExpansionCoefficient left, Temperature right) => Ratio.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalResistance.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalResistance.g.cs index be6cd27f..c91223af 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalResistance.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThermalResistance.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ThermalResistance dimension. /// /// The numeric storage type. -public partial record ThermalResistance : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct ThermalResistance : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static ThermalResistance Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ThermalResistance; + public DimensionInfo Dimension => PhysicalDimensions.ThermalResistance; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static ThermalResistance Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalResistance operator +(ThermalResistance left, ThermalResistance right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalResistance operator -(ThermalResistance value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalResistance operator *(ThermalResistance left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalResistance operator *(T left, ThermalResistance right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static ThermalResistance operator /(ThermalResistance left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(ThermalResistance left, ThermalResistance right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(ThermalResistance left, ThermalResistance right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(ThermalResistance left, ThermalResistance right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(ThermalResistance left, ThermalResistance right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(ThermalResistance left, ThermalResistance right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in KelvinPerWatt. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thickness.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thickness.g.cs index 14f35819..461b8d7c 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thickness.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thickness.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Thickness : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Thickness : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Thickness Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Thickness Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thickness operator +(Thickness left, Thickness right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thickness operator -(Thickness value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thickness operator *(Thickness left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thickness operator *(T left, Thickness right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thickness operator /(Thickness left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Thickness left, Thickness right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Thickness left, Thickness right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Thickness left, Thickness right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Thickness left, Thickness right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Thickness left, Thickness right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Thickness from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thrust.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thrust.g.cs index 608a1c51..93d7314b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thrust.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Thrust.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Thrust : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Thrust : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Thrust Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Thrust Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thrust operator +(Thrust left, Thrust right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thrust operator -(Thrust value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thrust operator *(Thrust left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thrust operator *(T left, Thrust right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Thrust operator /(Thrust left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Thrust left, Thrust right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Thrust left, Thrust right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Thrust left, Thrust right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Thrust left, Thrust right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Thrust left, Thrust right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Thrust from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThrustVector.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThrustVector.g.cs index 71c48723..a3294799 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThrustVector.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/ThrustVector.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Propulsive force vector. /// Semantic overload of . /// -public partial record ThrustVector : IVector3, T> +public readonly partial record struct ThrustVector : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TimeConstant.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TimeConstant.g.cs index 0fc81115..52b2d4f4 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TimeConstant.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TimeConstant.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record TimeConstant : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct TimeConstant : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static TimeConstant Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Time; + public DimensionInfo Dimension => PhysicalDimensions.Time; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static TimeConstant Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TimeConstant operator +(TimeConstant left, TimeConstant right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TimeConstant operator -(TimeConstant value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TimeConstant operator *(TimeConstant left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TimeConstant operator *(T left, TimeConstant right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TimeConstant operator /(TimeConstant left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(TimeConstant left, TimeConstant right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(TimeConstant left, TimeConstant right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(TimeConstant left, TimeConstant right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(TimeConstant left, TimeConstant right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(TimeConstant left, TimeConstant right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new TimeConstant from a value in Second. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque1D.g.cs index 9b5257b3..916ebb9a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Torque dimension. /// /// The numeric storage type. -public partial record Torque1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Torque1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Torque1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Torque; + public DimensionInfo Dimension => PhysicalDimensions.Torque; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Torque1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator +(Torque1D left, Torque1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator -(Torque1D left, Torque1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator -(Torque1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator *(Torque1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator *(T left, Torque1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Torque1D operator /(Torque1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Torque1D left, Torque1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Torque1D left, Torque1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Torque1D left, Torque1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Torque1D left, Torque1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Torque1D left, Torque1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in NewtonMeter. @@ -50,6 +129,6 @@ public partial record Torque1D : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentum1D operator *(Torque1D left, Duration right) => Multiply>(left, right); + public static AngularMomentum1D operator *(Torque1D left, Duration right) => AngularMomentum1D.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque3D.g.cs index 02e63906..556b51f6 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Torque3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Torque. /// /// The numeric component type. -public partial record Torque3D : IVector3, T> +public readonly partial record struct Torque3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TorqueMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TorqueMagnitude.g.cs index d2951c80..4c55247b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TorqueMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/TorqueMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Torque dimension. /// /// The numeric storage type. -public partial record TorqueMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct TorqueMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static TorqueMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Torque; + public DimensionInfo Dimension => PhysicalDimensions.Torque; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static TorqueMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TorqueMagnitude operator +(TorqueMagnitude left, TorqueMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TorqueMagnitude operator -(TorqueMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TorqueMagnitude operator *(TorqueMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TorqueMagnitude operator *(T left, TorqueMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static TorqueMagnitude operator /(TorqueMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(TorqueMagnitude left, TorqueMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(TorqueMagnitude left, TorqueMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(TorqueMagnitude left, TorqueMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(TorqueMagnitude left, TorqueMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(TorqueMagnitude left, TorqueMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in NewtonMeter. @@ -53,24 +128,24 @@ public partial record TorqueMagnitude : PhysicalQuantity, /// Multiplies TorqueMagnitude by Angle to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(TorqueMagnitude left, Angle right) => Multiply>(left, right); + public static Energy operator *(TorqueMagnitude left, Angle right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies TorqueMagnitude by Duration to produce AngularMomentumMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularMomentumMagnitude operator *(TorqueMagnitude left, Duration right) => Multiply>(left, right); + public static AngularMomentumMagnitude operator *(TorqueMagnitude left, Duration right) => AngularMomentumMagnitude.Create(left.Quantity * right.Quantity); /// /// Divides TorqueMagnitude by AngularAccelerationMagnitude to produce MomentOfInertia. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MomentOfInertia operator /(TorqueMagnitude left, AngularAccelerationMagnitude right) => Divide>(left, right); + public static MomentOfInertia operator /(TorqueMagnitude left, AngularAccelerationMagnitude right) => MomentOfInertia.Create(left.Quantity / right.Quantity); /// /// Divides TorqueMagnitude by MomentOfInertia to produce AngularAccelerationMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AngularAccelerationMagnitude operator /(TorqueMagnitude left, MomentOfInertia right) => Divide>(left, right); + public static AngularAccelerationMagnitude operator /(TorqueMagnitude left, MomentOfInertia right) => AngularAccelerationMagnitude.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Translation3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Translation3D.g.cs index 1ba41bdf..b97d3011 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Translation3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Translation3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Movement applied to an object in 3D space. /// Semantic overload of . /// -public partial record Translation3D : IVector3, T> +public readonly partial record struct Translation3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity1D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity1D.g.cs index b0cc592d..5431f98b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity1D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity1D.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the Velocity dimension. /// /// The numeric storage type. -public partial record Velocity1D : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Velocity1D : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Velocity1D Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Velocity1D Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator +(Velocity1D left, Velocity1D right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator -(Velocity1D left, Velocity1D right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator -(Velocity1D value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator *(Velocity1D left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator *(T left, Velocity1D right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Velocity1D operator /(Velocity1D left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Velocity1D left, Velocity1D right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Velocity1D left, Velocity1D right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Velocity1D left, Velocity1D right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Velocity1D left, Velocity1D right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Velocity1D left, Velocity1D right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in MeterPerSecond. @@ -71,12 +150,12 @@ public partial record Velocity1D : PhysicalQuantity, T>, IVecto /// Multiplies Velocity1D by Duration to produce Displacement1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Displacement1D operator *(Velocity1D left, Duration right) => Multiply>(left, right); + public static Displacement1D operator *(Velocity1D left, Duration right) => Displacement1D.Create(left.Quantity * right.Quantity); /// /// Divides Velocity1D by Duration to produce Acceleration1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Acceleration1D operator /(Velocity1D left, Duration right) => Divide>(left, right); + public static Acceleration1D operator /(Velocity1D left, Duration right) => Acceleration1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity2D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity2D.g.cs index 17dcfc0f..de91c457 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity2D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity2D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 2D vector representation of Velocity. /// /// The numeric component type. -public partial record Velocity2D : IVector2, T> +public readonly partial record struct Velocity2D : IVector2, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity3D.g.cs index 9668eb10..3ada42e1 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 3D vector representation of Velocity. /// /// The numeric component type. -public partial record Velocity3D : IVector3, T> +public readonly partial record struct Velocity3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity4D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity4D.g.cs index 9aac39be..c197cfc0 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity4D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Velocity4D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// 4D vector representation of Velocity. /// /// The numeric component type. -public partial record Velocity4D : IVector4, T> +public readonly partial record struct Velocity4D : IVector4, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Voltage.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Voltage.g.cs index c4cb449e..605c799b 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Voltage.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Voltage.g.cs @@ -9,14 +9,93 @@ namespace ktsu.Semantics.Quantities; /// Signed one-dimensional (Vector1) quantity for the ElectricPotential dimension. /// /// The numeric storage type. -public partial record Voltage : PhysicalQuantity, T>, IVector1, T> +public readonly partial record struct Voltage : IVector1, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Voltage Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + public DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Voltage Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator +(Voltage left, Voltage right) => Create(left.Quantity + right.Quantity); + + /// Subtracts one from another. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator -(Voltage left, Voltage right) => Create(left.Quantity - right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator -(Voltage value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator *(Voltage left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator *(T left, Voltage right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Voltage operator /(Voltage left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Voltage left, Voltage right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Voltage left, Voltage right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Voltage left, Voltage right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Voltage left, Voltage right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Voltage left, Voltage right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Volt. @@ -50,12 +129,12 @@ public partial record Voltage : PhysicalQuantity, T>, IVector1 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Current1D operator /(Voltage left, Resistance right) => Divide>(left, right); + public static Current1D operator /(Voltage left, Resistance right) => Current1D.Create(left.Quantity / right.Quantity); /// /// Divides Voltage by Length to produce ElectricField1D. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricField1D operator /(Voltage left, Length right) => Divide>(left, right); + public static ElectricField1D operator /(Voltage left, Length right) => ElectricField1D.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageDrop.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageDrop.g.cs index 70ac49d7..83049046 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageDrop.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageDrop.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record VoltageDrop : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct VoltageDrop : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static VoltageDrop Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + public DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static VoltageDrop Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageDrop operator +(VoltageDrop left, VoltageDrop right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageDrop operator -(VoltageDrop value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageDrop operator *(VoltageDrop left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageDrop operator *(T left, VoltageDrop right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageDrop operator /(VoltageDrop left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(VoltageDrop left, VoltageDrop right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(VoltageDrop left, VoltageDrop right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(VoltageDrop left, VoltageDrop right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(VoltageDrop left, VoltageDrop right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(VoltageDrop left, VoltageDrop right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new VoltageDrop from a value in Volt. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageMagnitude.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageMagnitude.g.cs index e46bcf0c..c3529c09 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageMagnitude.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VoltageMagnitude.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the ElectricPotential dimension. /// /// The numeric storage type. -public partial record VoltageMagnitude : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct VoltageMagnitude : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static VoltageMagnitude Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + public DimensionInfo Dimension => PhysicalDimensions.ElectricPotential; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static VoltageMagnitude Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageMagnitude operator +(VoltageMagnitude left, VoltageMagnitude right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageMagnitude operator -(VoltageMagnitude value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageMagnitude operator *(VoltageMagnitude left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageMagnitude operator *(T left, VoltageMagnitude right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VoltageMagnitude operator /(VoltageMagnitude left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(VoltageMagnitude left, VoltageMagnitude right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(VoltageMagnitude left, VoltageMagnitude right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(VoltageMagnitude left, VoltageMagnitude right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(VoltageMagnitude left, VoltageMagnitude right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(VoltageMagnitude left, VoltageMagnitude right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in Volt. @@ -53,60 +128,60 @@ public partial record VoltageMagnitude : PhysicalQuantity /// Divides VoltageMagnitude by Resistance to produce CurrentMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator /(VoltageMagnitude left, Resistance right) => Divide>(left, right); + public static CurrentMagnitude operator /(VoltageMagnitude left, Resistance right) => CurrentMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides VoltageMagnitude by CurrentMagnitude to produce Resistance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Resistance operator /(VoltageMagnitude left, CurrentMagnitude right) => Divide>(left, right); + public static Resistance operator /(VoltageMagnitude left, CurrentMagnitude right) => Resistance.Create(left.Quantity / right.Quantity); /// /// Multiplies VoltageMagnitude by CurrentMagnitude to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(VoltageMagnitude left, CurrentMagnitude right) => Multiply>(left, right); + public static Power operator *(VoltageMagnitude left, CurrentMagnitude right) => Power.Create(left.Quantity * right.Quantity); /// /// Divides VoltageMagnitude by Length to produce ElectricFieldMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ElectricFieldMagnitude operator /(VoltageMagnitude left, Length right) => Divide>(left, right); + public static ElectricFieldMagnitude operator /(VoltageMagnitude left, Length right) => ElectricFieldMagnitude.Create(left.Quantity / right.Quantity); /// /// Divides VoltageMagnitude by ElectricFieldMagnitude to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(VoltageMagnitude left, ElectricFieldMagnitude right) => Divide>(left, right); + public static Length operator /(VoltageMagnitude left, ElectricFieldMagnitude right) => Length.Create(left.Quantity / right.Quantity); /// /// Multiplies VoltageMagnitude by Capacitance to produce ChargeMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static ChargeMagnitude operator *(VoltageMagnitude left, Capacitance right) => Multiply>(left, right); + public static ChargeMagnitude operator *(VoltageMagnitude left, Capacitance right) => ChargeMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies VoltageMagnitude by Conductance to produce CurrentMagnitude. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static CurrentMagnitude operator *(VoltageMagnitude left, Conductance right) => Multiply>(left, right); + public static CurrentMagnitude operator *(VoltageMagnitude left, Conductance right) => CurrentMagnitude.Create(left.Quantity * right.Quantity); /// /// Multiplies VoltageMagnitude by Duration to produce MagneticFlux. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static MagneticFlux operator *(VoltageMagnitude left, Duration right) => Multiply>(left, right); + public static MagneticFlux operator *(VoltageMagnitude left, Duration right) => MagneticFlux.Create(left.Quantity * right.Quantity); /// /// Divides VoltageMagnitude by Pressure to produce Sensitivity. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Sensitivity operator /(VoltageMagnitude left, Pressure right) => Divide>(left, right); + public static Sensitivity operator /(VoltageMagnitude left, Pressure right) => Sensitivity.Create(left.Quantity / right.Quantity); /// /// Divides VoltageMagnitude by Sensitivity to produce Pressure. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Pressure operator /(VoltageMagnitude left, Sensitivity right) => Divide>(left, right); + public static Pressure operator /(VoltageMagnitude left, Sensitivity right) => Pressure.Create(left.Quantity / right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Volume.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Volume.g.cs index cb204a21..3c286644 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Volume.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Volume.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the Volume dimension. /// /// The numeric storage type. -public partial record Volume : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Volume : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Volume Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Volume; + public DimensionInfo Dimension => PhysicalDimensions.Volume; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Volume Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Volume operator +(Volume left, Volume right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Volume operator -(Volume value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Volume operator *(Volume left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Volume operator *(T left, Volume right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Volume operator /(Volume left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Volume left, Volume right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Volume left, Volume right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Volume left, Volume right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Volume left, Volume right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Volume left, Volume right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in CubicMeter. @@ -125,48 +200,48 @@ public partial record Volume : PhysicalQuantity, T>, IVector0 [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Area operator /(Volume left, Length right) => Divide>(left, right); + public static Area operator /(Volume left, Length right) => Area.Create(left.Quantity / right.Quantity); /// /// Divides Volume by Area to produce Length. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Length operator /(Volume left, Area right) => Divide>(left, right); + public static Length operator /(Volume left, Area right) => Length.Create(left.Quantity / right.Quantity); /// /// Multiplies Volume by Pressure to produce Energy. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Energy operator *(Volume left, Pressure right) => Multiply>(left, right); + public static Energy operator *(Volume left, Pressure right) => Energy.Create(left.Quantity * right.Quantity); /// /// Multiplies Volume by Density to produce Mass. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Mass operator *(Volume left, Density right) => Multiply>(left, right); + public static Mass operator *(Volume left, Density right) => Mass.Create(left.Quantity * right.Quantity); /// /// Multiplies Volume by Concentration to produce AmountOfSubstance. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static AmountOfSubstance operator *(Volume left, Concentration right) => Multiply>(left, right); + public static AmountOfSubstance operator *(Volume left, Concentration right) => AmountOfSubstance.Create(left.Quantity * right.Quantity); /// /// Divides Volume by Duration to produce VolumetricFlowRate. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static VolumetricFlowRate operator /(Volume left, Duration right) => Divide>(left, right); + public static VolumetricFlowRate operator /(Volume left, Duration right) => VolumetricFlowRate.Create(left.Quantity / right.Quantity); /// /// Divides Volume by VolumetricFlowRate to produce Duration. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Duration operator /(Volume left, VolumetricFlowRate right) => Divide>(left, right); + public static Duration operator /(Volume left, VolumetricFlowRate right) => Duration.Create(left.Quantity / right.Quantity); /// /// Multiplies Volume by ElectricPowerDensity to produce Power. /// [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Power operator *(Volume left, ElectricPowerDensity right) => Multiply>(left, right); + public static Power operator *(Volume left, ElectricPowerDensity right) => Power.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VolumetricFlowRate.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VolumetricFlowRate.g.cs index bce464a1..776b7d2a 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VolumetricFlowRate.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/VolumetricFlowRate.g.cs @@ -9,14 +9,89 @@ namespace ktsu.Semantics.Quantities; /// Magnitude (Vector0) quantity for the VolumetricFlowRate dimension. /// /// The numeric storage type. -public partial record VolumetricFlowRate : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct VolumetricFlowRate : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static VolumetricFlowRate Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.VolumetricFlowRate; + public DimensionInfo Dimension => PhysicalDimensions.VolumetricFlowRate; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static VolumetricFlowRate Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VolumetricFlowRate operator +(VolumetricFlowRate left, VolumetricFlowRate right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VolumetricFlowRate operator -(VolumetricFlowRate value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VolumetricFlowRate operator *(VolumetricFlowRate left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VolumetricFlowRate operator *(T left, VolumetricFlowRate right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static VolumetricFlowRate operator /(VolumetricFlowRate left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(VolumetricFlowRate left, VolumetricFlowRate right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(VolumetricFlowRate left, VolumetricFlowRate right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(VolumetricFlowRate left, VolumetricFlowRate right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(VolumetricFlowRate left, VolumetricFlowRate right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(VolumetricFlowRate left, VolumetricFlowRate right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new from a value in CubicMeterPerSecond. @@ -53,6 +128,6 @@ public partial record VolumetricFlowRate : PhysicalQuantity [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] - public static Volume operator *(VolumetricFlowRate left, Duration right) => Multiply>(left, right); + public static Volume operator *(VolumetricFlowRate left, Duration right) => Volume.Create(left.Quantity * right.Quantity); } diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Wavelength.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Wavelength.g.cs index 750c7342..a2bd8d51 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Wavelength.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Wavelength.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Wavelength : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Wavelength : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Wavelength Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Wavelength Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Wavelength operator +(Wavelength left, Wavelength right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Wavelength operator -(Wavelength value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Wavelength operator *(Wavelength left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Wavelength operator *(T left, Wavelength right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Wavelength operator /(Wavelength left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Wavelength left, Wavelength right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Wavelength left, Wavelength right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Wavelength left, Wavelength right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Wavelength left, Wavelength right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Wavelength left, Wavelength right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Wavelength from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Weight.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Weight.g.cs index b1b7dde0..13b453be 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Weight.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Weight.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Weight : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Weight : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Weight Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Force; + public DimensionInfo Dimension => PhysicalDimensions.Force; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Weight Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Weight operator +(Weight left, Weight right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Weight operator -(Weight value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Weight operator *(Weight left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Weight operator *(T left, Weight right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Weight operator /(Weight left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Weight left, Weight right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Weight left, Weight right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Weight left, Weight right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Weight left, Weight right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Weight left, Weight right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Weight from a value in Newton. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WeightVector.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WeightVector.g.cs index fde25283..2fe88f39 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WeightVector.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WeightVector.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Gravitational force vector. /// Semantic overload of . /// -public partial record WeightVector : IVector3, T> +public readonly partial record struct WeightVector : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Width.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Width.g.cs index 107550fb..bb280d77 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Width.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Width.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Width : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Width : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Width Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Length; + public DimensionInfo Dimension => PhysicalDimensions.Length; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Width Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Width operator +(Width left, Width right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Width operator -(Width value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Width operator *(Width left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Width operator *(T left, Width right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Width operator /(Width left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Width left, Width right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Width left, Width right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Width left, Width right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Width left, Width right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Width left, Width right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Width from a value in Meter. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindSpeed.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindSpeed.g.cs index 1cfefd0c..d4f9ed3d 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindSpeed.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindSpeed.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record WindSpeed : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct WindSpeed : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static WindSpeed Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Velocity; + public DimensionInfo Dimension => PhysicalDimensions.Velocity; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static WindSpeed Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static WindSpeed operator +(WindSpeed left, WindSpeed right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static WindSpeed operator -(WindSpeed value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static WindSpeed operator *(WindSpeed left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static WindSpeed operator *(T left, WindSpeed right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static WindSpeed operator /(WindSpeed left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(WindSpeed left, WindSpeed right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(WindSpeed left, WindSpeed right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(WindSpeed left, WindSpeed right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(WindSpeed left, WindSpeed right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(WindSpeed left, WindSpeed right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new WindSpeed from a value in MeterPerSecond. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindVelocity3D.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindVelocity3D.g.cs index 5edbc06a..58f9c6a2 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindVelocity3D.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/WindVelocity3D.g.cs @@ -13,7 +13,7 @@ namespace ktsu.Semantics.Quantities; /// Wind velocity vector in 3D space. /// Semantic overload of . /// -public partial record WindVelocity3D : IVector3, T> +public readonly partial record struct WindVelocity3D : IVector3, T> where T : struct, INumber { /// Gets the X component. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Work.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Work.g.cs index bd4223fc..f248ed36 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Work.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/Work.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record Work : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct Work : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static Work Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Energy; + public DimensionInfo Dimension => PhysicalDimensions.Energy; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static Work Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Work operator +(Work left, Work right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Work operator -(Work value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Work operator *(Work left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Work operator *(T left, Work right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static Work operator /(Work left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(Work left, Work right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(Work left, Work right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(Work left, Work right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(Work left, Work right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(Work left, Work right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new Work from a value in Joule. diff --git a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/YoungsModulus.g.cs b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/YoungsModulus.g.cs index 7e6d486a..9ac1ba7e 100644 --- a/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/YoungsModulus.g.cs +++ b/Semantics.Quantities/Generated/Semantics.SourceGenerators/Semantics.SourceGenerators.QuantitiesGenerator/YoungsModulus.g.cs @@ -10,14 +10,89 @@ namespace ktsu.Semantics.Quantities; /// Semantic overload of . /// /// The numeric storage type. -public partial record YoungsModulus : PhysicalQuantity, T>, IVector0, T> +public readonly partial record struct YoungsModulus : IVector0, T>, IPhysicalQuantity, T> where T : struct, INumber { + /// Gets the value stored in this quantity (in the dimension's SI base unit). + public T Value => Quantity; + + /// Gets whether this quantity is finite and not NaN. + public bool IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity); + /// Gets a quantity with value zero. public static YoungsModulus Zero => Create(T.Zero); /// Gets the physical dimension this quantity belongs to. - public override DimensionInfo Dimension => PhysicalDimensions.Pressure; + public DimensionInfo Dimension => PhysicalDimensions.Pressure; + + /// Gets the stored value, in the dimension's SI base unit. + public T Quantity { get; init; } + + /// + /// Creates a quantity holding , in the SI base unit. + /// + /// The value in the SI base unit. + /// A new quantity holding . + public static YoungsModulus Create(T value) => new() { Quantity = value }; + + /// + /// Compares this quantity to another of the same physical dimension. + /// + /// The quantity to compare against. + /// A negative number, zero or a positive number as this sorts before, with, or after . + /// When the two do not share a dimension. + public int CompareTo(IPhysicalQuantity other) => PhysicalQuantityCore.Compare, T>(this, other); + + /// + /// Reports whether this quantity shares a dimension and a value with . + /// + /// The quantity to compare against. + /// when both dimension and value match. + public bool Equals(IPhysicalQuantity other) => PhysicalQuantityCore.AreEqual, T>(this, other); + + /// Adds two values. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static YoungsModulus operator +(YoungsModulus left, YoungsModulus right) => Create(left.Quantity + right.Quantity); + + /// Negates a . + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static YoungsModulus operator -(YoungsModulus value) => Create(-value.Quantity); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static YoungsModulus operator *(YoungsModulus left, T right) => Create(left.Quantity * right); + + /// Scales a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static YoungsModulus operator *(T left, YoungsModulus right) => Create(left * right.Quantity); + + /// Divides a by a bare number. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static YoungsModulus operator /(YoungsModulus left, T right) => T.IsZero(right) ? throw new System.DivideByZeroException("Cannot divide by zero.") : Create(left.Quantity / right); + + /// Divides one by another, giving the bare ratio. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static T operator /(YoungsModulus left, YoungsModulus right) => T.IsZero(right.Quantity) ? throw new System.DivideByZeroException("Cannot divide by zero.") : left.Quantity / right.Quantity; + + /// Reports whether the left value sorts before the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <(YoungsModulus left, YoungsModulus right) => left.Quantity < right.Quantity; + + /// Reports whether the left value sorts before or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator <=(YoungsModulus left, YoungsModulus right) => left.Quantity <= right.Quantity; + + /// Reports whether the left value sorts after the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >(YoungsModulus left, YoungsModulus right) => left.Quantity > right.Quantity; + + /// Reports whether the left value sorts after or with the right. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] + public static bool operator >=(YoungsModulus left, YoungsModulus right) => left.Quantity >= right.Quantity; + + /// Returns the stored value as text. + /// The value in the SI base unit, rendered by . + public override string ToString() => Quantity.ToString() ?? string.Empty; /// /// Creates a new YoungsModulus from a value in Pascal. diff --git a/Semantics.Quantities/IPhysicalQuantity.cs b/Semantics.Quantities/IPhysicalQuantity.cs index f3fd31af..c38eaf7a 100644 --- a/Semantics.Quantities/IPhysicalQuantity.cs +++ b/Semantics.Quantities/IPhysicalQuantity.cs @@ -31,3 +31,27 @@ public interface IPhysicalQuantity /// Gets the physical dimension this quantity belongs to. public DimensionInfo Dimension { get; } } + +/// +/// A physical quantity that knows its own type, so generic code can construct one. +/// +/// +/// This is the seam that replaced the TSelf-constrained record base. Generated quantities +/// are structs and cannot inherit a shared Create, so each declares its own and this +/// interface is what lets a caller reach it without knowing which quantity it holds. +/// +/// The implementing quantity type. +/// The storage type for the quantity value. +public interface IPhysicalQuantity + : IPhysicalQuantity + where TSelf : struct, IPhysicalQuantity + where T : struct, INumber +{ + /// + /// Creates a quantity holding , interpreted in the dimension's SI + /// base unit. + /// + /// The value in the SI base unit. + /// A quantity of this type holding . + public static abstract TSelf Create(T value); +} diff --git a/Semantics.Quantities/PhysicalQuantity.cs b/Semantics.Quantities/PhysicalQuantity.cs deleted file mode 100644 index d5f70561..00000000 --- a/Semantics.Quantities/PhysicalQuantity.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2023-2026 ktsu-dev contributors - -namespace ktsu.Semantics.Quantities; - -using System; -using System.Numerics; - -/// -/// Base record for all physical quantity types. Inherits arithmetic operators from -/// and adds , -/// , and same-dimension comparison. -/// -/// The derived physical quantity type. -/// The storage type for the quantity value. -public abstract record PhysicalQuantity - : SemanticQuantity - , IPhysicalQuantity - where TSelf : PhysicalQuantity, new() - where T : struct, INumber -{ - /// Gets the value stored in this quantity (in the dimension's SI base unit). - public T Value => Quantity; - - /// Gets whether this quantity satisfies structural physical constraints. - public virtual bool IsPhysicallyValid => !T.IsNaN(Value) && T.IsFinite(Value); - - /// Gets the physical dimension this quantity belongs to. Implemented by generated types. - public abstract DimensionInfo Dimension { get; } - - /// - /// Initializes a new instance of the class. - /// - protected PhysicalQuantity() : base() { } - - /// - /// Compares this quantity to another of the same physical dimension. Throws - /// if dimensions differ — quantities of different - /// dimensions are not ordered. - /// - public int CompareTo(IPhysicalQuantity? other) - { - if (other is null) - { - return 1; - } - - if (!Equals(Dimension, other.Dimension)) - { - throw new ArgumentException( - $"Cannot compare quantity of dimension '{Dimension.Name}' to quantity of dimension '{other.Dimension.Name}'.", - nameof(other)); - } - - return Value.CompareTo(other.Value); - } - - /// - /// Equality across the surface — two quantities - /// are equal iff they share a dimension and a value. Cross-dimension comparisons - /// return false (they don't throw — equality is total). - /// - public virtual bool Equals(IPhysicalQuantity? other) - { - if (other is null) - { - return false; - } - - return Equals(Dimension, other.Dimension) && Value.Equals(other.Value); - } - - /// - /// Determines whether one quantity is less than another of the same type. - /// - public static bool operator <(PhysicalQuantity? left, PhysicalQuantity? right) => - left is null ? right is not null : left.CompareTo(right) < 0; - - /// - /// Determines whether one quantity is less than or equal to another of the same type. - /// - public static bool operator <=(PhysicalQuantity? left, PhysicalQuantity? right) => - left is null || left.CompareTo(right) <= 0; - - /// - /// Determines whether one quantity is greater than another of the same type. - /// - public static bool operator >(PhysicalQuantity? left, PhysicalQuantity? right) => - left is not null && left.CompareTo(right) > 0; - - /// - /// Determines whether one quantity is greater than or equal to another of the same type. - /// - public static bool operator >=(PhysicalQuantity? left, PhysicalQuantity? right) => - left is null ? right is null : left.CompareTo(right) >= 0; -} diff --git a/Semantics.Quantities/PhysicalQuantityCore.cs b/Semantics.Quantities/PhysicalQuantityCore.cs new file mode 100644 index 00000000..efcb15b7 --- /dev/null +++ b/Semantics.Quantities/PhysicalQuantityCore.cs @@ -0,0 +1,92 @@ +// Copyright (c) 2023-2026 ktsu-dev contributors + +namespace ktsu.Semantics.Quantities; + +using System; +using System.Numerics; + +/// +/// The validity and cross-dimension comparison rules every generated physical quantity shares. +/// +/// +/// These used to be inherited from an abstract PhysicalQuantity record. Generated +/// quantities are structs now, and a struct cannot inherit, so each one declares the three +/// members and delegates here — three one-line bodies per type instead of a copy of the rule. +/// The receiver is taken by and constrained to a struct so that delegating +/// does not box it; only the argument, which is already an +/// interface at the call site, can be boxed. +/// +public static class PhysicalQuantityCore +{ + /// + /// Reports whether is a value a physical quantity can hold: finite + /// and not NaN. + /// + /// The storage type for the quantity value. + /// The stored value, in the dimension's SI base unit. + /// when the value is finite and not NaN. + public static bool IsPhysicallyValid(T value) + where T : struct, INumber + => !T.IsNaN(value) && T.IsFinite(value); + + /// + /// Compares to another quantity of the same physical dimension. + /// + /// + /// Quantities of different dimensions are not ordered, so this throws rather than inventing + /// an answer. Equality, below, is total instead and returns . + /// + /// The receiver's quantity type. + /// The storage type for the quantity value. + /// The receiver. + /// The quantity to compare against, or . + /// + /// A negative number, zero or a positive number as sorts before, + /// with, or after . A other sorts first. + /// + /// + /// When the two quantities do not share a physical dimension. + /// + public static int Compare(in TSelf self, IPhysicalQuantity? other) + where TSelf : struct, IPhysicalQuantity + where T : struct, INumber + { + if (other is null) + { + return 1; + } + + if (!Equals(self.Dimension, other.Dimension)) + { + throw new ArgumentException( + $"Cannot compare quantity of dimension '{self.Dimension.Name}' to quantity of dimension '{other.Dimension.Name}'.", + nameof(other)); + } + + return self.Value.CompareTo(other.Value); + } + + /// + /// Reports whether two quantities share a dimension and a value. + /// + /// + /// Equality is total: comparing across dimensions returns rather than + /// throwing, because a collection asking whether it already holds a value must get an answer. + /// + /// The receiver's quantity type. + /// The storage type for the quantity value. + /// The receiver. + /// The quantity to compare against, or . + /// when both dimension and value match. + public static bool AreEqual(in TSelf self, IPhysicalQuantity? other) + where TSelf : struct, IPhysicalQuantity + where T : struct, INumber + { + if (other is null) + { + return false; + } + + return Equals(self.Dimension, other.Dimension) && self.Value.Equals(other.Value); + } +} diff --git a/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs b/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs index 8a2f3f89..9103b09c 100644 --- a/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs +++ b/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs @@ -804,7 +804,7 @@ private static void AddDimensionAndInMembers(ClassTemplate cls, PhysicalDimensio cls.Members.Add(new FieldTemplate() { Comments = {$"/// Gets the physical dimension this quantity belongs to."}, - Keywords = {Emit.Public, "override", "DimensionInfo"}, + Keywords = {Emit.Public, "DimensionInfo"}, Name = $"Dimension => PhysicalDimensions.{dim.Name}", }); @@ -829,6 +829,190 @@ private static void AddDimensionAndInMembers(ClassTemplate cls, PhysicalDimensio }); } + /// + /// Adds the members a scalar-storage quantity used to inherit from the abstract + /// PhysicalQuantity record: the stored value, construction, arithmetic, ordering and + /// the surface. + /// + /// + /// A quantity is a struct, so none of this can be inherited. Emitting it per type is not + /// only the way to keep the surface — it is the point: an operator declared on the type + /// itself is a direct call the JIT can inline, where the shared generic base allocated a + /// new object for every result. + /// + /// The type being built. + /// The type's name including its type argument, e.g. Mass<T>. + /// + /// Whether this is a magnitude (Vector0) type. A V0 declares its own subtraction — + /// T.Abs(left - right), per the locked decision in #52 — so the plain one is skipped + /// rather than emitted twice. + /// + private static void AddValueTypeCore(ClassTemplate cls, string fullType, bool isV0) + { + // A doc comment is XML, so the type argument is spelled with braces: Mass{T}, not Mass. + string docRef = $"', '}')}\"/>"; + + cls.Members.Add(new PropertyTemplate() + { + Comments = {"/// Gets the stored value, in the dimension's SI base unit."}, + Keywords = {Emit.Public}, + Type = "T", + Name = "Quantity", + Getter = new AccessorTemplate { Kind = AccessorKind.Auto }, + Setter = new AccessorTemplate { Kind = AccessorKind.Auto }, + SetterIsInitOnly = true, + }); + + cls.Members.Add(new FieldTemplate() + { + Comments = {"/// Gets the value stored in this quantity (in the dimension's SI base unit)."}, + Keywords = {Emit.Public, "T"}, + Name = "Value => Quantity", + }); + + cls.Members.Add(new FieldTemplate() + { + Comments = {"/// Gets whether this quantity is finite and not NaN."}, + Keywords = {Emit.Public, "bool"}, + Name = "IsPhysicallyValid => PhysicalQuantityCore.IsPhysicallyValid(Quantity)", + }); + + cls.Members.Add(new MethodTemplate() + { + Comments = + { + Emit.SummaryOpen, + "/// Creates a quantity holding , in the SI base unit.", + Emit.SummaryClose, + "/// The value in the SI base unit.", + "/// A new quantity holding .", + }, + Keywords = {Emit.Public, Emit.Static, fullType}, + Name = "Create", + Parameters = {new ParameterTemplate { Type = "T", Name = Emit.ValueParameter }}, + BodyFactory = (body) => body.Write("=> new() { Quantity = value };"), + }); + + cls.Members.Add(new MethodTemplate() + { + Comments = + { + Emit.SummaryOpen, + "/// Compares this quantity to another of the same physical dimension.", + Emit.SummaryClose, + "/// The quantity to compare against.", + "/// A negative number, zero or a positive number as this sorts before, with, or after .", + "/// When the two do not share a dimension.", + }, + Keywords = {Emit.Public, "int"}, + Name = "CompareTo", + Parameters = {new ParameterTemplate { Type = "IPhysicalQuantity", Name = "other" }}, + BodyFactory = (body) => body.Write($"=> PhysicalQuantityCore.Compare<{fullType}, T>(this, other);"), + }); + + cls.Members.Add(new MethodTemplate() + { + Comments = + { + Emit.SummaryOpen, + "/// Reports whether this quantity shares a dimension and a value with .", + Emit.SummaryClose, + "/// The quantity to compare against.", + "/// when both dimension and value match.", + }, + Keywords = {Emit.Public, "bool"}, + Name = "Equals", + Parameters = {new ParameterTemplate { Type = "IPhysicalQuantity", Name = "other" }}, + BodyFactory = (body) => body.Write($"=> PhysicalQuantityCore.AreEqual<{fullType}, T>(this, other);"), + }); + + AddBinaryOperator(cls, fullType, "+", fullType, fullType, "=> Create(left.Quantity + right.Quantity);", + $"Adds two {docRef} values."); + + if (!isV0) + { + AddBinaryOperator(cls, fullType, "-", fullType, fullType, "=> Create(left.Quantity - right.Quantity);", + $"Subtracts one {docRef} from another."); + } + + cls.Members.Add(new MethodTemplate() + { + Comments = {$"/// Negates a {docRef}."}, + Attributes = {Emit.PhysicsOperatorSuppression}, + Keywords = {Emit.Public, Emit.Static, fullType}, + Name = "operator -", + Parameters = {new ParameterTemplate { Type = fullType, Name = Emit.ValueParameter }}, + BodyFactory = (body) => body.Write("=> Create(-value.Quantity);"), + }); + + AddBinaryOperator(cls, fullType, "*", fullType, "T", "=> Create(left.Quantity * right);", + $"Scales a {docRef} by a bare number."); + AddBinaryOperator(cls, fullType, "*", "T", fullType, "=> Create(left * right.Quantity);", + $"Scales a {docRef} by a bare number."); + AddBinaryOperator(cls, fullType, "/", fullType, "T", + "=> T.IsZero(right) ? throw new System.DivideByZeroException(\"Cannot divide by zero.\") : Create(left.Quantity / right);", + $"Divides a {docRef} by a bare number."); + AddBinaryOperator(cls, "T", "/", fullType, fullType, + "=> T.IsZero(right.Quantity) ? throw new System.DivideByZeroException(\"Cannot divide by zero.\") : left.Quantity / right.Quantity;", + $"Divides one {docRef} by another, giving the bare ratio."); + + AddBinaryOperator(cls, "bool", "<", fullType, fullType, "=> left.Quantity < right.Quantity;", + "Reports whether the left value sorts before the right."); + AddBinaryOperator(cls, "bool", "<=", fullType, fullType, "=> left.Quantity <= right.Quantity;", + "Reports whether the left value sorts before or with the right."); + AddBinaryOperator(cls, "bool", ">", fullType, fullType, "=> left.Quantity > right.Quantity;", + "Reports whether the left value sorts after the right."); + AddBinaryOperator(cls, "bool", ">=", fullType, fullType, "=> left.Quantity >= right.Quantity;", + "Reports whether the left value sorts after or with the right."); + + cls.Members.Add(new MethodTemplate() + { + Comments = + { + "/// Returns the stored value as text.", + "/// The value in the SI base unit, rendered by .", + }, + Keywords = {Emit.Public, "override", "string"}, + Name = "ToString", + Parameters = {}, + BodyFactory = (body) => body.Write("=> Quantity.ToString() ?? string.Empty;"), + }); + } + + /// + /// Adds one binary operator to . + /// + /// The type being built. + /// What the operator returns. + /// The operator symbol. + /// The left operand's type. + /// The right operand's type. + /// The expression body, including its leading arrow. + /// One line of documentation. + private static void AddBinaryOperator( + ClassTemplate cls, + string returnType, + string symbol, + string leftType, + string rightType, + string body, + string summary) + { + cls.Members.Add(new MethodTemplate() + { + Comments = {$"/// {summary}"}, + Attributes = {Emit.PhysicsOperatorSuppression}, + Keywords = {Emit.Public, Emit.Static, returnType}, + Name = $"operator {symbol}", + Parameters = + { + new ParameterTemplate { Type = leftType, Name = "left" }, + new ParameterTemplate { Type = rightType, Name = Emit.RightParameter }, + }, + BodyFactory = (b) => b.Write(body), + }); + } + private static Dictionary> GroupBy(List items, Func keySelector) { Dictionary> groups = []; @@ -880,14 +1064,16 @@ private void EmitV0BaseType( Emit.SummaryClose, "/// The numeric storage type.", }, - Kind = TypeKind.Record, - Keywords = {Emit.Public, "partial"}, + Kind = TypeKind.RecordStruct, + Keywords = {Emit.Public, "readonly", "partial"}, Name = fullType, - BaseClass = $"PhysicalQuantity<{fullType}, T>", - Interfaces = {$"IVector0<{fullType}, T>"}, + Interfaces = {$"IVector0<{fullType}, T>", $"IPhysicalQuantity<{fullType}, T>"}, Constraints = {"where T : struct, INumber"}, }; + // Everything a quantity used to inherit from the PhysicalQuantity record. + AddValueTypeCore(cls, fullType, isV0: true); + // Zero property (satisfies IVector0) cls.Members.Add(new FieldTemplate() { @@ -974,14 +1160,16 @@ private void EmitV1BaseType( Emit.SummaryClose, "/// The numeric storage type.", }, - Kind = TypeKind.Record, - Keywords = {Emit.Public, "partial"}, + Kind = TypeKind.RecordStruct, + Keywords = {Emit.Public, "readonly", "partial"}, Name = fullType, - BaseClass = $"PhysicalQuantity<{fullType}, T>", - Interfaces = {$"IVector1<{fullType}, T>"}, + Interfaces = {$"IVector1<{fullType}, T>", $"IPhysicalQuantity<{fullType}, T>"}, Constraints = {"where T : struct, INumber"}, }; + // Everything a quantity used to inherit from the PhysicalQuantity record. + AddValueTypeCore(cls, fullType, isV0: false); + // Zero property (satisfies IVector1) cls.Members.Add(new FieldTemplate() { @@ -1069,7 +1257,7 @@ private static void EmitVectorType( cb.WriteLine($"/// {dims}D vector representation of {dim.Name}."); cb.WriteLine(Emit.SummaryClose); cb.WriteLine("/// The numeric component type."); - cb.WriteLine($"public partial record {fullType} : {interfaceName}"); + cb.WriteLine($"public readonly partial record struct {fullType} : {interfaceName}"); cb.WriteLine("\twhere T : struct, INumber"); using (new ScopeWithTrailingSemicolon(cb)) @@ -1157,14 +1345,16 @@ private void EmitOverloadType( Emit.SummaryClose, "/// The numeric storage type.", }, - Kind = TypeKind.Record, - Keywords = {Emit.Public, "partial"}, + Kind = TypeKind.RecordStruct, + Keywords = {Emit.Public, "readonly", "partial"}, Name = fullType, - BaseClass = $"PhysicalQuantity<{fullType}, T>", - Interfaces = {interfaceName}, + Interfaces = {interfaceName, $"IPhysicalQuantity<{fullType}, T>"}, Constraints = {"where T : struct, INumber"}, }; + // Everything a quantity used to inherit from the PhysicalQuantity record. + AddValueTypeCore(cls, fullType, isV0: vectorForm == 0); + // Zero property cls.Members.Add(new FieldTemplate() { @@ -1332,7 +1522,7 @@ private static void EmitVectorOverloadType( cb.WriteLine($"/// {overload.Description}"); cb.WriteLine($"/// Semantic overload of ."); cb.WriteLine(Emit.SummaryClose); - cb.WriteLine($"public partial record {fullType} : {interfaceName}"); + cb.WriteLine($"public readonly partial record struct {fullType} : {interfaceName}"); cb.WriteLine("\twhere T : struct, INumber"); using (new ScopeWithTrailingSemicolon(cb)) @@ -1380,7 +1570,9 @@ private static void EmitScalarOperators( // For V0/V1 owner types, use Multiply/Divide helpers when both operands are V0/V1 if (leftForm <= 1 && rightForm <= 1) { - string helperName = op.Op == "*" ? "Multiply" : "Divide"; + // The inherited Multiply/Divide helpers went away with the record base. A + // quantity constructs its result directly now, which is also what makes the + // operator a plain arithmetic expression the JIT can inline. cls.Members.Add(new MethodTemplate() { Comments = @@ -1397,7 +1589,8 @@ private static void EmitScalarOperators( new ParameterTemplate { Type = $"{op.LeftTypeName}", Name = "left" }, new ParameterTemplate { Type = $"{op.RightTypeName}", Name = Emit.RightParameter }, }, - BodyFactory = (body) => body.Write($"=> {helperName}<{op.ReturnTypeName}>(left, right);"), + BodyFactory = (body) => body.Write( + $"=> {op.ReturnTypeName}.Create(left.Quantity {op.Op} right.Quantity);"), }); } else diff --git a/Semantics.Test/Quantities/QuantityValueTypeTests.cs b/Semantics.Test/Quantities/QuantityValueTypeTests.cs new file mode 100644 index 00000000..cb3c150b --- /dev/null +++ b/Semantics.Test/Quantities/QuantityValueTypeTests.cs @@ -0,0 +1,168 @@ +// Copyright (c) 2023-2026 ktsu-dev contributors + +namespace ktsu.Semantics.Test.Quantities; + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using ktsu.Semantics.Quantities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +/// +/// Locks in that a quantity is a value type, and that arithmetic on one allocates nothing. +/// +/// +/// Quantities used to be records deriving from an abstract PhysicalQuantity, whose +/// Create was new TQuantity() with { Quantity = value } — two heap allocations, +/// 48 bytes, for every operator and every unit factory. That is invisible in a unit test and +/// ruinous in a per-frame loop, so the property is asserted here rather than left to be +/// rediscovered. +/// +[TestClass] +public sealed class QuantityValueTypeTests +{ + /// + /// Every generated quantity is a struct. This is what makes the allocation test below + /// possible, and what lets a consumer lay a quantity out inline in a component. + /// + [TestMethod] + public void EveryGeneratedQuantityIsAValueType() + { + List quantities = [.. CollectGeneratedQuantityTypes(typeof(Mass<>).Assembly)]; + + // Sanity: a filter that silently matched nothing would pass vacuously. + Assert.IsGreaterThan( + 50, + quantities.Count, + $"Expected to find many generated quantity types (got {quantities.Count}). The filter likely needs updating."); + + List referenceTypes = [.. quantities.Where(static t => !t.IsValueType).Select(static t => t.Name)]; + + Assert.IsEmpty( + referenceTypes, + $"These generated quantities are reference types and will allocate on every operation:\n " + + string.Join("\n ", referenceTypes)); + } + + /// + /// Arithmetic, unit factories and cross-dimensional operators allocate nothing. + /// + /// + /// Measured rather than inferred from the type's shape: a struct returned through a shared + /// generic path can still be boxed, so the byte counter is what actually settles it. The + /// warm-up is what keeps tiered compilation out of the measurement. + /// + [TestMethod] + public void QuantityArithmeticDoesNotAllocate() + { + Length a = Length.FromMeter(3.0); + Duration t = Duration.FromSecond(1.5); + + Assert.AreEqual(0L, MeasureAllocation(() => (a + a).Value), "addition allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => (a - a).Value), "subtraction allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => (a * 2.0).Value), "scaling allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => Length.FromMeter(3.0).Value), "a base-unit factory allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => Length.FromFoot(3.0).Value), "a converting factory allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => (a / t).Value), "a cross-dimensional operator allocated"); + } + + /// + /// A vector quantity is a value type too, and its arithmetic allocates nothing. + /// + [TestMethod] + public void VectorQuantityArithmeticDoesNotAllocate() + { + Velocity3D v = new() { X = 1.0, Y = 2.0, Z = 3.0 }; + + Assert.AreEqual(0L, MeasureAllocation(() => (v + v).X), "vector addition allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => (v * 2.0).Y), "vector scaling allocated"); + Assert.AreEqual(0L, MeasureAllocation(() => v.Magnitude().Value), "Magnitude() allocated"); + } + + /// + /// The stored value still renders as the bare number, not as a record's { Quantity = 2.5 }. + /// + [TestMethod] + public void ToStringIsTheBareValue() + => Assert.AreEqual("2.5", Length.FromMeter(2.5).ToString()); + + /// + /// default of a quantity is its zero, and equals Zero. + /// + [TestMethod] + public void DefaultIsZero() + { + Assert.AreEqual(0.0, default(Mass).Value); + Assert.AreEqual(Mass.Zero, default); + } + + /// + /// The one behaviour a value type gives up: default does not run a factory, so a + /// quantity whose constraint excludes zero can be reached at zero through it. + /// + /// + /// This affects only the V0 overloads declaring physicalConstraints.minExclusive: "0" + /// — Wavelength, Period and HalfLife. Every other quantity's invariant + /// is non-negativity, which zero already satisfies, so default is a legal value for + /// them. The test exists to state the gap rather than to endorse it: a caller that must + /// reject an unset value should ask, and Zero is the value to compare against. + /// + [TestMethod] + public void DefaultBypassesAStrictlyPositiveConstructionGuard() + { + Assert.ThrowsExactly(static () => Wavelength.FromMeter(0.0)); + Assert.AreEqual(0.0, default(Wavelength).Value); + } + + /// + /// Runs enough times for tiering to settle, then reports the bytes + /// it allocates per iteration over a measured run. + /// + /// The expression under measurement, returning its result. + /// Bytes allocated per iteration, rounded down. + private static long MeasureAllocation(Func body) + { + const int WarmUp = 10_000; + const int Iterations = 100_000; + + double accumulated = 0.0; + for (int i = 0; i < WarmUp; i++) + { + accumulated += body(); + } + + // No GC.Collect first: this counter is the thread's cumulative allocation total, which + // a collection does not reset. Collecting would measure nothing and cost seconds. + long before = GC.GetAllocatedBytesForCurrentThread(); + for (int i = 0; i < Iterations; i++) + { + accumulated += body(); + } + + long allocated = GC.GetAllocatedBytesForCurrentThread() - before; + + // Reading the accumulated result is what stops the measured expression being optimised + // away — without it the loop could be removed and every measurement would read zero. + Assert.IsTrue(double.IsFinite(accumulated), "the measured expression produced a non-finite result"); + + return allocated / Iterations; + } + + private static IEnumerable CollectGeneratedQuantityTypes(Assembly assembly) + { + foreach (Type type in assembly.GetTypes()) + { + if (type.Namespace != "ktsu.Semantics.Quantities" || !type.IsGenericTypeDefinition) + { + continue; + } + + // Generated quantity types implement one of IVector0..IVector4 (closed over TSelf, T). + if (type.GetInterfaces().Any(static i => i.IsGenericType && i.Name.StartsWith("IVector", StringComparison.Ordinal))) + { + yield return type; + } + } + } +} diff --git a/docs/architecture.md b/docs/architecture.md index bd1a7567..ecbfff12 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -323,8 +323,7 @@ Semantics.Quantities/Generated/ (committed source — diff before commit) ### Runtime contract — `IPhysicalQuantity` Every generated V0 / V1 quantity (and V0/V1 semantic overload) implements -`IPhysicalQuantity` through the `PhysicalQuantity` base. The contract is -deliberately slim: +`IPhysicalQuantity`, and through it the slim `IPhysicalQuantity`: ```csharp public interface IPhysicalQuantity @@ -353,6 +352,18 @@ Semantics (locked in #59): V2 / V3 / V4 vector types implement only their `IVectorN` interface — the slim `IPhysicalQuantity` contract applies to scalar-storage quantities. +A quantity is a **`readonly record struct`**, so none of this is inherited: there is no +base class to inherit it from. `IPhysicalQuantity` adds +`static abstract TSelf Create(T)`, which is what replaced the +`where TSelf : PhysicalQuantity, new()` constraint the record base needed, and +the generator emits the members per type. That is not merely how the surface is kept — +it is the point. The record base's `Create` was `new TQuantity() with { Quantity = value }`, +two heap allocations for one number, on every operator and every unit factory; an operator +declared on the struct itself is a plain arithmetic expression the JIT inlines to nothing. +The three rules above are shared without a base class through `PhysicalQuantityCore`, +which each quantity delegates to in one line. `QuantityValueTypeTests` measures the +allocation, so the regression cannot return silently. + ### Unit conversion — typed `In(...)` Each V0/V1 quantity emits a dimensionally-typed `In` method: diff --git a/docs/migration-guide-4.0.md b/docs/migration-guide-4.0.md new file mode 100644 index 00000000..fa95f501 --- /dev/null +++ b/docs/migration-guide-4.0.md @@ -0,0 +1,91 @@ +# Migrating from Semantics 3.x to 4.0 + +Semantics 4.0 makes every physical quantity a **value type**. `Length`, +`Velocity3D`, `Weight` and the other 212 generated quantities were +`record` classes; they are now `readonly record struct`. + +Strings, Paths, Music and Color are unaffected. + +## Why + +The record base built every result with `new TQuantity() with { Quantity = value }` — +two heap allocations for one number. Every operator and every unit factory went through +it, so `a + b` on a `Length` allocated 48 bytes: + +``` +a + b : 48.0 bytes/op → 0.0 bytes/op +FromMeter : 48.0 bytes/op → 0.0 bytes/op +FromFoot : 48.0 bytes/op → 0.0 bytes/op +Length / Duration: 48.0 bytes/op → 0.0 bytes/op +``` + +In a loop over a few thousand entities at 60 Hz that is tens of megabytes a second of +garbage, for a library whose whole purpose is to be the type a number is stored in. +`QuantityValueTypeTests` measures this now, so it cannot come back. + +## Quick checklist + +1. Remove null checks and `?` annotations on quantities — a struct is never null. +2. Replace `quantity is null` / `== null` with a comparison against `Zero`, if you + meant "unset". +3. If you derived from `PhysicalQuantity`, implement + `IPhysicalQuantity` on a struct instead. +4. Nothing to do for arithmetic, unit factories, `In(unit)`, `Dimension`, `CompareTo`, + `Equals`, comparison operators, or `ToString` — all identical. + +## 1. A quantity cannot be null + +```csharp +Length? maybe = null; // now Nullable>, not a null reference +if (length is null) { … } // no longer compiles for a non-nullable quantity +ArgumentNullException.ThrowIfNull(m); // now a no-op; analyzers flag it (CA2264) +``` + +Code that treated "no quantity" as `null` should use `Zero`, or `Nullable<>` where the +distinction between "zero" and "not supplied" genuinely matters. + +## 2. `PhysicalQuantity` is gone + +The abstract record base has been replaced by two things: + +- **`IPhysicalQuantity`** — the interface a quantity implements, carrying + `static abstract TSelf Create(T value)`. This is the seam that replaced the + `where TSelf : PhysicalQuantity, new()` constraint, so generic code over + quantities still works. +- **`PhysicalQuantityCore`** — the static class holding the validity and + cross-dimension comparison rules a quantity used to inherit. Generated quantities + delegate to it; you would rarely call it directly. + +`SemanticQuantity` and `SemanticQuantity` are **unchanged**. +They remain available for a reference-type semantic quantity of your own; the physical +quantities simply no longer derive from them. + +## 3. `default` does not run a construction guard + +This is the one behaviour given up, and it is narrow. + +A Vector0 quantity is non-negative, and `default` gives it zero — which satisfies that +invariant, so nothing changes for it. But three quantities declare +`physicalConstraints.minExclusive: "0"` in `dimensions.json` — `Wavelength`, `Period` +and `HalfLife` — for which zero is unphysical: + +```csharp +Wavelength.FromMeter(0.0); // still throws ArgumentException +default(Wavelength).Value; // 0.0 — the guard cannot run +``` + +A struct always has a zero value and no factory can intercept it. If you need to reject +an unset value, compare against `Zero` explicitly rather than relying on construction to +have refused it. + +## 4. Equality and hashing + +Value equality is unchanged in what it reports: two quantities are equal when they share +a type and a value, and `Equals(IPhysicalQuantity)` still compares dimension and +value, returning `false` across dimensions rather than throwing. `CompareTo` still throws +`ArgumentException` across dimensions, because quantities of different dimensions are not +ordered. + +What changed is that a quantity is no longer reference-comparable. `ReferenceEquals(a, b)` +on two quantities now boxes both and is always `false`; it was never meaningful and is +now visibly so. diff --git a/docs/physics-generator.md b/docs/physics-generator.md index 43f8daa6..9d705818 100644 --- a/docs/physics-generator.md +++ b/docs/physics-generator.md @@ -2,7 +2,7 @@ The semantic quantities system is generated by Roslyn incremental generators in `Semantics.SourceGenerators/`, driven by metadata files in `Semantics.SourceGenerators/Metadata/`. This doc explains the schema and the workflow for adding or changing dimensions. -For the *why* (the unified vector model), see `docs/strategy-unified-vector-quantities.md`. For the runtime contracts (`IVector0`..`IVector4`, `PhysicalQuantity`), see `Semantics.Quantities/`. +For the *why* (the unified vector model), see `docs/strategy-unified-vector-quantities.md`. For the runtime contracts (`IVector0`..`IVector4`, `IPhysicalQuantity`), see `Semantics.Quantities/`. ## What gets generated diff --git a/docs/strategy-unified-vector-quantities.md b/docs/strategy-unified-vector-quantities.md index 973e16ee..c22622de 100644 --- a/docs/strategy-unified-vector-quantities.md +++ b/docs/strategy-unified-vector-quantities.md @@ -707,7 +707,7 @@ For each entry in `quantities` (vector0 through vector4): ```csharp // vector0 → implements IVector0 -public record Speed : IVector0, T> +public readonly record struct Speed : IVector0, T> where T : struct, INumber { public T Value { get; init; } @@ -734,7 +734,7 @@ public record Speed : IVector0, T> ```csharp // vector1 → implements IVector1 -public record Velocity1D : IVector1, T> +public readonly record struct Velocity1D : IVector1, T> where T : struct, INumber { public T Value { get; init; } @@ -759,7 +759,7 @@ public record Velocity1D : IVector1, T> ```csharp // vector3 → implements IVector3 -public record Velocity3D : IVector3, T> +public readonly record struct Velocity3D : IVector3, T> where T : struct, INumber { public T X { get; init; } @@ -791,7 +791,7 @@ public record Velocity3D : IVector3, T> For each overload in a vector form's `overloads` array: ```csharp -public record Width : IVector0, T> +public readonly record struct Width : IVector0, T> where T : struct, INumber { public T Value { get; init; } @@ -1059,7 +1059,7 @@ Semantic overloads are generated as thin wrapper records around the base type: ```csharp // Generated base type -public record Length : IVector0, T> +public readonly record struct Length : IVector0, T> where T : struct, INumber { public T Value { get; init; } @@ -1067,7 +1067,7 @@ public record Length : IVector0, T> } // Generated semantic overload -public record Width : IVector0, T> +public readonly record struct Width : IVector0, T> where T : struct, INumber { public T Value { get; init; }