-
Notifications
You must be signed in to change notification settings - Fork 393
Add quantity constructor overload for UnitSystem #547
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@tmilnthorp I started on this and quickly realized I didn't fully understand how we should implement it. Hoping you have some ideas :-) I hoped to bring it into v4, but it can wait to v5 if it's not straight forward. |
|
I wonder how we'll resolve things like this: "SingularName": "SquareFoot",
"PluralName": "SquareFeet",
"BaseUnits": {
"Length": "LengthUnit.Foot"
},
"FromUnitToBaseFunc": "x*0.092903",
"FromBaseToUnitFunc": "x/0.092903",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "ft²" ]
},
{
"Culture": "ru-RU",
"Abbreviations": [ "фут²" ]
}
]
},
{
"SingularName": "UsSurveySquareFoot",
"PluralName": "UsSurveySquareFeet",
"BaseUnits": {
"Length": "LengthUnit.Foot"
},
"FromUnitToBaseFunc": "x*0.09290341161",
"FromBaseToUnitFunc": "x/0.09290341161",
"Localization": [
{
"Culture": "en-US",
"Abbreviations": [ "ft² (US)" ]
}
]
}, Both have a base unit of feet. Similar to ambiguous parsing we'll have ambiguous unit system values potentially. |
Well, in this particular scenario, I think maybe we'll just have to try mapping up all the units and see if we find any ambiguity? |
One thing we can run into is unmapped units. You've defined a UnitSystem with base length unit UsSurveyFoot. Then you try to create an Area with this unit system and maybe we didn't get around to adding UsSurveySquareFoot yet. That would throw an exception. Not sure how big of a problem this would be, but I kind of don't like running into runtime exceptions like this. At least something to be aware of when using these constructors. Another thing is, we are adding significant complexity here and I sincerely hope it adds enough value that people will make use of it. |
I'm not sure how to move this discussion along. There seems to be some uncertainty how this should all work, I think I need to see a PR with some actual code and tests to consider it further. I'm closing this issue due to inactivity, please create a PR or reopen this issue to discuss further. |
In my example PR you can see I added a constructor for it. Just need to finalize that and add base units for everything |
For reference, ☝️ is #601 . |
Now I just need some help adding BaseUnits for all the units we have! |
Per discussion in #519, we want to construct quantities using a unit system such as SI or a custom unit system. The advantage is consistent base units and not having to specify the unit when constructing quantities.
So you can do
Implementation
MyQuantity(double numericValue, UnitSystem unitSystem) {}
MyQuantity(double numericValue) : MyQuantity(numericValue, UnitSystem.SI) {}
Quantities with dimensions matching base units is easy
Dimensionless quantities?
Information
,Ratio
,Angle
, etc...These are not coupled to any unit system, so we can keep the existing choice of base unit?
Logarithmic quantities?
Level
(dB),PoweRatio
,AmplitudeRatio
AmplitudeRatio dBV
PoweRatio dBW
They seem uncoupled from unit systems, so we can keep the existing choices of base unit?
Non-trivial quantities?
Most quantities fall in this category. How do we construct them given a non-SI instance of
UnitSystem
?ElectricChargeDensity C/m³
The text was updated successfully, but these errors were encountered: