From 6806b6394cd55d6c0c55f688229b1ee1123f6cdd Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 9 May 2026 12:11:00 +0000 Subject: [PATCH] feat(generator): add SEM002 metadata validation; refresh stale generator output - Adds DimensionsMetadata.Validate() and a SEM002 Roslyn diagnostic so malformed entries in dimensions.json (missing name/symbol, empty availableUnits, duplicate type names, no vector forms declared) surface in the build log instead of crashing the emit pass or dropping output silently. Pairs with the existing SEM001 (closes #60). - Adds AnalyzerReleases.Shipped/Unshipped.md so SEM001/SEM002 satisfy RS2008 analyzer release tracking; the generator project now builds clean. - Re-runs QuantitiesGenerator to refresh 132 committed .g.cs files that were stale relative to the V0 non-negativity / absolute V0-V0 subtraction work merged in #66/#68. Diff is purely the documented #50/#52 changes (Vector0Guards.EnsureNonNegative in factories; same-type T.Abs subtraction replacing the old V1-typed result). - CLAUDE.md: corrects the V0 invariant entry (constraints are enforced structurally, not yet declared in metadata), fixes the PhysicalConstants surface to match what's actually emitted (no Conversion sub-class), and lists the SEM00x diagnostics. --- CLAUDE.md | 17 ++- .../AbsorbedDose.g.cs | 8 +- .../AccelerationMagnitude.g.cs | 8 +- .../AcousticImpedance.g.cs | 8 +- .../ActivationEnergy.g.cs | 4 +- .../Admittance.g.cs | 4 +- .../Airspeed.g.cs | 6 +- .../Altitude.g.cs | 6 +- .../AmountOfSubstance.g.cs | 8 +- .../Angle.g.cs | 8 +- .../AngularAccelerationMagnitude.g.cs | 8 +- .../AngularJerkMagnitude.g.cs | 8 +- .../AngularMomentumMagnitude.g.cs | 8 +- .../AngularSpeed.g.cs | 8 +- .../ApertureAngle.g.cs | 6 +- .../Area.g.cs | 8 +- .../AtmosphericPressure.g.cs | 4 +- .../AtomicMass.g.cs | 4 +- .../Bandwidth.g.cs | 4 +- .../BulkModulus.g.cs | 4 +- .../Capacitance.g.cs | 8 +- .../Capacity.g.cs | 4 +- .../CatalyticActivity.g.cs | 8 +- .../ChargeMagnitude.g.cs | 8 +- .../ClockSpeed.g.cs | 4 +- .../Concentration.g.cs | 8 +- .../Conductance.g.cs | 8 +- .../CrossSectionalArea.g.cs | 4 +- .../CurrentMagnitude.g.cs | 8 +- .../DecayTime.g.cs | 4 +- .../Density.g.cs | 8 +- .../Depth.g.cs | 6 +- .../Diameter.g.cs | 6 +- .../Distance.g.cs | 6 +- .../Drag.g.cs | 6 +- .../Duration.g.cs | 8 +- .../DynamicViscosity.g.cs | 8 +- .../EMF.g.cs | 6 +- .../ElectricFieldMagnitude.g.cs | 8 +- .../Energy.g.cs | 8 +- .../EnergyFluxDensity.g.cs | 4 +- .../Entropy.g.cs | 8 +- .../EnzymeActivity.g.cs | 4 +- .../EquivalentDose.g.cs | 8 +- .../Exposure.g.cs | 8 +- .../FieldOfView.g.cs | 6 +- .../FlowSpeed.g.cs | 6 +- .../ForceMagnitude.g.cs | 8 +- .../Frequency.g.cs | 8 +- .../Friction.g.cs | 6 +- .../GaugePressure.g.cs | 4 +- .../GravitationalAcceleration.g.cs | 6 +- .../GroundSpeed.g.cs | 6 +- .../GroupVelocity.g.cs | 6 +- .../HalfLife.g.cs | 4 +- .../Heat.g.cs | 4 +- .../HeatCapacity.g.cs | 4 +- .../HeatFlowRate.g.cs | 4 +- .../HeatFlux.g.cs | 4 +- .../HeatTransferCoefficient.g.cs | 8 +- .../Height.g.cs | 6 +- .../Illuminance.g.cs | 8 +- .../Inductance.g.cs | 8 +- .../Irradiance.g.cs | 8 +- .../JerkMagnitude.g.cs | 8 +- .../KinematicViscosity.g.cs | 8 +- .../KineticEnergy.g.cs | 4 +- .../Latency.g.cs | 4 +- .../Length.g.cs | 8 +- .../Lift.g.cs | 6 +- .../Luminance.g.cs | 4 +- .../LuminousFlux.g.cs | 8 +- .../LuminousIntensity.g.cs | 8 +- .../MachNumber.g.cs | 6 +- .../MagneticFlux.g.cs | 8 +- .../MagneticFluxDensityMagnitude.g.cs | 8 +- .../Mass.g.cs | 8 +- .../MassFlowRate.g.cs | 8 +- .../MolarEnergy.g.cs | 8 +- .../MolarEnthalpy.g.cs | 4 +- .../MolarMass.g.cs | 8 +- .../MomentOfInertia.g.cs | 8 +- .../MomentumMagnitude.g.cs | 8 +- .../NormalForce.g.cs | 6 +- .../NuclearCrossSection.g.cs | 8 +- .../OpticalPower.g.cs | 8 +- .../Perimeter.g.cs | 6 +- .../Period.g.cs | 4 +- .../PhaseVelocity.g.cs | 6 +- .../Pitch.g.cs | 4 +- .../PotentialEnergy.g.cs | 4 +- .../Power.g.cs | 8 +- .../Pressure.g.cs | 8 +- .../RadioactiveActivity.g.cs | 8 +- .../Radius.g.cs | 6 +- .../Ratio.g.cs | 8 +- .../ReactionRate.g.cs | 8 +- .../RefractiveIndex.g.cs | 6 +- .../Resistance.g.cs | 8 +- .../ReverberationTime.g.cs | 4 +- .../ReynoldsNumber.g.cs | 6 +- .../SamplingRate.g.cs | 4 +- .../ShearModulus.g.cs | 4 +- .../SnapMagnitude.g.cs | 8 +- .../SoundIntensity.g.cs | 4 +- .../SoundSpeed.g.cs | 6 +- .../SpecificEntropy.g.cs | 4 +- .../SpecificGravity.g.cs | 6 +- .../SpecificHeat.g.cs | 8 +- .../Speed.g.cs | 8 +- .../Stress.g.cs | 4 +- .../SurfaceArea.g.cs | 4 +- .../SurfaceTension.g.cs | 8 +- .../Temperature.g.cs | 8 +- .../Tension.g.cs | 6 +- .../ThermalConductivity.g.cs | 8 +- .../ThermalDiffusivity.g.cs | 4 +- .../ThermalEnergy.g.cs | 4 +- .../ThermalExpansionCoefficient.g.cs | 8 +- .../Thickness.g.cs | 6 +- .../Thrust.g.cs | 6 +- .../TimeConstant.g.cs | 4 +- .../TorqueMagnitude.g.cs | 8 +- .../VoltageDrop.g.cs | 6 +- .../VoltageMagnitude.g.cs | 8 +- .../Volume.g.cs | 8 +- .../VolumetricFlowRate.g.cs | 8 +- .../Wavelength.g.cs | 6 +- .../Weight.g.cs | 6 +- .../Width.g.cs | 6 +- .../WindSpeed.g.cs | 6 +- .../Work.g.cs | 4 +- .../YoungsModulus.g.cs | 4 +- .../AnalyzerReleases.Shipped.md | 2 + .../AnalyzerReleases.Unshipped.md | 9 ++ .../Generators/QuantitiesGenerator.cs | 19 ++++ .../Models/DimensionsMetadata.cs | 106 ++++++++++++++++++ 137 files changed, 755 insertions(+), 240 deletions(-) create mode 100644 Semantics.SourceGenerators/AnalyzerReleases.Shipped.md create mode 100644 Semantics.SourceGenerators/AnalyzerReleases.Unshipped.md diff --git a/CLAUDE.md b/CLAUDE.md index a001f4f..0f851d7 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -51,19 +51,25 @@ These are now baked into the generator and enforced by tests. **Do not reopen wi 1. **`V0 - V0` returns the same `V0` of `T.Abs(a - b)`.** Magnitude subtraction stays non-negative; signed subtraction must use the V1 form explicitly. 2. **Dimensionless and angular quantities have both `Ratio` (V0) and `SignedRatio` (V1) bases.** Ratios that semantically must be non-negative (e.g. `RefractiveIndex`, `MachNumber`, `SpecificGravity`) are V0 overloads of `Ratio`. 3. **Semantic overloads widen implicitly to their base, narrow explicitly from it.** A `Weight` is implicitly a `ForceMagnitude`; the reverse requires `Weight.From(forceMagnitude)` or an explicit cast. -4. **Physical constraints come from per-dimension metadata.** Floors like absolute zero or non-negative frequency are declared in `dimensions.json` and the generator emits `ArgumentException`-throwing guards inside the `Create`/`From*` factories. +4. **Physical constraints are enforced structurally via the V0 (magnitude) form.** `Vector0` factories run `Vector0Guards.EnsureNonNegative` and throw `ArgumentException` on a negative value. That covers absolute zero (Temperature is V0, so Kelvin must be ≥ 0), non-negative frequency, non-negative absolute pressure, etc. Strict-positive or upper-bound constraints are not yet declared in metadata (tracked separately). ### Physical constants -`PhysicalConstants` is **generated** from `dimensions.json` (and a constants fixture). Public surface: +`PhysicalConstants` is **generated** from `domains.json`. Public surface: ```csharp +// Domain-grouped PreciseNumber values: +PhysicalConstants.Fundamental.SpeedOfLight +PhysicalConstants.Fundamental.PlanckConstant +PhysicalConstants.AngularMechanics.DegreesPerRadian + +// Generic accessors that materialise into any T : INumber: PhysicalConstants.Generic.SpeedOfLight() PhysicalConstants.Generic.PlanckConstant() -PhysicalConstants.Conversion.FeetToMeters() +PhysicalConstants.Generic.DegreesPerRadian() ``` -Use these accessors instead of hard-coded numerics. Backing values are stored as `PreciseNumber` and converted with `T.CreateChecked` per call. +Backing values are stored as `PreciseNumber` and converted with `T.CreateChecked` per call. ### Operators and physics relationships @@ -139,6 +145,9 @@ var converted = sourceString.As(); - Edit `Semantics.SourceGenerators/Metadata/dimensions.json` to add a dimension, vector form, semantic overload, or relationship. - Rebuild `Semantics.SourceGenerators` and the consuming `Semantics.Quantities` project; emitted files appear in `Semantics.Quantities/Generated/Semantics.SourceGenerators//`. - Treat generator output as committed source. Diff it before commit so accidental regressions are visible. +- Generator diagnostics: + - **SEM001** — a relationship in `dimensions.json` references a dimension that does not exist (typo or rename). The operator is silently dropped. + - **SEM002** — schema-level validation issue (missing `name`/`symbol`, empty `availableUnits`, duplicate type names, no vector forms declared). - See `docs/physics-generator.md` for the full schema and an end-to-end "add a dimension" walk-through. This file is the entry point. For deeper material: 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 a41ab3a..bca841e 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 @@ -22,6 +22,12 @@ public record AbsorbedDose : PhysicalQuantity, T>, IVector0 /// The value in Gray. /// A new instance. - public static AbsorbedDose FromGray(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AbsorbedDose FromGray(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two AbsorbedDose values, returning the absolute difference as a non-negative AbsorbedDose. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AbsorbedDose operator -(AbsorbedDose left, AbsorbedDose right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 70f7271..8087afa 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 @@ -22,11 +22,13 @@ public record AccelerationMagnitude : PhysicalQuantity /// The value in MetersPerSecondSquared. /// A new instance. - public static AccelerationMagnitude FromMetersPerSecondSquared(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AccelerationMagnitude FromMetersPerSecondSquared(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two AccelerationMagnitude values, returning a signed Acceleration1D result. + /// Subtracts two AccelerationMagnitude values, returning the absolute difference as a non-negative AccelerationMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Acceleration1D operator -(AccelerationMagnitude left, AccelerationMagnitude right) => Acceleration1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AccelerationMagnitude operator -(AccelerationMagnitude left, AccelerationMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies AccelerationMagnitude by Mass to produce ForceMagnitude. /// 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 7a552f6..f1da82a 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 @@ -22,6 +22,12 @@ public record AcousticImpedance : PhysicalQuantity, T>, /// /// The value in PascalSecondPerMeter. /// A new instance. - public static AcousticImpedance FromPascalSecondPerMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AcousticImpedance FromPascalSecondPerMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two AcousticImpedance values, returning the absolute difference as a non-negative AcousticImpedance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AcousticImpedance operator -(AcousticImpedance left, AcousticImpedance right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 f8c0167..b7cae07 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 @@ -19,12 +19,14 @@ public record ActivationEnergy : PhysicalQuantity, T>, IV public static ActivationEnergy Zero => Create(T.Zero); /// Creates a new ActivationEnergy from a value in JoulePerMole. - public static ActivationEnergy FromJoulePerMole(T value) => Create(value); + public static ActivationEnergy FromJoulePerMole(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to MolarEnergy. public static implicit operator MolarEnergy(ActivationEnergy value) => MolarEnergy.Create(value.Value); /// Explicit conversion from MolarEnergy. public static explicit operator ActivationEnergy(MolarEnergy value) => Create(value.Value); /// Creates a ActivationEnergy from a MolarEnergy value. public static ActivationEnergy From(MolarEnergy value) => Create(value.Value); +/// Subtracts two ActivationEnergy values, returning the absolute difference as a non-negative ActivationEnergy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ActivationEnergy operator -(ActivationEnergy left, ActivationEnergy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 40fb836..707010c 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 @@ -19,12 +19,14 @@ public record Admittance : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Admittance from a value in Siemens. - public static Admittance FromSiemens(T value) => Create(value); + public static Admittance FromSiemens(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Conductance. public static implicit operator Conductance(Admittance value) => Conductance.Create(value.Value); /// Explicit conversion from Conductance. public static explicit operator Admittance(Conductance value) => Create(value.Value); /// Creates a Admittance from a Conductance value. public static Admittance From(Conductance value) => Create(value.Value); +/// Subtracts two Admittance values, returning the absolute difference as a non-negative Admittance. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Admittance operator -(Admittance left, Admittance right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 153c1e0..f2ec703 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 @@ -19,14 +19,14 @@ public record Airspeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Airspeed from a value in MetersPerSecond. - public static Airspeed FromMetersPerSecond(T value) => Create(value); + public static Airspeed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(Airspeed value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator Airspeed(Speed value) => Create(value.Value); /// Creates a Airspeed from a Speed value. public static Airspeed From(Speed value) => Create(value.Value); -/// Subtracts two Airspeed values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(Airspeed left, Airspeed right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Airspeed values, returning the absolute difference as a non-negative Airspeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Airspeed operator -(Airspeed left, Airspeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 0119a12..f9ddfff 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 @@ -19,14 +19,14 @@ public record Altitude : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Altitude from a value in Meter. - public static Altitude FromMeter(T value) => Create(value); + public static Altitude FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Altitude value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Altitude(Length value) => Create(value.Value); /// Creates a Altitude from a Length value. public static Altitude From(Length value) => Create(value.Value); -/// Subtracts two Altitude values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Altitude left, Altitude right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Altitude values, returning the absolute difference as a non-negative Altitude. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Altitude operator -(Altitude left, Altitude right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 f0a4737..2bdaef9 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 @@ -22,7 +22,13 @@ public record AmountOfSubstance : PhysicalQuantity, T>, /// /// The value in Mole. /// A new instance. - public static AmountOfSubstance FromMole(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AmountOfSubstance FromMole(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two AmountOfSubstance values, returning the absolute difference as a non-negative AmountOfSubstance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AmountOfSubstance operator -(AmountOfSubstance left, AmountOfSubstance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides AmountOfSubstance by Volume to produce Concentration. /// 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 b91e019..6048b4f 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 @@ -22,11 +22,13 @@ public record Angle : PhysicalQuantity, T>, IVector0, T> /// /// The value in Radian. /// A new instance. - public static Angle FromRadian(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Angle FromRadian(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two Angle values, returning a signed SignedAngle result. + /// Subtracts two Angle values, returning the absolute difference as a non-negative Angle. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedAngle operator -(Angle left, Angle right) => SignedAngle.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Angle operator -(Angle left, Angle right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Angle by Duration to produce AngularSpeed. /// 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 85f5c4c..8aa2693 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 @@ -22,11 +22,13 @@ public record AngularAccelerationMagnitude : PhysicalQuantity /// The value in RadiansPerSecondSquared. /// A new instance. - public static AngularAccelerationMagnitude FromRadiansPerSecondSquared(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AngularAccelerationMagnitude FromRadiansPerSecondSquared(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two AngularAccelerationMagnitude values, returning a signed AngularAcceleration1D result. + /// Subtracts two AngularAccelerationMagnitude values, returning the absolute difference as a non-negative AngularAccelerationMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularAcceleration1D operator -(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => AngularAcceleration1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularAccelerationMagnitude operator -(AngularAccelerationMagnitude left, AngularAccelerationMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies AngularAccelerationMagnitude by Duration to produce AngularSpeed. /// 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 1476410..af232d6 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 @@ -22,11 +22,13 @@ public record AngularJerkMagnitude : PhysicalQuantity /// /// The value in RadiansPerSecondCubed. /// A new instance. - public static AngularJerkMagnitude FromRadiansPerSecondCubed(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AngularJerkMagnitude FromRadiansPerSecondCubed(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two AngularJerkMagnitude values, returning a signed AngularJerk1D result. + /// Subtracts two AngularJerkMagnitude values, returning the absolute difference as a non-negative AngularJerkMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularJerk1D operator -(AngularJerkMagnitude left, AngularJerkMagnitude right) => AngularJerk1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularJerkMagnitude operator -(AngularJerkMagnitude left, AngularJerkMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies AngularJerkMagnitude by Duration to produce AngularAccelerationMagnitude. /// 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 812928d..847f6fd 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 @@ -22,11 +22,13 @@ public record AngularMomentumMagnitude : PhysicalQuantity /// The value in KilogramMeterSquaredPerSecond. /// A new instance. - public static AngularMomentumMagnitude FromKilogramMeterSquaredPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AngularMomentumMagnitude FromKilogramMeterSquaredPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two AngularMomentumMagnitude values, returning a signed AngularMomentum1D result. + /// Subtracts two AngularMomentumMagnitude values, returning the absolute difference as a non-negative AngularMomentumMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularMomentum1D operator -(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => AngularMomentum1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularMomentumMagnitude operator -(AngularMomentumMagnitude left, AngularMomentumMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides AngularMomentumMagnitude by Duration to produce TorqueMagnitude. /// 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 9bc4e6c..1178d1a 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 @@ -22,11 +22,13 @@ public record AngularSpeed : PhysicalQuantity, T>, IVector0 /// The value in RadiansPerSecond. /// A new instance. - public static AngularSpeed FromRadiansPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static AngularSpeed FromRadiansPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two AngularSpeed values, returning a signed AngularVelocity1D result. + /// Subtracts two AngularSpeed values, returning the absolute difference as a non-negative AngularSpeed. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularVelocity1D operator -(AngularSpeed left, AngularSpeed right) => AngularVelocity1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AngularSpeed operator -(AngularSpeed left, AngularSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies AngularSpeed by Duration to produce Angle. /// 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 498eb3b..cbbad52 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 @@ -19,14 +19,14 @@ public record ApertureAngle : PhysicalQuantity, T>, IVector0 public static ApertureAngle Zero => Create(T.Zero); /// Creates a new ApertureAngle from a value in Radian. - public static ApertureAngle FromRadian(T value) => Create(value); + public static ApertureAngle FromRadian(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Angle. public static implicit operator Angle(ApertureAngle value) => Angle.Create(value.Value); /// Explicit conversion from Angle. public static explicit operator ApertureAngle(Angle value) => Create(value.Value); /// Creates a ApertureAngle from a Angle value. public static ApertureAngle From(Angle value) => Create(value.Value); -/// Subtracts two ApertureAngle values, returning a signed SignedAngle result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedAngle operator -(ApertureAngle left, ApertureAngle right) => SignedAngle.Create(left.Quantity - right.Quantity); +/// Subtracts two ApertureAngle values, returning the absolute difference as a non-negative ApertureAngle. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ApertureAngle operator -(ApertureAngle left, ApertureAngle right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 fdd30ee..ce261a8 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 @@ -22,7 +22,13 @@ public record Area : PhysicalQuantity, T>, IVector0, T> /// /// The value in SquareMeter. /// A new instance. - public static Area FromSquareMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Area FromSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Area values, returning the absolute difference as a non-negative Area. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Area operator -(Area left, Area right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Area by Length to produce Length. /// 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 4762946..67637d1 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 @@ -19,12 +19,14 @@ public record AtmosphericPressure : PhysicalQuantity, public static AtmosphericPressure Zero => Create(T.Zero); /// Creates a new AtmosphericPressure from a value in Pascal. - public static AtmosphericPressure FromPascal(T value) => Create(value); + public static AtmosphericPressure FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(AtmosphericPressure value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator AtmosphericPressure(Pressure value) => Create(value.Value); /// Creates a AtmosphericPressure from a Pressure value. public static AtmosphericPressure From(Pressure value) => Create(value.Value); +/// Subtracts two AtmosphericPressure values, returning the absolute difference as a non-negative AtmosphericPressure. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AtmosphericPressure operator -(AtmosphericPressure left, AtmosphericPressure right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 ee44d30..5635926 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 @@ -19,12 +19,14 @@ public record AtomicMass : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new AtomicMass from a value in Kilogram. - public static AtomicMass FromKilogram(T value) => Create(value); + public static AtomicMass FromKilogram(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Mass. public static implicit operator Mass(AtomicMass value) => Mass.Create(value.Value); /// Explicit conversion from Mass. public static explicit operator AtomicMass(Mass value) => Create(value.Value); /// Creates a AtomicMass from a Mass value. public static AtomicMass From(Mass value) => Create(value.Value); +/// Subtracts two AtomicMass values, returning the absolute difference as a non-negative AtomicMass. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static AtomicMass operator -(AtomicMass left, AtomicMass right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 235bdcf..231f89c 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 @@ -19,12 +19,14 @@ public record Bandwidth : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Bandwidth from a value in Hertz. - public static Bandwidth FromHertz(T value) => Create(value); + public static Bandwidth FromHertz(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Frequency. public static implicit operator Frequency(Bandwidth value) => Frequency.Create(value.Value); /// Explicit conversion from Frequency. public static explicit operator Bandwidth(Frequency value) => Create(value.Value); /// Creates a Bandwidth from a Frequency value. public static Bandwidth From(Frequency value) => Create(value.Value); +/// Subtracts two Bandwidth values, returning the absolute difference as a non-negative Bandwidth. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Bandwidth operator -(Bandwidth left, Bandwidth right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 63713ac..04a79eb 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 @@ -19,12 +19,14 @@ public record BulkModulus : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new BulkModulus from a value in Pascal. - public static BulkModulus FromPascal(T value) => Create(value); + public static BulkModulus FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(BulkModulus value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator BulkModulus(Pressure value) => Create(value.Value); /// Creates a BulkModulus from a Pressure value. public static BulkModulus From(Pressure value) => Create(value.Value); +/// Subtracts two BulkModulus values, returning the absolute difference as a non-negative BulkModulus. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static BulkModulus operator -(BulkModulus left, BulkModulus right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 8a54208..c92022f 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 @@ -22,7 +22,13 @@ public record Capacitance : PhysicalQuantity, T>, IVector0 /// The value in Farad. /// A new instance. - public static Capacitance FromFarad(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Capacitance FromFarad(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Capacitance values, returning the absolute difference as a non-negative Capacitance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Capacitance operator -(Capacitance left, Capacitance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Capacitance by VoltageMagnitude to produce ChargeMagnitude. /// 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 0f71ad2..50d6035 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 @@ -19,12 +19,14 @@ public record Capacity : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Capacity from a value in CubicMeter. - public static Capacity FromCubicMeter(T value) => Create(value); + public static Capacity FromCubicMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Volume. public static implicit operator Volume(Capacity value) => Volume.Create(value.Value); /// Explicit conversion from Volume. public static explicit operator Capacity(Volume value) => Create(value.Value); /// Creates a Capacity from a Volume value. public static Capacity From(Volume value) => Create(value.Value); +/// Subtracts two Capacity values, returning the absolute difference as a non-negative Capacity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Capacity operator -(Capacity left, Capacity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 b83422d..c820864 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 @@ -22,7 +22,13 @@ public record CatalyticActivity : PhysicalQuantity, T>, /// /// The value in Katal. /// A new instance. - public static CatalyticActivity FromKatal(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static CatalyticActivity FromKatal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two CatalyticActivity values, returning the absolute difference as a non-negative CatalyticActivity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static CatalyticActivity operator -(CatalyticActivity left, CatalyticActivity right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies CatalyticActivity by Duration to produce AmountOfSubstance. /// 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 375a4a5..ac9d67b 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 @@ -22,11 +22,13 @@ public record ChargeMagnitude : PhysicalQuantity, T>, IVec /// /// The value in Coulomb. /// A new instance. - public static ChargeMagnitude FromCoulomb(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ChargeMagnitude FromCoulomb(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two ChargeMagnitude values, returning a signed Charge result. + /// Subtracts two ChargeMagnitude values, returning the absolute difference as a non-negative ChargeMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Charge operator -(ChargeMagnitude left, ChargeMagnitude right) => Charge.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ChargeMagnitude operator -(ChargeMagnitude left, ChargeMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides ChargeMagnitude by Duration to produce CurrentMagnitude. /// 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 49f389d..056c3bc 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 @@ -19,12 +19,14 @@ public record ClockSpeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new ClockSpeed from a value in Hertz. - public static ClockSpeed FromHertz(T value) => Create(value); + public static ClockSpeed FromHertz(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Frequency. public static implicit operator Frequency(ClockSpeed value) => Frequency.Create(value.Value); /// Explicit conversion from Frequency. public static explicit operator ClockSpeed(Frequency value) => Create(value.Value); /// Creates a ClockSpeed from a Frequency value. public static ClockSpeed From(Frequency value) => Create(value.Value); +/// Subtracts two ClockSpeed values, returning the absolute difference as a non-negative ClockSpeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ClockSpeed operator -(ClockSpeed left, ClockSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 2e669be..c6ba074 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 @@ -22,7 +22,13 @@ public record Concentration : PhysicalQuantity, T>, IVector0 /// /// The value in Molar. /// A new instance. - public static Concentration FromMolar(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Concentration FromMolar(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Concentration values, returning the absolute difference as a non-negative Concentration. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Concentration operator -(Concentration left, Concentration right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Concentration by Volume to produce AmountOfSubstance. /// 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 120789c..1868e62 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 @@ -22,7 +22,13 @@ public record Conductance : PhysicalQuantity, T>, IVector0 /// The value in Siemens. /// A new instance. - public static Conductance FromSiemens(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Conductance FromSiemens(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Conductance values, returning the absolute difference as a non-negative Conductance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Conductance operator -(Conductance left, Conductance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Conductance by VoltageMagnitude to produce CurrentMagnitude. /// 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 351c933..8dcab5b 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 @@ -19,12 +19,14 @@ public record CrossSectionalArea : PhysicalQuantity, T> public static CrossSectionalArea Zero => Create(T.Zero); /// Creates a new CrossSectionalArea from a value in SquareMeter. - public static CrossSectionalArea FromSquareMeter(T value) => Create(value); + public static CrossSectionalArea FromSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Area. public static implicit operator Area(CrossSectionalArea value) => Area.Create(value.Value); /// Explicit conversion from Area. public static explicit operator CrossSectionalArea(Area value) => Create(value.Value); /// Creates a CrossSectionalArea from a Area value. public static CrossSectionalArea From(Area value) => Create(value.Value); +/// Subtracts two CrossSectionalArea values, returning the absolute difference as a non-negative CrossSectionalArea. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static CrossSectionalArea operator -(CrossSectionalArea left, CrossSectionalArea right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 34eb520..2e69d94 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 @@ -22,11 +22,13 @@ public record CurrentMagnitude : PhysicalQuantity, T>, IV /// /// The value in Ampere. /// A new instance. - public static CurrentMagnitude FromAmpere(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static CurrentMagnitude FromAmpere(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two CurrentMagnitude values, returning a signed Current1D result. + /// Subtracts two CurrentMagnitude values, returning the absolute difference as a non-negative CurrentMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Current1D operator -(CurrentMagnitude left, CurrentMagnitude right) => Current1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static CurrentMagnitude operator -(CurrentMagnitude left, CurrentMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies CurrentMagnitude by Duration to produce ChargeMagnitude. /// 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 b460698..4a2073f 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 @@ -19,12 +19,14 @@ public record DecayTime : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new DecayTime from a value in Second. - public static DecayTime FromSecond(T value) => Create(value); + public static DecayTime FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(DecayTime value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator DecayTime(Duration value) => Create(value.Value); /// Creates a DecayTime from a Duration value. public static DecayTime From(Duration value) => Create(value.Value); +/// Subtracts two DecayTime values, returning the absolute difference as a non-negative DecayTime. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static DecayTime operator -(DecayTime left, DecayTime right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 6ee2663..cdfc747 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 @@ -22,7 +22,13 @@ public record Density : PhysicalQuantity, T>, IVector0, /// /// The value in KilogramPerCubicMeter. /// A new instance. - public static Density FromKilogramPerCubicMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Density FromKilogramPerCubicMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Density values, returning the absolute difference as a non-negative Density. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Density operator -(Density left, Density right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Density by Volume to produce Mass. /// 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 7314bce..39cc14a 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 @@ -19,14 +19,14 @@ public record Depth : PhysicalQuantity, T>, IVector0, T> public static Depth Zero => Create(T.Zero); /// Creates a new Depth from a value in Meter. - public static Depth FromMeter(T value) => Create(value); + public static Depth FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Depth value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Depth(Length value) => Create(value.Value); /// Creates a Depth from a Length value. public static Depth From(Length value) => Create(value.Value); -/// Subtracts two Depth values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Depth left, Depth right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Depth values, returning the absolute difference as a non-negative Depth. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Depth operator -(Depth left, Depth right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 47b7365..4de680b 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 @@ -19,15 +19,15 @@ public record Diameter : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Diameter from a value in Meter. - public static Diameter FromMeter(T value) => Create(value); + public static Diameter FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Diameter value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Diameter(Length value) => Create(value.Value); /// Creates a Diameter from a Length value. public static Diameter From(Length value) => Create(value.Value); -/// Subtracts two Diameter values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Diameter left, Diameter right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Diameter values, returning the absolute difference as a non-negative Diameter. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Diameter operator -(Diameter left, Diameter right) => Create(T.Abs(left.Quantity - right.Quantity)); /// Converts this Diameter to a Radius. public Radius ToRadius() => Radius.Create(Value / T.CreateChecked(2)); /// Creates a Diameter from a Radius value. 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 0a0ac7b..64fb873 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 @@ -19,14 +19,14 @@ public record Distance : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Distance from a value in Meter. - public static Distance FromMeter(T value) => Create(value); + public static Distance FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Distance value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Distance(Length value) => Create(value.Value); /// Creates a Distance from a Length value. public static Distance From(Length value) => Create(value.Value); -/// Subtracts two Distance values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Distance left, Distance right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Distance values, returning the absolute difference as a non-negative Distance. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Distance operator -(Distance left, Distance right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 66b55d4..7fd0cc9 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 @@ -19,14 +19,14 @@ public record Drag : PhysicalQuantity, T>, IVector0, T> public static Drag Zero => Create(T.Zero); /// Creates a new Drag from a value in Newton. - public static Drag FromNewton(T value) => Create(value); + public static Drag FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Drag value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Drag(ForceMagnitude value) => Create(value.Value); /// Creates a Drag from a ForceMagnitude value. public static Drag From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Drag values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Drag left, Drag right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Drag values, returning the absolute difference as a non-negative Drag. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Drag operator -(Drag left, Drag right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 fb3bbb3..19d625e 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 @@ -22,7 +22,13 @@ public record Duration : PhysicalQuantity, T>, IVector0 /// The value in Second. /// A new instance. - public static Duration FromSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Duration FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Duration values, returning the absolute difference as a non-negative Duration. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Duration operator -(Duration left, Duration right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Duration by CurrentMagnitude to produce ChargeMagnitude. /// 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 96a41fa..3cc9c30 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 @@ -22,7 +22,13 @@ public record DynamicViscosity : PhysicalQuantity, T>, IV /// /// The value in PascalSecond. /// A new instance. - public static DynamicViscosity FromPascalSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static DynamicViscosity FromPascalSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two DynamicViscosity values, returning the absolute difference as a non-negative DynamicViscosity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static DynamicViscosity operator -(DynamicViscosity left, DynamicViscosity right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides DynamicViscosity by Density to produce KinematicViscosity. /// 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 7507a65..524de20 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 @@ -19,14 +19,14 @@ public record EMF : PhysicalQuantity, T>, IVector0, T> public static EMF Zero => Create(T.Zero); /// Creates a new EMF from a value in Volt. - public static EMF FromVolt(T value) => Create(value); + public static EMF FromVolt(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to VoltageMagnitude. public static implicit operator VoltageMagnitude(EMF value) => VoltageMagnitude.Create(value.Value); /// Explicit conversion from VoltageMagnitude. public static explicit operator EMF(VoltageMagnitude value) => Create(value.Value); /// Creates a EMF from a VoltageMagnitude value. public static EMF From(VoltageMagnitude value) => Create(value.Value); -/// Subtracts two EMF values, returning a signed Voltage result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Voltage operator -(EMF left, EMF right) => Voltage.Create(left.Quantity - right.Quantity); +/// Subtracts two EMF values, returning the absolute difference as a non-negative EMF. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static EMF operator -(EMF left, EMF right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 8c15f0a..6497f9c 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 @@ -22,11 +22,13 @@ public record ElectricFieldMagnitude : PhysicalQuantity /// The value in VoltPerMeter. /// A new instance. - public static ElectricFieldMagnitude FromVoltPerMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ElectricFieldMagnitude FromVoltPerMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two ElectricFieldMagnitude values, returning a signed ElectricField1D result. + /// Subtracts two ElectricFieldMagnitude values, returning the absolute difference as a non-negative ElectricFieldMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ElectricField1D operator -(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => ElectricField1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ElectricFieldMagnitude operator -(ElectricFieldMagnitude left, ElectricFieldMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies ElectricFieldMagnitude by Length to produce VoltageMagnitude. /// 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 9b737ef..720f42d 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 @@ -22,7 +22,13 @@ public record Energy : PhysicalQuantity, T>, IVector0, T> /// /// The value in Joule. /// A new instance. - public static Energy FromJoule(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Energy FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Energy values, returning the absolute difference as a non-negative Energy. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Energy operator -(Energy left, Energy right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Energy by Angle to produce TorqueMagnitude. /// 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 bf2d406..2dcf6d9 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 @@ -19,12 +19,14 @@ public record EnergyFluxDensity : PhysicalQuantity, T>, public static EnergyFluxDensity Zero => Create(T.Zero); /// Creates a new EnergyFluxDensity from a value in WattPerSquareMeter. - public static EnergyFluxDensity FromWattPerSquareMeter(T value) => Create(value); + public static EnergyFluxDensity FromWattPerSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Irradiance. public static implicit operator Irradiance(EnergyFluxDensity value) => Irradiance.Create(value.Value); /// Explicit conversion from Irradiance. public static explicit operator EnergyFluxDensity(Irradiance value) => Create(value.Value); /// Creates a EnergyFluxDensity from a Irradiance value. public static EnergyFluxDensity From(Irradiance value) => Create(value.Value); +/// Subtracts two EnergyFluxDensity values, returning the absolute difference as a non-negative EnergyFluxDensity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static EnergyFluxDensity operator -(EnergyFluxDensity left, EnergyFluxDensity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 18b2523..a74acf2 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 @@ -22,7 +22,13 @@ public record Entropy : PhysicalQuantity, T>, IVector0, /// /// The value in JoulePerKelvin. /// A new instance. - public static Entropy FromJoulePerKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Entropy FromJoulePerKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Entropy values, returning the absolute difference as a non-negative Entropy. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Entropy operator -(Entropy left, Entropy right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Entropy by Temperature to produce Energy. /// 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 8649f07..390fc5e 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 @@ -19,12 +19,14 @@ public record EnzymeActivity : PhysicalQuantity, T>, IVecto public static EnzymeActivity Zero => Create(T.Zero); /// Creates a new EnzymeActivity from a value in Katal. - public static EnzymeActivity FromKatal(T value) => Create(value); + public static EnzymeActivity FromKatal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to CatalyticActivity. public static implicit operator CatalyticActivity(EnzymeActivity value) => CatalyticActivity.Create(value.Value); /// Explicit conversion from CatalyticActivity. public static explicit operator EnzymeActivity(CatalyticActivity value) => Create(value.Value); /// Creates a EnzymeActivity from a CatalyticActivity value. public static EnzymeActivity From(CatalyticActivity value) => Create(value.Value); +/// Subtracts two EnzymeActivity values, returning the absolute difference as a non-negative EnzymeActivity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static EnzymeActivity operator -(EnzymeActivity left, EnzymeActivity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 2bf717f..7375ff9 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 @@ -22,6 +22,12 @@ public record EquivalentDose : PhysicalQuantity, T>, IVecto /// /// The value in Sievert. /// A new instance. - public static EquivalentDose FromSievert(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static EquivalentDose FromSievert(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two EquivalentDose values, returning the absolute difference as a non-negative EquivalentDose. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static EquivalentDose operator -(EquivalentDose left, EquivalentDose right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 44a5251..bb594b4 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 @@ -22,6 +22,12 @@ public record Exposure : PhysicalQuantity, T>, IVector0 /// The value in CoulombPerKilogram. /// A new instance. - public static Exposure FromCoulombPerKilogram(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Exposure FromCoulombPerKilogram(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Exposure values, returning the absolute difference as a non-negative Exposure. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Exposure operator -(Exposure left, Exposure right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 75b5dba..21c9502 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 @@ -19,14 +19,14 @@ public record FieldOfView : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new FieldOfView from a value in Radian. - public static FieldOfView FromRadian(T value) => Create(value); + public static FieldOfView FromRadian(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Angle. public static implicit operator Angle(FieldOfView value) => Angle.Create(value.Value); /// Explicit conversion from Angle. public static explicit operator FieldOfView(Angle value) => Create(value.Value); /// Creates a FieldOfView from a Angle value. public static FieldOfView From(Angle value) => Create(value.Value); -/// Subtracts two FieldOfView values, returning a signed SignedAngle result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedAngle operator -(FieldOfView left, FieldOfView right) => SignedAngle.Create(left.Quantity - right.Quantity); +/// Subtracts two FieldOfView values, returning the absolute difference as a non-negative FieldOfView. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static FieldOfView operator -(FieldOfView left, FieldOfView right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 d6708ee..61e996f 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 @@ -19,14 +19,14 @@ public record FlowSpeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new FlowSpeed from a value in MetersPerSecond. - public static FlowSpeed FromMetersPerSecond(T value) => Create(value); + public static FlowSpeed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(FlowSpeed value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator FlowSpeed(Speed value) => Create(value.Value); /// Creates a FlowSpeed from a Speed value. public static FlowSpeed From(Speed value) => Create(value.Value); -/// Subtracts two FlowSpeed values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(FlowSpeed left, FlowSpeed right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two FlowSpeed values, returning the absolute difference as a non-negative FlowSpeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static FlowSpeed operator -(FlowSpeed left, FlowSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 ce7d431..a46a1d4 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 @@ -22,11 +22,13 @@ public record ForceMagnitude : PhysicalQuantity, T>, IVecto /// /// The value in Newton. /// A new instance. - public static ForceMagnitude FromNewton(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ForceMagnitude FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two ForceMagnitude values, returning a signed Force1D result. + /// Subtracts two ForceMagnitude values, returning the absolute difference as a non-negative ForceMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(ForceMagnitude left, ForceMagnitude right) => Force1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ForceMagnitude operator -(ForceMagnitude left, ForceMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides ForceMagnitude by AccelerationMagnitude to produce Mass. /// 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 01d5975..54878d6 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 @@ -22,7 +22,13 @@ public record Frequency : PhysicalQuantity, T>, IVector0 /// The value in Hertz. /// A new instance. - public static Frequency FromHertz(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Frequency FromHertz(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Frequency values, returning the absolute difference as a non-negative Frequency. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Frequency operator -(Frequency left, Frequency right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Frequency by Duration to produce Ratio. /// 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 6371816..342cd1d 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 @@ -19,14 +19,14 @@ public record Friction : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Friction from a value in Newton. - public static Friction FromNewton(T value) => Create(value); + public static Friction FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Friction value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Friction(ForceMagnitude value) => Create(value.Value); /// Creates a Friction from a ForceMagnitude value. public static Friction From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Friction values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Friction left, Friction right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Friction values, returning the absolute difference as a non-negative Friction. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Friction operator -(Friction left, Friction right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 00bee5f..e08975c 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 @@ -19,12 +19,14 @@ public record GaugePressure : PhysicalQuantity, T>, IVector0 public static GaugePressure Zero => Create(T.Zero); /// Creates a new GaugePressure from a value in Pascal. - public static GaugePressure FromPascal(T value) => Create(value); + public static GaugePressure FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(GaugePressure value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator GaugePressure(Pressure value) => Create(value.Value); /// Creates a GaugePressure from a Pressure value. public static GaugePressure From(Pressure value) => Create(value.Value); +/// Subtracts two GaugePressure values, returning the absolute difference as a non-negative GaugePressure. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static GaugePressure operator -(GaugePressure left, GaugePressure right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 734c705..315eb9e 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 @@ -19,14 +19,14 @@ public record GravitationalAcceleration : PhysicalQuantity Zero => Create(T.Zero); /// Creates a new GravitationalAcceleration from a value in MetersPerSecondSquared. - public static GravitationalAcceleration FromMetersPerSecondSquared(T value) => Create(value); + public static GravitationalAcceleration FromMetersPerSecondSquared(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to AccelerationMagnitude. public static implicit operator AccelerationMagnitude(GravitationalAcceleration value) => AccelerationMagnitude.Create(value.Value); /// Explicit conversion from AccelerationMagnitude. public static explicit operator GravitationalAcceleration(AccelerationMagnitude value) => Create(value.Value); /// Creates a GravitationalAcceleration from a AccelerationMagnitude value. public static GravitationalAcceleration From(AccelerationMagnitude value) => Create(value.Value); -/// Subtracts two GravitationalAcceleration values, returning a signed Acceleration1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Acceleration1D operator -(GravitationalAcceleration left, GravitationalAcceleration right) => Acceleration1D.Create(left.Quantity - right.Quantity); +/// Subtracts two GravitationalAcceleration values, returning the absolute difference as a non-negative GravitationalAcceleration. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static GravitationalAcceleration operator -(GravitationalAcceleration left, GravitationalAcceleration right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 255c20b..41b950c 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 @@ -19,14 +19,14 @@ public record GroundSpeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new GroundSpeed from a value in MetersPerSecond. - public static GroundSpeed FromMetersPerSecond(T value) => Create(value); + public static GroundSpeed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(GroundSpeed value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator GroundSpeed(Speed value) => Create(value.Value); /// Creates a GroundSpeed from a Speed value. public static GroundSpeed From(Speed value) => Create(value.Value); -/// Subtracts two GroundSpeed values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(GroundSpeed left, GroundSpeed right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two GroundSpeed values, returning the absolute difference as a non-negative GroundSpeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static GroundSpeed operator -(GroundSpeed left, GroundSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 605a667..17eb76c 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 @@ -19,14 +19,14 @@ public record GroupVelocity : PhysicalQuantity, T>, IVector0 public static GroupVelocity Zero => Create(T.Zero); /// Creates a new GroupVelocity from a value in MetersPerSecond. - public static GroupVelocity FromMetersPerSecond(T value) => Create(value); + public static GroupVelocity FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(GroupVelocity value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator GroupVelocity(Speed value) => Create(value.Value); /// Creates a GroupVelocity from a Speed value. public static GroupVelocity From(Speed value) => Create(value.Value); -/// Subtracts two GroupVelocity values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(GroupVelocity left, GroupVelocity right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two GroupVelocity values, returning the absolute difference as a non-negative GroupVelocity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static GroupVelocity operator -(GroupVelocity left, GroupVelocity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 b3adf5d..50e76ba 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 @@ -19,12 +19,14 @@ public record HalfLife : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new HalfLife from a value in Second. - public static HalfLife FromSecond(T value) => Create(value); + public static HalfLife FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(HalfLife value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator HalfLife(Duration value) => Create(value.Value); /// Creates a HalfLife from a Duration value. public static HalfLife From(Duration value) => Create(value.Value); +/// Subtracts two HalfLife values, returning the absolute difference as a non-negative HalfLife. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static HalfLife operator -(HalfLife left, HalfLife right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 769c6ec..a221abb 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 @@ -19,12 +19,14 @@ public record Heat : PhysicalQuantity, T>, IVector0, T> public static Heat Zero => Create(T.Zero); /// Creates a new Heat from a value in Joule. - public static Heat FromJoule(T value) => Create(value); + public static Heat FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Energy. public static implicit operator Energy(Heat value) => Energy.Create(value.Value); /// Explicit conversion from Energy. public static explicit operator Heat(Energy value) => Create(value.Value); /// Creates a Heat from a Energy value. public static Heat From(Energy value) => Create(value.Value); +/// Subtracts two Heat values, returning the absolute difference as a non-negative Heat. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Heat operator -(Heat left, Heat right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 50a68a4..6148b27 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 @@ -19,12 +19,14 @@ public record HeatCapacity : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new HeatCapacity from a value in JoulePerKelvin. - public static HeatCapacity FromJoulePerKelvin(T value) => Create(value); + public static HeatCapacity FromJoulePerKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Entropy. public static implicit operator Entropy(HeatCapacity value) => Entropy.Create(value.Value); /// Explicit conversion from Entropy. public static explicit operator HeatCapacity(Entropy value) => Create(value.Value); /// Creates a HeatCapacity from a Entropy value. public static HeatCapacity From(Entropy value) => Create(value.Value); +/// Subtracts two HeatCapacity values, returning the absolute difference as a non-negative HeatCapacity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static HeatCapacity operator -(HeatCapacity left, HeatCapacity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 b4f230d..8cd3da2 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 @@ -19,12 +19,14 @@ public record HeatFlowRate : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new HeatFlowRate from a value in Watt. - public static HeatFlowRate FromWatt(T value) => Create(value); + public static HeatFlowRate FromWatt(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Power. public static implicit operator Power(HeatFlowRate value) => Power.Create(value.Value); /// Explicit conversion from Power. public static explicit operator HeatFlowRate(Power value) => Create(value.Value); /// Creates a HeatFlowRate from a Power value. public static HeatFlowRate From(Power value) => Create(value.Value); +/// Subtracts two HeatFlowRate values, returning the absolute difference as a non-negative HeatFlowRate. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static HeatFlowRate operator -(HeatFlowRate left, HeatFlowRate right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 7103c45..a63b4aa 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 @@ -19,12 +19,14 @@ public record HeatFlux : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new HeatFlux from a value in WattPerSquareMeter. - public static HeatFlux FromWattPerSquareMeter(T value) => Create(value); + public static HeatFlux FromWattPerSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Irradiance. public static implicit operator Irradiance(HeatFlux value) => Irradiance.Create(value.Value); /// Explicit conversion from Irradiance. public static explicit operator HeatFlux(Irradiance value) => Create(value.Value); /// Creates a HeatFlux from a Irradiance value. public static HeatFlux From(Irradiance value) => Create(value.Value); +/// Subtracts two HeatFlux values, returning the absolute difference as a non-negative HeatFlux. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static HeatFlux operator -(HeatFlux left, HeatFlux right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 12adf69..bc39731 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 @@ -22,6 +22,12 @@ public record HeatTransferCoefficient : PhysicalQuantity /// The value in WattPerSquareMeterKelvin. /// A new instance. - public static HeatTransferCoefficient FromWattPerSquareMeterKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static HeatTransferCoefficient FromWattPerSquareMeterKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two HeatTransferCoefficient values, returning the absolute difference as a non-negative HeatTransferCoefficient. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static HeatTransferCoefficient operator -(HeatTransferCoefficient left, HeatTransferCoefficient right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 94acf72..3c69ea0 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 @@ -19,14 +19,14 @@ public record Height : PhysicalQuantity, T>, IVector0, T> public static Height Zero => Create(T.Zero); /// Creates a new Height from a value in Meter. - public static Height FromMeter(T value) => Create(value); + public static Height FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Height value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Height(Length value) => Create(value.Value); /// Creates a Height from a Length value. public static Height From(Length value) => Create(value.Value); -/// Subtracts two Height values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Height left, Height right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Height values, returning the absolute difference as a non-negative Height. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Height operator -(Height left, Height right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 ee13704..1822a7a 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 @@ -22,7 +22,13 @@ public record Illuminance : PhysicalQuantity, T>, IVector0 /// The value in Lux. /// A new instance. - public static Illuminance FromLux(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Illuminance FromLux(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Illuminance values, returning the absolute difference as a non-negative Illuminance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Illuminance operator -(Illuminance left, Illuminance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Illuminance by Area to produce LuminousFlux. /// 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 237bdee..541b0f7 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 @@ -22,7 +22,13 @@ public record Inductance : PhysicalQuantity, T>, IVector0 /// The value in Henry. /// A new instance. - public static Inductance FromHenry(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Inductance FromHenry(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Inductance values, returning the absolute difference as a non-negative Inductance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Inductance operator -(Inductance left, Inductance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Inductance by CurrentMagnitude to produce MagneticFlux. /// 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 533c9ff..68de849 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 @@ -22,7 +22,13 @@ public record Irradiance : PhysicalQuantity, T>, IVector0 /// The value in WattPerSquareMeter. /// A new instance. - public static Irradiance FromWattPerSquareMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Irradiance FromWattPerSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Irradiance values, returning the absolute difference as a non-negative Irradiance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Irradiance operator -(Irradiance left, Irradiance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Irradiance by Area to produce Power. /// 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 08e6c2f..7919a44 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 @@ -22,11 +22,13 @@ public record JerkMagnitude : PhysicalQuantity, T>, IVector0 /// /// The value in MetersPerSecondCubed. /// A new instance. - public static JerkMagnitude FromMetersPerSecondCubed(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static JerkMagnitude FromMetersPerSecondCubed(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two JerkMagnitude values, returning a signed Jerk1D result. + /// Subtracts two JerkMagnitude values, returning the absolute difference as a non-negative JerkMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Jerk1D operator -(JerkMagnitude left, JerkMagnitude right) => Jerk1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static JerkMagnitude operator -(JerkMagnitude left, JerkMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies JerkMagnitude by Duration to produce AccelerationMagnitude. /// 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 0fe7348..23dc9a5 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 @@ -22,7 +22,13 @@ public record KinematicViscosity : PhysicalQuantity, T> /// /// The value in SquareMeterPerSecond. /// A new instance. - public static KinematicViscosity FromSquareMeterPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static KinematicViscosity FromSquareMeterPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two KinematicViscosity values, returning the absolute difference as a non-negative KinematicViscosity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static KinematicViscosity operator -(KinematicViscosity left, KinematicViscosity right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies KinematicViscosity by Density to produce DynamicViscosity. /// 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 ab8285d..0f72c31 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 @@ -19,12 +19,14 @@ public record KineticEnergy : PhysicalQuantity, T>, IVector0 public static KineticEnergy Zero => Create(T.Zero); /// Creates a new KineticEnergy from a value in Joule. - public static KineticEnergy FromJoule(T value) => Create(value); + public static KineticEnergy FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Energy. public static implicit operator Energy(KineticEnergy value) => Energy.Create(value.Value); /// Explicit conversion from Energy. public static explicit operator KineticEnergy(Energy value) => Create(value.Value); /// Creates a KineticEnergy from a Energy value. public static KineticEnergy From(Energy value) => Create(value.Value); +/// Subtracts two KineticEnergy values, returning the absolute difference as a non-negative KineticEnergy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static KineticEnergy operator -(KineticEnergy left, KineticEnergy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 e81f507..135a894 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 @@ -19,12 +19,14 @@ public record Latency : PhysicalQuantity, T>, IVector0, public static Latency Zero => Create(T.Zero); /// Creates a new Latency from a value in Second. - public static Latency FromSecond(T value) => Create(value); + public static Latency FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(Latency value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator Latency(Duration value) => Create(value.Value); /// Creates a Latency from a Duration value. public static Latency From(Duration value) => Create(value.Value); +/// Subtracts two Latency values, returning the absolute difference as a non-negative Latency. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Latency operator -(Latency left, Latency right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 7539b88..947a676 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 @@ -22,11 +22,13 @@ public record Length : PhysicalQuantity, T>, IVector0, T> /// /// The value in Meter. /// A new instance. - public static Length FromMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Length FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two Length values, returning a signed Displacement1D result. + /// Subtracts two Length values, returning the absolute difference as a non-negative Length. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Length left, Length right) => Displacement1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Length operator -(Length left, Length right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Length by Length to produce Area. /// 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 d188cc8..73d0e78 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 @@ -19,14 +19,14 @@ public record Lift : PhysicalQuantity, T>, IVector0, T> public static Lift Zero => Create(T.Zero); /// Creates a new Lift from a value in Newton. - public static Lift FromNewton(T value) => Create(value); + public static Lift FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Lift value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Lift(ForceMagnitude value) => Create(value.Value); /// Creates a Lift from a ForceMagnitude value. public static Lift From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Lift values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Lift left, Lift right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Lift values, returning the absolute difference as a non-negative Lift. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Lift operator -(Lift left, Lift right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 6c006ab..56910cf 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 @@ -19,12 +19,14 @@ public record Luminance : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Luminance from a value in Lux. - public static Luminance FromLux(T value) => Create(value); + public static Luminance FromLux(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Illuminance. public static implicit operator Illuminance(Luminance value) => Illuminance.Create(value.Value); /// Explicit conversion from Illuminance. public static explicit operator Luminance(Illuminance value) => Create(value.Value); /// Creates a Luminance from a Illuminance value. public static Luminance From(Illuminance value) => Create(value.Value); +/// Subtracts two Luminance values, returning the absolute difference as a non-negative Luminance. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Luminance operator -(Luminance left, Luminance right) => Create(T.Abs(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 9cb99ca..07fd68e 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 @@ -22,7 +22,13 @@ public record LuminousFlux : PhysicalQuantity, T>, IVector0 /// The value in Lumen. /// A new instance. - public static LuminousFlux FromLumen(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static LuminousFlux FromLumen(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two LuminousFlux values, returning the absolute difference as a non-negative LuminousFlux. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static LuminousFlux operator -(LuminousFlux left, LuminousFlux right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides LuminousFlux by Area to produce Illuminance. /// 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 ca269b4..e093a3a 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 @@ -22,6 +22,12 @@ public record LuminousIntensity : PhysicalQuantity, T>, /// /// The value in Candela. /// A new instance. - public static LuminousIntensity FromCandela(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static LuminousIntensity FromCandela(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two LuminousIntensity values, returning the absolute difference as a non-negative LuminousIntensity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static LuminousIntensity operator -(LuminousIntensity left, LuminousIntensity right) => Create(T.Abs(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 1263d68..fd81419 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 @@ -19,14 +19,14 @@ public record MachNumber : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new MachNumber from a value in Dimensionless. - public static MachNumber FromDimensionless(T value) => Create(value); + public static MachNumber FromDimensionless(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Ratio. public static implicit operator Ratio(MachNumber value) => Ratio.Create(value.Value); /// Explicit conversion from Ratio. public static explicit operator MachNumber(Ratio value) => Create(value.Value); /// Creates a MachNumber from a Ratio value. public static MachNumber From(Ratio value) => Create(value.Value); -/// Subtracts two MachNumber values, returning a signed SignedRatio result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedRatio operator -(MachNumber left, MachNumber right) => SignedRatio.Create(left.Quantity - right.Quantity); +/// Subtracts two MachNumber values, returning the absolute difference as a non-negative MachNumber. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MachNumber operator -(MachNumber left, MachNumber right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 e2a89d1..32a30c9 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 @@ -22,7 +22,13 @@ public record MagneticFlux : PhysicalQuantity, T>, IVector0 /// The value in Weber. /// A new instance. - public static MagneticFlux FromWeber(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MagneticFlux FromWeber(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MagneticFlux values, returning the absolute difference as a non-negative MagneticFlux. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MagneticFlux operator -(MagneticFlux left, MagneticFlux right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides MagneticFlux by Area to produce MagneticFluxDensityMagnitude. /// 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 503c9a9..1c7f720 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 @@ -22,7 +22,13 @@ public record MagneticFluxDensityMagnitude : PhysicalQuantity /// The value in Tesla. /// A new instance. - public static MagneticFluxDensityMagnitude FromTesla(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MagneticFluxDensityMagnitude FromTesla(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MagneticFluxDensityMagnitude values, returning the absolute difference as a non-negative MagneticFluxDensityMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MagneticFluxDensityMagnitude operator -(MagneticFluxDensityMagnitude left, MagneticFluxDensityMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies MagneticFluxDensityMagnitude by Area to produce MagneticFlux. /// 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 2a07e48..d729700 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 @@ -22,7 +22,13 @@ public record Mass : PhysicalQuantity, T>, IVector0, T> /// /// The value in Kilogram. /// A new instance. - public static Mass FromKilogram(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Mass FromKilogram(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Mass values, returning the absolute difference as a non-negative Mass. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Mass operator -(Mass left, Mass right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Mass by AccelerationMagnitude to produce ForceMagnitude. /// 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 44c23d3..19bdd90 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 @@ -22,7 +22,13 @@ public record MassFlowRate : PhysicalQuantity, T>, IVector0 /// The value in KilogramPerSecond. /// A new instance. - public static MassFlowRate FromKilogramPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MassFlowRate FromKilogramPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MassFlowRate values, returning the absolute difference as a non-negative MassFlowRate. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MassFlowRate operator -(MassFlowRate left, MassFlowRate right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies MassFlowRate by Duration to produce Mass. /// 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 9931537..b14d41a 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 @@ -22,7 +22,13 @@ public record MolarEnergy : PhysicalQuantity, T>, IVector0 /// The value in JoulePerMole. /// A new instance. - public static MolarEnergy FromJoulePerMole(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MolarEnergy FromJoulePerMole(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MolarEnergy values, returning the absolute difference as a non-negative MolarEnergy. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MolarEnergy operator -(MolarEnergy left, MolarEnergy right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies MolarEnergy by AmountOfSubstance to produce Energy. /// 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 80fb5c8..abf48cd 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 @@ -19,12 +19,14 @@ public record MolarEnthalpy : PhysicalQuantity, T>, IVector0 public static MolarEnthalpy Zero => Create(T.Zero); /// Creates a new MolarEnthalpy from a value in JoulePerMole. - public static MolarEnthalpy FromJoulePerMole(T value) => Create(value); + public static MolarEnthalpy FromJoulePerMole(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to MolarEnergy. public static implicit operator MolarEnergy(MolarEnthalpy value) => MolarEnergy.Create(value.Value); /// Explicit conversion from MolarEnergy. public static explicit operator MolarEnthalpy(MolarEnergy value) => Create(value.Value); /// Creates a MolarEnthalpy from a MolarEnergy value. public static MolarEnthalpy From(MolarEnergy value) => Create(value.Value); +/// Subtracts two MolarEnthalpy values, returning the absolute difference as a non-negative MolarEnthalpy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MolarEnthalpy operator -(MolarEnthalpy left, MolarEnthalpy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 64b5052..334fc43 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 @@ -22,7 +22,13 @@ public record MolarMass : PhysicalQuantity, T>, IVector0 /// The value in KilogramPerMole. /// A new instance. - public static MolarMass FromKilogramPerMole(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MolarMass FromKilogramPerMole(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MolarMass values, returning the absolute difference as a non-negative MolarMass. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MolarMass operator -(MolarMass left, MolarMass right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies MolarMass by AmountOfSubstance to produce Mass. /// 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 06fd5df..231864f 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 @@ -22,7 +22,13 @@ public record MomentOfInertia : PhysicalQuantity, T>, IVec /// /// The value in KilogramMeterSquared. /// A new instance. - public static MomentOfInertia FromKilogramMeterSquared(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MomentOfInertia FromKilogramMeterSquared(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two MomentOfInertia values, returning the absolute difference as a non-negative MomentOfInertia. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MomentOfInertia operator -(MomentOfInertia left, MomentOfInertia right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies MomentOfInertia by AngularSpeed to produce AngularMomentumMagnitude. /// 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 f8cee62..7ccd5de 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 @@ -22,11 +22,13 @@ public record MomentumMagnitude : PhysicalQuantity, T>, /// /// The value in NewtonSecond. /// A new instance. - public static MomentumMagnitude FromNewtonSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static MomentumMagnitude FromNewtonSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two MomentumMagnitude values, returning a signed Momentum1D result. + /// Subtracts two MomentumMagnitude values, returning the absolute difference as a non-negative MomentumMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Momentum1D operator -(MomentumMagnitude left, MomentumMagnitude right) => Momentum1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static MomentumMagnitude operator -(MomentumMagnitude left, MomentumMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides MomentumMagnitude by Speed to produce Mass. /// 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 8882414..c88cb39 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 @@ -19,14 +19,14 @@ public record NormalForce : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new NormalForce from a value in Newton. - public static NormalForce FromNewton(T value) => Create(value); + public static NormalForce FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(NormalForce value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator NormalForce(ForceMagnitude value) => Create(value.Value); /// Creates a NormalForce from a ForceMagnitude value. public static NormalForce From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two NormalForce values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(NormalForce left, NormalForce right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two NormalForce values, returning the absolute difference as a non-negative NormalForce. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static NormalForce operator -(NormalForce left, NormalForce right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 61684c7..875e493 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 @@ -22,6 +22,12 @@ public record NuclearCrossSection : PhysicalQuantity, /// /// The value in Barn. /// A new instance. - public static NuclearCrossSection FromBarn(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static NuclearCrossSection FromBarn(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two NuclearCrossSection values, returning the absolute difference as a non-negative NuclearCrossSection. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static NuclearCrossSection operator -(NuclearCrossSection left, NuclearCrossSection right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 a81a0d4..9b25a8d 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 @@ -22,6 +22,12 @@ public record OpticalPower : PhysicalQuantity, T>, IVector0 /// The value in Diopter. /// A new instance. - public static OpticalPower FromDiopter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static OpticalPower FromDiopter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two OpticalPower values, returning the absolute difference as a non-negative OpticalPower. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static OpticalPower operator -(OpticalPower left, OpticalPower right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 90c186e..5ecfc7c 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 @@ -19,14 +19,14 @@ public record Perimeter : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Perimeter from a value in Meter. - public static Perimeter FromMeter(T value) => Create(value); + public static Perimeter FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Perimeter value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Perimeter(Length value) => Create(value.Value); /// Creates a Perimeter from a Length value. public static Perimeter From(Length value) => Create(value.Value); -/// Subtracts two Perimeter values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Perimeter left, Perimeter right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Perimeter values, returning the absolute difference as a non-negative Perimeter. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Perimeter operator -(Perimeter left, Perimeter right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 1a9a03d..3087f9a 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 @@ -19,12 +19,14 @@ public record Period : PhysicalQuantity, T>, IVector0, T> public static Period Zero => Create(T.Zero); /// Creates a new Period from a value in Second. - public static Period FromSecond(T value) => Create(value); + public static Period FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(Period value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator Period(Duration value) => Create(value.Value); /// Creates a Period from a Duration value. public static Period From(Duration value) => Create(value.Value); +/// Subtracts two Period values, returning the absolute difference as a non-negative Period. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Period operator -(Period left, Period right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 73fbf83..54e774c 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 @@ -19,14 +19,14 @@ public record PhaseVelocity : PhysicalQuantity, T>, IVector0 public static PhaseVelocity Zero => Create(T.Zero); /// Creates a new PhaseVelocity from a value in MetersPerSecond. - public static PhaseVelocity FromMetersPerSecond(T value) => Create(value); + public static PhaseVelocity FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(PhaseVelocity value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator PhaseVelocity(Speed value) => Create(value.Value); /// Creates a PhaseVelocity from a Speed value. public static PhaseVelocity From(Speed value) => Create(value.Value); -/// Subtracts two PhaseVelocity values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(PhaseVelocity left, PhaseVelocity right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two PhaseVelocity values, returning the absolute difference as a non-negative PhaseVelocity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static PhaseVelocity operator -(PhaseVelocity left, PhaseVelocity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 6c72987..a6326a2 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 @@ -19,12 +19,14 @@ public record Pitch : PhysicalQuantity, T>, IVector0, T> public static Pitch Zero => Create(T.Zero); /// Creates a new Pitch from a value in Hertz. - public static Pitch FromHertz(T value) => Create(value); + public static Pitch FromHertz(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Frequency. public static implicit operator Frequency(Pitch value) => Frequency.Create(value.Value); /// Explicit conversion from Frequency. public static explicit operator Pitch(Frequency value) => Create(value.Value); /// Creates a Pitch from a Frequency value. public static Pitch From(Frequency value) => Create(value.Value); +/// Subtracts two Pitch values, returning the absolute difference as a non-negative Pitch. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Pitch operator -(Pitch left, Pitch right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 e9148e6..de99fcd 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 @@ -19,12 +19,14 @@ public record PotentialEnergy : PhysicalQuantity, T>, IVec public static PotentialEnergy Zero => Create(T.Zero); /// Creates a new PotentialEnergy from a value in Joule. - public static PotentialEnergy FromJoule(T value) => Create(value); + public static PotentialEnergy FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Energy. public static implicit operator Energy(PotentialEnergy value) => Energy.Create(value.Value); /// Explicit conversion from Energy. public static explicit operator PotentialEnergy(Energy value) => Create(value.Value); /// Creates a PotentialEnergy from a Energy value. public static PotentialEnergy From(Energy value) => Create(value.Value); +/// Subtracts two PotentialEnergy values, returning the absolute difference as a non-negative PotentialEnergy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static PotentialEnergy operator -(PotentialEnergy left, PotentialEnergy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 9066447..01b2925 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 @@ -22,7 +22,13 @@ public record Power : PhysicalQuantity, T>, IVector0, T> /// /// The value in Watt. /// A new instance. - public static Power FromWatt(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Power FromWatt(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Power values, returning the absolute difference as a non-negative Power. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Power operator -(Power left, Power right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Power by VoltageMagnitude to produce CurrentMagnitude. /// 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 3a44d62..ad3a1f1 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 @@ -22,7 +22,13 @@ public record Pressure : PhysicalQuantity, T>, IVector0 /// The value in Pascal. /// A new instance. - public static Pressure FromPascal(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Pressure FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Pressure values, returning the absolute difference as a non-negative Pressure. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Pressure operator -(Pressure left, Pressure right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Pressure by Area to produce ForceMagnitude. /// 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 f7176e2..fe5d715 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 @@ -22,6 +22,12 @@ public record RadioactiveActivity : PhysicalQuantity, /// /// The value in Becquerel. /// A new instance. - public static RadioactiveActivity FromBecquerel(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static RadioactiveActivity FromBecquerel(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two RadioactiveActivity values, returning the absolute difference as a non-negative RadioactiveActivity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static RadioactiveActivity operator -(RadioactiveActivity left, RadioactiveActivity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 4507335..e783867 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 @@ -19,14 +19,14 @@ public record Radius : PhysicalQuantity, T>, IVector0, T> public static Radius Zero => Create(T.Zero); /// Creates a new Radius from a value in Meter. - public static Radius FromMeter(T value) => Create(value); + public static Radius FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Radius value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Radius(Length value) => Create(value.Value); /// Creates a Radius from a Length value. public static Radius From(Length value) => Create(value.Value); -/// Subtracts two Radius values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Radius left, Radius right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Radius values, returning the absolute difference as a non-negative Radius. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Radius operator -(Radius left, Radius right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 d16ffa6..a1efe70 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 @@ -22,11 +22,13 @@ public record Ratio : PhysicalQuantity, T>, IVector0, T> /// /// The value in Dimensionless. /// A new instance. - public static Ratio FromDimensionless(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Ratio FromDimensionless(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two Ratio values, returning a signed SignedRatio result. + /// Subtracts two Ratio values, returning the absolute difference as a non-negative Ratio. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedRatio operator -(Ratio left, Ratio right) => SignedRatio.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Ratio operator -(Ratio left, Ratio right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Ratio by Duration to produce Frequency. /// 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 9cab4ca..6abab86 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 @@ -22,7 +22,13 @@ public record ReactionRate : PhysicalQuantity, T>, IVector0 /// The value in MolePerCubicMeterSecond. /// A new instance. - public static ReactionRate FromMolePerCubicMeterSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ReactionRate FromMolePerCubicMeterSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two ReactionRate values, returning the absolute difference as a non-negative ReactionRate. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ReactionRate operator -(ReactionRate left, ReactionRate right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies ReactionRate by Duration to produce Concentration. /// 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 02ffafe..11f8c97 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 @@ -19,14 +19,14 @@ public record RefractiveIndex : PhysicalQuantity, T>, IVec public static RefractiveIndex Zero => Create(T.Zero); /// Creates a new RefractiveIndex from a value in Dimensionless. - public static RefractiveIndex FromDimensionless(T value) => Create(value); + public static RefractiveIndex FromDimensionless(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Ratio. public static implicit operator Ratio(RefractiveIndex value) => Ratio.Create(value.Value); /// Explicit conversion from Ratio. public static explicit operator RefractiveIndex(Ratio value) => Create(value.Value); /// Creates a RefractiveIndex from a Ratio value. public static RefractiveIndex From(Ratio value) => Create(value.Value); -/// Subtracts two RefractiveIndex values, returning a signed SignedRatio result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedRatio operator -(RefractiveIndex left, RefractiveIndex right) => SignedRatio.Create(left.Quantity - right.Quantity); +/// Subtracts two RefractiveIndex values, returning the absolute difference as a non-negative RefractiveIndex. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static RefractiveIndex operator -(RefractiveIndex left, RefractiveIndex right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 f8c8b3c..bf8bd68 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 @@ -22,7 +22,13 @@ public record Resistance : PhysicalQuantity, T>, IVector0 /// The value in Ohm. /// A new instance. - public static Resistance FromOhm(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Resistance FromOhm(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Resistance values, returning the absolute difference as a non-negative Resistance. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Resistance operator -(Resistance left, Resistance right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Resistance by CurrentMagnitude to produce VoltageMagnitude. /// 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 860c4af..289ed68 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 @@ -19,12 +19,14 @@ public record ReverberationTime : PhysicalQuantity, T>, public static ReverberationTime Zero => Create(T.Zero); /// Creates a new ReverberationTime from a value in Second. - public static ReverberationTime FromSecond(T value) => Create(value); + public static ReverberationTime FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(ReverberationTime value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator ReverberationTime(Duration value) => Create(value.Value); /// Creates a ReverberationTime from a Duration value. public static ReverberationTime From(Duration value) => Create(value.Value); +/// Subtracts two ReverberationTime values, returning the absolute difference as a non-negative ReverberationTime. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ReverberationTime operator -(ReverberationTime left, ReverberationTime right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 93b2a71..27a9abb 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 @@ -19,14 +19,14 @@ public record ReynoldsNumber : PhysicalQuantity, T>, IVecto public static ReynoldsNumber Zero => Create(T.Zero); /// Creates a new ReynoldsNumber from a value in Dimensionless. - public static ReynoldsNumber FromDimensionless(T value) => Create(value); + public static ReynoldsNumber FromDimensionless(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Ratio. public static implicit operator Ratio(ReynoldsNumber value) => Ratio.Create(value.Value); /// Explicit conversion from Ratio. public static explicit operator ReynoldsNumber(Ratio value) => Create(value.Value); /// Creates a ReynoldsNumber from a Ratio value. public static ReynoldsNumber From(Ratio value) => Create(value.Value); -/// Subtracts two ReynoldsNumber values, returning a signed SignedRatio result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedRatio operator -(ReynoldsNumber left, ReynoldsNumber right) => SignedRatio.Create(left.Quantity - right.Quantity); +/// Subtracts two ReynoldsNumber values, returning the absolute difference as a non-negative ReynoldsNumber. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ReynoldsNumber operator -(ReynoldsNumber left, ReynoldsNumber right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 e133807..f1043da 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 @@ -19,12 +19,14 @@ public record SamplingRate : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new SamplingRate from a value in Hertz. - public static SamplingRate FromHertz(T value) => Create(value); + public static SamplingRate FromHertz(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Frequency. public static implicit operator Frequency(SamplingRate value) => Frequency.Create(value.Value); /// Explicit conversion from Frequency. public static explicit operator SamplingRate(Frequency value) => Create(value.Value); /// Creates a SamplingRate from a Frequency value. public static SamplingRate From(Frequency value) => Create(value.Value); +/// Subtracts two SamplingRate values, returning the absolute difference as a non-negative SamplingRate. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SamplingRate operator -(SamplingRate left, SamplingRate right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 59cf3c4..610eb46 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 @@ -19,12 +19,14 @@ public record ShearModulus : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new ShearModulus from a value in Pascal. - public static ShearModulus FromPascal(T value) => Create(value); + public static ShearModulus FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(ShearModulus value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator ShearModulus(Pressure value) => Create(value.Value); /// Creates a ShearModulus from a Pressure value. public static ShearModulus From(Pressure value) => Create(value.Value); +/// Subtracts two ShearModulus values, returning the absolute difference as a non-negative ShearModulus. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ShearModulus operator -(ShearModulus left, ShearModulus right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 85d1765..dc82f8b 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 @@ -22,11 +22,13 @@ public record SnapMagnitude : PhysicalQuantity, T>, IVector0 /// /// The value in MetersPerSecondQuartic. /// A new instance. - public static SnapMagnitude FromMetersPerSecondQuartic(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static SnapMagnitude FromMetersPerSecondQuartic(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two SnapMagnitude values, returning a signed Snap1D result. + /// Subtracts two SnapMagnitude values, returning the absolute difference as a non-negative SnapMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Snap1D operator -(SnapMagnitude left, SnapMagnitude right) => Snap1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SnapMagnitude operator -(SnapMagnitude left, SnapMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies SnapMagnitude by Duration to produce JerkMagnitude. /// 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 75d47c3..5a9dff8 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 @@ -19,12 +19,14 @@ public record SoundIntensity : PhysicalQuantity, T>, IVecto public static SoundIntensity Zero => Create(T.Zero); /// Creates a new SoundIntensity from a value in WattPerSquareMeter. - public static SoundIntensity FromWattPerSquareMeter(T value) => Create(value); + public static SoundIntensity FromWattPerSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Irradiance. public static implicit operator Irradiance(SoundIntensity value) => Irradiance.Create(value.Value); /// Explicit conversion from Irradiance. public static explicit operator SoundIntensity(Irradiance value) => Create(value.Value); /// Creates a SoundIntensity from a Irradiance value. public static SoundIntensity From(Irradiance value) => Create(value.Value); +/// Subtracts two SoundIntensity values, returning the absolute difference as a non-negative SoundIntensity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SoundIntensity operator -(SoundIntensity left, SoundIntensity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 34e1b4a..bcf0841 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 @@ -19,14 +19,14 @@ public record SoundSpeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new SoundSpeed from a value in MetersPerSecond. - public static SoundSpeed FromMetersPerSecond(T value) => Create(value); + public static SoundSpeed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(SoundSpeed value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator SoundSpeed(Speed value) => Create(value.Value); /// Creates a SoundSpeed from a Speed value. public static SoundSpeed From(Speed value) => Create(value.Value); -/// Subtracts two SoundSpeed values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(SoundSpeed left, SoundSpeed right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two SoundSpeed values, returning the absolute difference as a non-negative SoundSpeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SoundSpeed operator -(SoundSpeed left, SoundSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 d5e1ffa..5a8c0fb 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 @@ -19,12 +19,14 @@ public record SpecificEntropy : PhysicalQuantity, T>, IVec public static SpecificEntropy Zero => Create(T.Zero); /// Creates a new SpecificEntropy from a value in JoulePerKilogramKelvin. - public static SpecificEntropy FromJoulePerKilogramKelvin(T value) => Create(value); + public static SpecificEntropy FromJoulePerKilogramKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to SpecificHeat. public static implicit operator SpecificHeat(SpecificEntropy value) => SpecificHeat.Create(value.Value); /// Explicit conversion from SpecificHeat. public static explicit operator SpecificEntropy(SpecificHeat value) => Create(value.Value); /// Creates a SpecificEntropy from a SpecificHeat value. public static SpecificEntropy From(SpecificHeat value) => Create(value.Value); +/// Subtracts two SpecificEntropy values, returning the absolute difference as a non-negative SpecificEntropy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SpecificEntropy operator -(SpecificEntropy left, SpecificEntropy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 05686b8..0c703ef 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 @@ -19,14 +19,14 @@ public record SpecificGravity : PhysicalQuantity, T>, IVec public static SpecificGravity Zero => Create(T.Zero); /// Creates a new SpecificGravity from a value in Dimensionless. - public static SpecificGravity FromDimensionless(T value) => Create(value); + public static SpecificGravity FromDimensionless(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Ratio. public static implicit operator Ratio(SpecificGravity value) => Ratio.Create(value.Value); /// Explicit conversion from Ratio. public static explicit operator SpecificGravity(Ratio value) => Create(value.Value); /// Creates a SpecificGravity from a Ratio value. public static SpecificGravity From(Ratio value) => Create(value.Value); -/// Subtracts two SpecificGravity values, returning a signed SignedRatio result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SignedRatio operator -(SpecificGravity left, SpecificGravity right) => SignedRatio.Create(left.Quantity - right.Quantity); +/// Subtracts two SpecificGravity values, returning the absolute difference as a non-negative SpecificGravity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SpecificGravity operator -(SpecificGravity left, SpecificGravity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 7621ff8..67a62b3 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 @@ -22,7 +22,13 @@ public record SpecificHeat : PhysicalQuantity, T>, IVector0 /// The value in JoulePerKilogramKelvin. /// A new instance. - public static SpecificHeat FromJoulePerKilogramKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static SpecificHeat FromJoulePerKilogramKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two SpecificHeat values, returning the absolute difference as a non-negative SpecificHeat. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SpecificHeat operator -(SpecificHeat left, SpecificHeat right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies SpecificHeat by Mass to produce Entropy. /// 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 340b571..08a03b2 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 @@ -22,11 +22,13 @@ public record Speed : PhysicalQuantity, T>, IVector0, T> /// /// The value in MetersPerSecond. /// A new instance. - public static Speed FromMetersPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Speed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two Speed values, returning a signed Velocity1D result. + /// Subtracts two Speed values, returning the absolute difference as a non-negative Speed. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(Speed left, Speed right) => Velocity1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Speed operator -(Speed left, Speed right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Speed by Mass to produce MomentumMagnitude. /// 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 bccfb6d..b28dc95 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 @@ -19,12 +19,14 @@ public record Stress : PhysicalQuantity, T>, IVector0, T> public static Stress Zero => Create(T.Zero); /// Creates a new Stress from a value in Pascal. - public static Stress FromPascal(T value) => Create(value); + public static Stress FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(Stress value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator Stress(Pressure value) => Create(value.Value); /// Creates a Stress from a Pressure value. public static Stress From(Pressure value) => Create(value.Value); +/// Subtracts two Stress values, returning the absolute difference as a non-negative Stress. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Stress operator -(Stress left, Stress right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 dd30585..c3236d0 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 @@ -19,12 +19,14 @@ public record SurfaceArea : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new SurfaceArea from a value in SquareMeter. - public static SurfaceArea FromSquareMeter(T value) => Create(value); + public static SurfaceArea FromSquareMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Area. public static implicit operator Area(SurfaceArea value) => Area.Create(value.Value); /// Explicit conversion from Area. public static explicit operator SurfaceArea(Area value) => Create(value.Value); /// Creates a SurfaceArea from a Area value. public static SurfaceArea From(Area value) => Create(value.Value); +/// Subtracts two SurfaceArea values, returning the absolute difference as a non-negative SurfaceArea. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SurfaceArea operator -(SurfaceArea left, SurfaceArea right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 1528069..a4913f3 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 @@ -22,7 +22,13 @@ public record SurfaceTension : PhysicalQuantity, T>, IVecto /// /// The value in NewtonPerMeter. /// A new instance. - public static SurfaceTension FromNewtonPerMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static SurfaceTension FromNewtonPerMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two SurfaceTension values, returning the absolute difference as a non-negative SurfaceTension. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static SurfaceTension operator -(SurfaceTension left, SurfaceTension right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies SurfaceTension by Length to produce ForceMagnitude. /// 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 21f091c..d5d272c 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 @@ -22,11 +22,13 @@ public record Temperature : PhysicalQuantity, T>, IVector0 /// The value in Kelvin. /// A new instance. - public static Temperature FromKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Temperature FromKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two Temperature values, returning a signed TemperatureDelta result. + /// Subtracts two Temperature values, returning the absolute difference as a non-negative Temperature. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static TemperatureDelta operator -(Temperature left, Temperature right) => TemperatureDelta.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Temperature operator -(Temperature left, Temperature right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies Temperature by Entropy to produce Energy. /// 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 2aa3ca6..0e819f6 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 @@ -19,14 +19,14 @@ public record Tension : PhysicalQuantity, T>, IVector0, public static Tension Zero => Create(T.Zero); /// Creates a new Tension from a value in Newton. - public static Tension FromNewton(T value) => Create(value); + public static Tension FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Tension value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Tension(ForceMagnitude value) => Create(value.Value); /// Creates a Tension from a ForceMagnitude value. public static Tension From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Tension values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Tension left, Tension right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Tension values, returning the absolute difference as a non-negative Tension. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Tension operator -(Tension left, Tension right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 0763a0e..c455e96 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 @@ -22,6 +22,12 @@ public record ThermalConductivity : PhysicalQuantity, /// /// The value in WattPerMeterKelvin. /// A new instance. - public static ThermalConductivity FromWattPerMeterKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ThermalConductivity FromWattPerMeterKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two ThermalConductivity values, returning the absolute difference as a non-negative ThermalConductivity. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ThermalConductivity operator -(ThermalConductivity left, ThermalConductivity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 0241d7c..07cbd8b 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 @@ -19,12 +19,14 @@ public record ThermalDiffusivity : PhysicalQuantity, T> public static ThermalDiffusivity Zero => Create(T.Zero); /// Creates a new ThermalDiffusivity from a value in SquareMeterPerSecond. - public static ThermalDiffusivity FromSquareMeterPerSecond(T value) => Create(value); + public static ThermalDiffusivity FromSquareMeterPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to KinematicViscosity. public static implicit operator KinematicViscosity(ThermalDiffusivity value) => KinematicViscosity.Create(value.Value); /// Explicit conversion from KinematicViscosity. public static explicit operator ThermalDiffusivity(KinematicViscosity value) => Create(value.Value); /// Creates a ThermalDiffusivity from a KinematicViscosity value. public static ThermalDiffusivity From(KinematicViscosity value) => Create(value.Value); +/// Subtracts two ThermalDiffusivity values, returning the absolute difference as a non-negative ThermalDiffusivity. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ThermalDiffusivity operator -(ThermalDiffusivity left, ThermalDiffusivity right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 aefc424..3558913 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 @@ -19,12 +19,14 @@ public record ThermalEnergy : PhysicalQuantity, T>, IVector0 public static ThermalEnergy Zero => Create(T.Zero); /// Creates a new ThermalEnergy from a value in Joule. - public static ThermalEnergy FromJoule(T value) => Create(value); + public static ThermalEnergy FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Energy. public static implicit operator Energy(ThermalEnergy value) => Energy.Create(value.Value); /// Explicit conversion from Energy. public static explicit operator ThermalEnergy(Energy value) => Create(value.Value); /// Creates a ThermalEnergy from a Energy value. public static ThermalEnergy From(Energy value) => Create(value.Value); +/// Subtracts two ThermalEnergy values, returning the absolute difference as a non-negative ThermalEnergy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ThermalEnergy operator -(ThermalEnergy left, ThermalEnergy right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 2549f07..37001b5 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 @@ -22,7 +22,13 @@ public record ThermalExpansionCoefficient : PhysicalQuantity /// The value in PerKelvin. /// A new instance. - public static ThermalExpansionCoefficient FromPerKelvin(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static ThermalExpansionCoefficient FromPerKelvin(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two ThermalExpansionCoefficient values, returning the absolute difference as a non-negative ThermalExpansionCoefficient. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static ThermalExpansionCoefficient operator -(ThermalExpansionCoefficient left, ThermalExpansionCoefficient right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies ThermalExpansionCoefficient by Temperature to produce Ratio. /// 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 62c9603..aa68862 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 @@ -19,14 +19,14 @@ public record Thickness : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Thickness from a value in Meter. - public static Thickness FromMeter(T value) => Create(value); + public static Thickness FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Thickness value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Thickness(Length value) => Create(value.Value); /// Creates a Thickness from a Length value. public static Thickness From(Length value) => Create(value.Value); -/// Subtracts two Thickness values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Thickness left, Thickness right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Thickness values, returning the absolute difference as a non-negative Thickness. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Thickness operator -(Thickness left, Thickness right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 0336e1f..0bc9234 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 @@ -19,14 +19,14 @@ public record Thrust : PhysicalQuantity, T>, IVector0, T> public static Thrust Zero => Create(T.Zero); /// Creates a new Thrust from a value in Newton. - public static Thrust FromNewton(T value) => Create(value); + public static Thrust FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Thrust value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Thrust(ForceMagnitude value) => Create(value.Value); /// Creates a Thrust from a ForceMagnitude value. public static Thrust From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Thrust values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Thrust left, Thrust right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Thrust values, returning the absolute difference as a non-negative Thrust. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Thrust operator -(Thrust left, Thrust right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 27e3d53..288c679 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 @@ -19,12 +19,14 @@ public record TimeConstant : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new TimeConstant from a value in Second. - public static TimeConstant FromSecond(T value) => Create(value); + public static TimeConstant FromSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Duration. public static implicit operator Duration(TimeConstant value) => Duration.Create(value.Value); /// Explicit conversion from Duration. public static explicit operator TimeConstant(Duration value) => Create(value.Value); /// Creates a TimeConstant from a Duration value. public static TimeConstant From(Duration value) => Create(value.Value); +/// Subtracts two TimeConstant values, returning the absolute difference as a non-negative TimeConstant. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static TimeConstant operator -(TimeConstant left, TimeConstant right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 ed29879..d933bb1 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 @@ -22,11 +22,13 @@ public record TorqueMagnitude : PhysicalQuantity, T>, IVec /// /// The value in NewtonMeter. /// A new instance. - public static TorqueMagnitude FromNewtonMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static TorqueMagnitude FromNewtonMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two TorqueMagnitude values, returning a signed Torque1D result. + /// Subtracts two TorqueMagnitude values, returning the absolute difference as a non-negative TorqueMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Torque1D operator -(TorqueMagnitude left, TorqueMagnitude right) => Torque1D.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static TorqueMagnitude operator -(TorqueMagnitude left, TorqueMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies TorqueMagnitude by Angle to produce Energy. /// 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 8366375..c1dc372 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 @@ -19,14 +19,14 @@ public record VoltageDrop : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new VoltageDrop from a value in Volt. - public static VoltageDrop FromVolt(T value) => Create(value); + public static VoltageDrop FromVolt(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to VoltageMagnitude. public static implicit operator VoltageMagnitude(VoltageDrop value) => VoltageMagnitude.Create(value.Value); /// Explicit conversion from VoltageMagnitude. public static explicit operator VoltageDrop(VoltageMagnitude value) => Create(value.Value); /// Creates a VoltageDrop from a VoltageMagnitude value. public static VoltageDrop From(VoltageMagnitude value) => Create(value.Value); -/// Subtracts two VoltageDrop values, returning a signed Voltage result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Voltage operator -(VoltageDrop left, VoltageDrop right) => Voltage.Create(left.Quantity - right.Quantity); +/// Subtracts two VoltageDrop values, returning the absolute difference as a non-negative VoltageDrop. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static VoltageDrop operator -(VoltageDrop left, VoltageDrop right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 9a67843..d7748ec 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 @@ -22,11 +22,13 @@ public record VoltageMagnitude : PhysicalQuantity, T>, IV /// /// The value in Volt. /// A new instance. - public static VoltageMagnitude FromVolt(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static VoltageMagnitude FromVolt(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// - /// Subtracts two VoltageMagnitude values, returning a signed Voltage result. + /// Subtracts two VoltageMagnitude values, returning the absolute difference as a non-negative VoltageMagnitude. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Voltage operator -(VoltageMagnitude left, VoltageMagnitude right) => Voltage.Create(left.Quantity - right.Quantity); + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static VoltageMagnitude operator -(VoltageMagnitude left, VoltageMagnitude right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides VoltageMagnitude by Resistance to produce CurrentMagnitude. /// 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 d54b4e2..cf9e3a2 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 @@ -22,7 +22,13 @@ public record Volume : PhysicalQuantity, T>, IVector0, T> /// /// The value in CubicMeter. /// A new instance. - public static Volume FromCubicMeter(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static Volume FromCubicMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two Volume values, returning the absolute difference as a non-negative Volume. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Volume operator -(Volume left, Volume right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Divides Volume by Length to produce Area. /// 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 b7161a0..04b749e 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 @@ -22,7 +22,13 @@ public record VolumetricFlowRate : PhysicalQuantity, T> /// /// The value in CubicMeterPerSecond. /// A new instance. - public static VolumetricFlowRate FromCubicMeterPerSecond(T value) => Create(value); + /// Thrown when the resulting magnitude would be negative. + public static VolumetricFlowRate FromCubicMeterPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); +/// + /// Subtracts two VolumetricFlowRate values, returning the absolute difference as a non-negative VolumetricFlowRate. + /// Magnitude subtraction stays a magnitude (per the unified-vector model). + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static VolumetricFlowRate operator -(VolumetricFlowRate left, VolumetricFlowRate right) => Create(T.Abs(left.Quantity - right.Quantity)); /// /// Multiplies VolumetricFlowRate by Duration to produce Volume. /// 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 dc54d95..40dfbb1 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 @@ -19,14 +19,14 @@ public record Wavelength : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new Wavelength from a value in Meter. - public static Wavelength FromMeter(T value) => Create(value); + public static Wavelength FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Wavelength value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Wavelength(Length value) => Create(value.Value); /// Creates a Wavelength from a Length value. public static Wavelength From(Length value) => Create(value.Value); -/// Subtracts two Wavelength values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Wavelength left, Wavelength right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Wavelength values, returning the absolute difference as a non-negative Wavelength. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Wavelength operator -(Wavelength left, Wavelength right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 15bdd40..51d6c2f 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 @@ -19,14 +19,14 @@ public record Weight : PhysicalQuantity, T>, IVector0, T> public static Weight Zero => Create(T.Zero); /// Creates a new Weight from a value in Newton. - public static Weight FromNewton(T value) => Create(value); + public static Weight FromNewton(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to ForceMagnitude. public static implicit operator ForceMagnitude(Weight value) => ForceMagnitude.Create(value.Value); /// Explicit conversion from ForceMagnitude. public static explicit operator Weight(ForceMagnitude value) => Create(value.Value); /// Creates a Weight from a ForceMagnitude value. public static Weight From(ForceMagnitude value) => Create(value.Value); -/// Subtracts two Weight values, returning a signed Force1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Force1D operator -(Weight left, Weight right) => Force1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Weight values, returning the absolute difference as a non-negative Weight. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Weight operator -(Weight left, Weight right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 a00ee51..a0765ba 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 @@ -19,14 +19,14 @@ public record Width : PhysicalQuantity, T>, IVector0, T> public static Width Zero => Create(T.Zero); /// Creates a new Width from a value in Meter. - public static Width FromMeter(T value) => Create(value); + public static Width FromMeter(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Length. public static implicit operator Length(Width value) => Length.Create(value.Value); /// Explicit conversion from Length. public static explicit operator Width(Length value) => Create(value.Value); /// Creates a Width from a Length value. public static Width From(Length value) => Create(value.Value); -/// Subtracts two Width values, returning a signed Displacement1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Displacement1D operator -(Width left, Width right) => Displacement1D.Create(left.Quantity - right.Quantity); +/// Subtracts two Width values, returning the absolute difference as a non-negative Width. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Width operator -(Width left, Width right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 b467b31..d74d1f9 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 @@ -19,14 +19,14 @@ public record WindSpeed : PhysicalQuantity, T>, IVector0 Zero => Create(T.Zero); /// Creates a new WindSpeed from a value in MetersPerSecond. - public static WindSpeed FromMetersPerSecond(T value) => Create(value); + public static WindSpeed FromMetersPerSecond(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Speed. public static implicit operator Speed(WindSpeed value) => Speed.Create(value.Value); /// Explicit conversion from Speed. public static explicit operator WindSpeed(Speed value) => Create(value.Value); /// Creates a WindSpeed from a Speed value. public static WindSpeed From(Speed value) => Create(value.Value); -/// Subtracts two WindSpeed values, returning a signed Velocity1D result. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Velocity1D operator -(WindSpeed left, WindSpeed right) => Velocity1D.Create(left.Quantity - right.Quantity); +/// Subtracts two WindSpeed values, returning the absolute difference as a non-negative WindSpeed. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static WindSpeed operator -(WindSpeed left, WindSpeed right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 dcc33ce..e3940d3 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 @@ -19,12 +19,14 @@ public record Work : PhysicalQuantity, T>, IVector0, T> public static Work Zero => Create(T.Zero); /// Creates a new Work from a value in Joule. - public static Work FromJoule(T value) => Create(value); + public static Work FromJoule(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Energy. public static implicit operator Energy(Work value) => Energy.Create(value.Value); /// Explicit conversion from Energy. public static explicit operator Work(Energy value) => Create(value.Value); /// Creates a Work from a Energy value. public static Work From(Energy value) => Create(value.Value); +/// Subtracts two Work values, returning the absolute difference as a non-negative Work. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static Work operator -(Work left, Work right) => Create(T.Abs(left.Quantity - right.Quantity)); }; 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 9b10d19..b70121d 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 @@ -19,12 +19,14 @@ public record YoungsModulus : PhysicalQuantity, T>, IVector0 public static YoungsModulus Zero => Create(T.Zero); /// Creates a new YoungsModulus from a value in Pascal. - public static YoungsModulus FromPascal(T value) => Create(value); + public static YoungsModulus FromPascal(T value) => Create(Vector0Guards.EnsureNonNegative(value, nameof(value))); /// Implicit conversion to Pressure. public static implicit operator Pressure(YoungsModulus value) => Pressure.Create(value.Value); /// Explicit conversion from Pressure. public static explicit operator YoungsModulus(Pressure value) => Create(value.Value); /// Creates a YoungsModulus from a Pressure value. public static YoungsModulus From(Pressure value) => Create(value.Value); +/// Subtracts two YoungsModulus values, returning the absolute difference as a non-negative YoungsModulus. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "CA2225:Operator overloads have named alternates", Justification = "Physics quantity operator")] public static YoungsModulus operator -(YoungsModulus left, YoungsModulus right) => Create(T.Abs(left.Quantity - right.Quantity)); }; diff --git a/Semantics.SourceGenerators/AnalyzerReleases.Shipped.md b/Semantics.SourceGenerators/AnalyzerReleases.Shipped.md new file mode 100644 index 0000000..c1b674f --- /dev/null +++ b/Semantics.SourceGenerators/AnalyzerReleases.Shipped.md @@ -0,0 +1,2 @@ +; Shipped analyzer releases. +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md diff --git a/Semantics.SourceGenerators/AnalyzerReleases.Unshipped.md b/Semantics.SourceGenerators/AnalyzerReleases.Unshipped.md new file mode 100644 index 0000000..0513be6 --- /dev/null +++ b/Semantics.SourceGenerators/AnalyzerReleases.Unshipped.md @@ -0,0 +1,9 @@ +; Unshipped analyzer release. +; https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md + +### New Rules + +Rule ID | Category | Severity | Notes +--------|----------|----------|------ +SEM001 | Semantics.SourceGenerators | Warning | Reports relationships in dimensions.json that reference unknown dimension names. +SEM002 | Semantics.SourceGenerators | Warning | Reports schema-level validation issues in dimensions.json (missing fields, duplicate type names, etc). diff --git a/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs b/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs index e972b54..c9e88a5 100644 --- a/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs +++ b/Semantics.SourceGenerators/Generators/QuantitiesGenerator.cs @@ -28,6 +28,14 @@ public class QuantitiesGenerator : GeneratorBase defaultSeverity: DiagnosticSeverity.Warning, isEnabledByDefault: true); + private static readonly DiagnosticDescriptor MetadataValidationFailed = new( + id: "SEM002", + title: "dimensions.json metadata validation failed", + messageFormat: "dimensions.json validation issue: {0}", + category: "Semantics.SourceGenerators", + defaultSeverity: DiagnosticSeverity.Warning, + isEnabledByDefault: true); + public QuantitiesGenerator() : base("dimensions.json") { } protected override void Generate(SourceProductionContext context, DimensionsMetadata metadata, CodeBlocker codeBlocker) @@ -37,6 +45,17 @@ protected override void Generate(SourceProductionContext context, DimensionsMeta return; } + // Issue #60: surface schema-level metadata problems as diagnostics so they + // show up in the build log instead of crashing mid-emit. + List validationIssues = metadata.Validate(); + foreach (string issue in validationIssues) + { + context.ReportDiagnostic(Diagnostic.Create( + MetadataValidationFailed, + Location.None, + issue)); + } + // Phase A: Build maps and collect operators Dictionary dimensionMap = BuildDimensionMap(metadata); Dictionary typeFormMap = BuildTypeFormMap(metadata); diff --git a/Semantics.SourceGenerators/Models/DimensionsMetadata.cs b/Semantics.SourceGenerators/Models/DimensionsMetadata.cs index 781239f..e0f9acd 100644 --- a/Semantics.SourceGenerators/Models/DimensionsMetadata.cs +++ b/Semantics.SourceGenerators/Models/DimensionsMetadata.cs @@ -12,6 +12,112 @@ namespace Semantics.SourceGenerators.Models; public class DimensionsMetadata { public List PhysicalDimensions { get; set; } = []; + + /// + /// Validates the deserialised metadata, returning a list of human-readable issues. + /// An empty list means the metadata is well-formed. + /// + /// + /// Per #60: catches malformed entries before they reach the generator emit + /// pass, so problems surface as Roslyn diagnostics rather than a mid-emit crash + /// or a silently dropped operator. Cross-dimension reference checks are still + /// performed in the generator (#56 / SEM001) because they need the full + /// dimension map. + /// + public List Validate() + { + List issues = []; + + if (PhysicalDimensions.Count == 0) + { + issues.Add("dimensions.json contains no physicalDimensions entries."); + return issues; + } + + HashSet seenDimensionNames = []; + HashSet seenTypeNames = []; + + foreach (PhysicalDimension dim in PhysicalDimensions) + { + string label = string.IsNullOrEmpty(dim.Name) ? "" : dim.Name; + + if (string.IsNullOrEmpty(dim.Name)) + { + issues.Add("A physicalDimensions entry is missing 'name'."); + } + else if (!seenDimensionNames.Add(dim.Name)) + { + issues.Add($"Dimension '{dim.Name}' is declared more than once."); + } + + if (string.IsNullOrEmpty(dim.Symbol)) + { + issues.Add($"Dimension '{label}' is missing 'symbol'."); + } + + if (dim.AvailableUnits.Count == 0) + { + issues.Add($"Dimension '{label}' has an empty 'availableUnits' list."); + } + else + { + foreach (string unit in dim.AvailableUnits) + { + if (string.IsNullOrWhiteSpace(unit)) + { + issues.Add($"Dimension '{label}' has a blank entry in 'availableUnits'."); + } + } + } + + VectorFormDefinition?[] forms = [ + dim.Quantities.Vector0, + dim.Quantities.Vector1, + dim.Quantities.Vector2, + dim.Quantities.Vector3, + dim.Quantities.Vector4, + ]; + + if (System.Array.TrueForAll(forms, f => f == null)) + { + issues.Add($"Dimension '{label}' declares no vector forms (vector0..vector4)."); + } + + for (int i = 0; i < forms.Length; i++) + { + VectorFormDefinition? form = forms[i]; + if (form == null) + { + continue; + } + + if (string.IsNullOrEmpty(form.Base)) + { + issues.Add($"Dimension '{label}' vector{i} is missing 'base'."); + } + else if (!seenTypeNames.Add(form.Base)) + { + issues.Add($"Type name '{form.Base}' (dimension '{label}' vector{i}) collides with another base or overload."); + } + + foreach (OverloadDefinition overload in form.Overloads) + { + if (string.IsNullOrEmpty(overload.Name)) + { + issues.Add($"Dimension '{label}' vector{i} has an overload missing 'name'."); + continue; + } + + if (!seenTypeNames.Add(overload.Name)) + { + issues.Add($"Overload type name '{overload.Name}' (dimension '{label}' vector{i}) collides with another base or overload."); + } + } + } + } + + return issues; + } } ///