diff --git a/NEOSPlus/Quantity/Joules.cs b/NEOSPlus/Quantity/Joules.cs index 8b13789..5b1dc56 100644 --- a/NEOSPlus/Quantity/Joules.cs +++ b/NEOSPlus/Quantity/Joules.cs @@ -1 +1,145 @@ +using System; +using QuantityX; + +namespace NEOSPlus.Quantity +{ + public readonly struct Joule : IQuantitySI, IQuantitySI, IQuantity, IQuantity, IComparable, IEquatable + { + public readonly double BaseValue; + + public static readonly Unit Joules = new UnitSI(0, "J", "joule"); + + double IQuantity.BaseValue => BaseValue; + + public double SIPower => 1.0; + + public Unit DefaultUnit => Joules; + + public Joule(double baseValue = 0.0) + { + this = default(Joule); + BaseValue = baseValue; + } + + public bool Equals(Joule other) + { + return BaseValue == other.BaseValue; + } + + public int CompareTo(Joule other) + { + return BaseValue.CompareTo(other.BaseValue); + } + + public string[] GetShortBaseNames() + { + return new string[] { "J" }; + } + + public string[] GetLongBaseNames() + { + return new string[] { "joules", "joule" }; + } + + public IUnit[] GetCommonSIUnits() + { + return new IUnit[] + { + SI.Pico, + SI.Nano, + SI.Micro, + SI.Milli, + Joules, + SI.Kilo, + SI.Mega, + SI.Giga, + SI.Tera, + SI.Peta + }; + } + + public IUnit[] GetExludedSIUnits() + { + return new IUnit[] + { + SI.Yotta, + SI.Zetta, + SI.Exa, + SI.Deca, + SI.Hecto, + SI.Centi, + SI.Deci, + SI.Yocto, + SI.Zepto, + SI.Atto, + SI.Femto + }; + } + + public Joule New(double baseVal) + { + return new Joule(baseVal); + } + + public Joule Add(Joule q) + { + return new Joule(BaseValue + q.BaseValue); + } + + public Joule Subtract(Joule q) + { + return new Joule(BaseValue - q.BaseValue); + } + + public Joule Multiply(double n) + { + return new Joule(BaseValue * n); + } + + public Joule Divide(double n) + { + return new Joule(BaseValue / n); + } + + public Ratio Divide(Joule q) + { + return new Ratio(BaseValue / q.BaseValue); + } + + public static Joule operator +(Joule a, Joule b) + { + return a.Add(b); + } + + public static Joule operator -(Joule a, Joule b) + { + return a.Subtract(b); + } + + public static Joule operator *(Joule a, double n) + { + return a.Multiply(n); + } + + public static Joule operator /(Joule a, double n) + { + return a.Divide(n); + } + + public static Ratio operator /(Joule a, Joule b) + { + return a.Divide(b); + } + + public static Joule operator -(Joule a) + { + return a.Multiply(-1.0); + } + + public override string ToString() + { + return this.FormatAuto(); + } + } +}