diff --git a/Elements.Quantity/Quantities/Basic/Density.cs b/Elements.Quantity/Quantities/Basic/Density.cs new file mode 100644 index 0000000..6156588 --- /dev/null +++ b/Elements.Quantity/Quantities/Basic/Density.cs @@ -0,0 +1,71 @@ +using System; + +namespace Elements.Quantity +{ + public readonly struct Density : IQuantity + { + #region ESSENTIALS + + public readonly double BaseValue; + + double IQuantity.BaseValue => BaseValue; + + public Density(double baseValue = 0) : this() { BaseValue = baseValue; } + + public bool Equals(Density other) { return BaseValue == other.BaseValue; } + public int CompareTo(Density other) { return BaseValue.CompareTo(other.BaseValue); } + + #endregion + + #region QUANTITY NAME DEFINITIONS + + public string[] GetShortBaseNames() { return new string[] { "kg/m³" }; } + public string[] GetLongBaseNames() { return new string[] { "kilograms per cubic meter", "kilogram per cubic meter" }; } + + #endregion + + #region UNITS + + public Unit DefaultUnit { get { return KilogramPerCubicMeter; } } + + public static readonly Unit KilogramPerCubicMeter = new Unit(1, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " kg/m³" }, new string[] { "kilograms per cubic meter" }); + + public static readonly Unit GramPerCubicCentimeter = new Unit(1000, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " g/cm³" }, new string[] { "grams per cubic centimeter" }); + + public static readonly Unit PoundPerCubicFoot = new Unit(16.0185, + new UnitGroup[] { UnitGroup.Imperial }, + new string[] { " lb/ft³" }, new string[] { "pounds per cubic foot" }); + + #endregion + + #region OPERATORS + + public Density New(double baseVal) { return new Density(baseVal); } + + public Density Add(Density q) { return new Density(BaseValue + q.BaseValue); } + public Density Subtract(Density q) { return new Density(BaseValue - q.BaseValue); } + + public Density Multiply(double n) { return new Density(BaseValue * n); } + public Density Multiply(Density a, Ratio r) { return a * r.BaseValue; } + public Density Multiply(Ratio r, Density a) { return a * r.BaseValue; } + + public Density Divide(double n) { return new Density(BaseValue / n); } + public Ratio Divide(Density q) { return new Ratio(BaseValue / q.BaseValue); } + + public static Density Parse(string str) { return Unit.Parse(str); } + public static bool TryParse(string str, out Density q) { return Unit.TryParse(str, out q); } + + public static Density operator +(Density a, Density b) { return a.Add(b); } + public static Density operator -(Density a, Density b) { return a.Subtract(b); } + public static Density operator *(Density a, double n) { return a.Multiply(n); } + public static Density operator /(Density a, double n) { return a.Divide(n); } + public static Ratio operator /(Density a, Density b) { return a.Divide(b); } + public static Density operator -(Density a) { return a.Multiply(-1); } + + #endregion + } +} diff --git a/Elements.Quantity/Quantities/Basic/Luminance.cs b/Elements.Quantity/Quantities/Basic/Luminance.cs new file mode 100644 index 0000000..4e9dace --- /dev/null +++ b/Elements.Quantity/Quantities/Basic/Luminance.cs @@ -0,0 +1,67 @@ +using System; + +namespace Elements.Quantity +{ + public readonly struct Luminance : IQuantity + { + #region ESSENTIALS + + public readonly double BaseValue; + + double IQuantity.BaseValue => BaseValue; + + public Luminance(double baseValue = 0) : this() { BaseValue = baseValue; } + + public bool Equals(Luminance other) { return BaseValue == other.BaseValue; } + public int CompareTo(Luminance other) { return BaseValue.CompareTo(other.BaseValue); } + + #endregion + + #region QUANTITY NAME DEFINITIONS + + public string[] GetShortBaseNames() { return new string[] { "cd/m²" }; } + public string[] GetLongBaseNames() { return new string[] { "candelas per square meter", "candela per square meter" }; } + + #endregion + + #region UNITS + + public Unit DefaultUnit { get { return CandelaPerSquareMeter; } } + + public static readonly Unit CandelaPerSquareMeter = new Unit(1, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " cd/m²" }, new string[] { "candelas per square meter" }); + + public static readonly Unit Nit = new Unit(1, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " nit" }, new string[] { "nits" }); // Nit is a non-SI name for cd/m² + + #endregion + + #region OPERATORS + + public Luminance New(double baseVal) { return new Luminance(baseVal); } + + public Luminance Add(Luminance q) { return new Luminance(BaseValue + q.BaseValue); } + public Luminance Subtract(Luminance q) { return new Luminance(BaseValue - q.BaseValue); } + + public Luminance Multiply(double n) { return new Luminance(BaseValue * n); } + public Luminance Multiply(Luminance a, Ratio r) { return a * r.BaseValue; } + public Luminance Multiply(Ratio r, Luminance a) { return a * r.BaseValue; } + + public Luminance Divide(double n) { return new Luminance(BaseValue / n); } + public Ratio Divide(Luminance q) { return new Ratio(BaseValue / q.BaseValue); } + + public static Luminance Parse(string str) { return Unit.Parse(str); } + public static bool TryParse(string str, out Luminance q) { return Unit.TryParse(str, out q); } + + public static Luminance operator +(Luminance a, Luminance b) { return a.Add(b); } + public static Luminance operator -(Luminance a, Luminance b) { return a.Subtract(b); } + public static Luminance operator *(Luminance a, double n) { return a.Multiply(n); } + public static Luminance operator /(Luminance a, double n) { return a.Divide(n); } + public static Ratio operator /(Luminance a, Luminance b) { return a.Divide(b); } + public static Luminance operator -(Luminance a) { return a.Multiply(-1); } + + #endregion + } +} diff --git a/Elements.Quantity/Quantities/Basic/Torque.cs b/Elements.Quantity/Quantities/Basic/Torque.cs new file mode 100644 index 0000000..aa54dc3 --- /dev/null +++ b/Elements.Quantity/Quantities/Basic/Torque.cs @@ -0,0 +1,67 @@ +using System; + +namespace Elements.Quantity +{ + public readonly struct Torque : IQuantity + { + #region ESSENTIALS + + public readonly double BaseValue; + + double IQuantity.BaseValue => BaseValue; + + public Torque(double baseValue = 0) : this() { BaseValue = baseValue; } + + public bool Equals(Torque other) { return BaseValue == other.BaseValue; } + public int CompareTo(Torque other) { return BaseValue.CompareTo(other.BaseValue); } + + #endregion + + #region QUANTITY NAME DEFINITIONS + + public string[] GetShortBaseNames() { return new string[] { "Nm" }; } + public string[] GetLongBaseNames() { return new string[] { "newton meters", "newton meter" }; } + + #endregion + + #region UNITS + + public Unit DefaultUnit { get { return NewtonMeter; } } + + public static readonly Unit NewtonMeter = new Unit(1, + new UnitGroup[] { UnitGroup.Common }, + new string[] { " Nm" }, new string[] { "newton meters" }); + + public static readonly Unit PoundFoot = new Unit(1.35582, + new UnitGroup[] { UnitGroup.Imperial }, + new string[] { " lb·ft" }, new string[] { "pound-feet" }); + + #endregion + + #region OPERATORS + + public Torque New(double baseVal) { return new Torque(baseVal); } + + public Torque Add(Torque q) { return new Torque(BaseValue + q.BaseValue); } + public Torque Subtract(Torque q) { return new Torque(BaseValue - q.BaseValue); } + + public Torque Multiply(double n) { return new Torque(BaseValue * n); } + public Torque Multiply(Torque a, Ratio r) { return a * r.BaseValue; } + public Torque Multiply(Ratio r, Torque a) { return a * r.BaseValue; } + + public Torque Divide(double n) { return new Torque(BaseValue / n); } + public Ratio Divide(Torque q) { return new Ratio(BaseValue / q.BaseValue); } + + public static Torque Parse(string str) { return Unit.Parse(str); } + public static bool TryParse(string str, out Torque q) { return Unit.TryParse(str, out q); } + + public static Torque operator +(Torque a, Torque b) { return a.Add(b); } + public static Torque operator -(Torque a, Torque b) { return a.Subtract(b); } + public static Torque operator *(Torque a, double n) { return a.Multiply(n); } + public static Torque operator /(Torque a, double n) { return a.Divide(n); } + public static Ratio operator /(Torque a, Torque b) { return a.Divide(b); } + public static Torque operator -(Torque a) { return a.Multiply(-1); } + + #endregion + } +}