-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
|
||
namespace Elements.Quantity | ||
{ | ||
public readonly struct Density : IQuantity<Density> | ||
{ | ||
#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<Density> DefaultUnit { get { return KilogramPerCubicMeter; } } | ||
|
||
public static readonly Unit<Density> KilogramPerCubicMeter = new Unit<Density>(1, | ||
new UnitGroup[] { UnitGroup.Common }, | ||
new string[] { " kg/m³" }, new string[] { "kilograms per cubic meter" }); | ||
|
||
public static readonly Unit<Density> GramPerCubicCentimeter = new Unit<Density>(1000, | ||
new UnitGroup[] { UnitGroup.Common }, | ||
new string[] { " g/cm³" }, new string[] { "grams per cubic centimeter" }); | ||
|
||
public static readonly Unit<Density> PoundPerCubicFoot = new Unit<Density>(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<Density>.Parse(str); } | ||
public static bool TryParse(string str, out Density q) { return Unit<Density>.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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
|
||
namespace Elements.Quantity | ||
{ | ||
public readonly struct Luminance : IQuantity<Luminance> | ||
{ | ||
#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<Luminance> DefaultUnit { get { return CandelaPerSquareMeter; } } | ||
|
||
public static readonly Unit<Luminance> CandelaPerSquareMeter = new Unit<Luminance>(1, | ||
new UnitGroup[] { UnitGroup.Common }, | ||
new string[] { " cd/m²" }, new string[] { "candelas per square meter" }); | ||
|
||
public static readonly Unit<Luminance> Nit = new Unit<Luminance>(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<Luminance>.Parse(str); } | ||
public static bool TryParse(string str, out Luminance q) { return Unit<Luminance>.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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
|
||
namespace Elements.Quantity | ||
{ | ||
public readonly struct Torque : IQuantity<Torque> | ||
{ | ||
#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<Torque> DefaultUnit { get { return NewtonMeter; } } | ||
|
||
public static readonly Unit<Torque> NewtonMeter = new Unit<Torque>(1, | ||
new UnitGroup[] { UnitGroup.Common }, | ||
new string[] { " Nm" }, new string[] { "newton meters" }); | ||
|
||
public static readonly Unit<Torque> PoundFoot = new Unit<Torque>(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<Torque>.Parse(str); } | ||
public static bool TryParse(string str, out Torque q) { return Unit<Torque>.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 | ||
} | ||
} |