Skip to content

Having a Unit.SI #519

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

Closed
Mobz87 opened this issue Oct 14, 2018 · 7 comments
Closed

Having a Unit.SI #519

Mobz87 opened this issue Oct 14, 2018 · 7 comments

Comments

@Mobz87
Copy link

Mobz87 commented Oct 14, 2018

I find myself having a lot of:

entropy.JoulesPerKelvin
enthalpy.JoulesPerKilogram
pressure.Pascals

And a lot of:

MassFlow.FromKilogramsPerSecond(...)
VolumeFlow.FromCubicMetersPerSecond(...)
Power.FromWatts(...)

in my code.

I would love at have a option to not have to write the long SI-units (fx. KilogramsPerSecond).

If I could write instead:

entropy.SI
enthalpy.SI
pressure.SI
MassFlow.FromSI(...)
VolumeFlow.FromSI(...)
Power.FromSI(...)

Then my code would look much more clean and there would be less errors.
What do you think of this idea? And how difficult would it be to implement?

@tmilnthorp
Copy link
Collaborator

We were discussing having a UnitSystem class where you would define the 7 base units (as well as have a predefined SI system), and allow From and As to take a UnitSystem. This would allow you to convert or define everything in a consistent system of your choosing. However it is not possible at this time.

The auto generated operator overloads will need to be worked on first to get it to work generically.

@angularsen
Copy link
Owner

What @tmilnthorp said. When we (read @tmilnthorp ) extends with a new UnitSystem class, and we have a default instance for SI base units, then your examples above makes perfect sense to me.

Mass.FromSI(1) being equivalent to Mass.From(1, UnitSystem.SI) or perhaps new Mass(1, UnitSystem.SI) and maybe even defaulting to SI like this new Mass(1) // 1kg?

@angularsen
Copy link
Owner

#524 on the way already, wow.

@tmilnthorp
Copy link
Collaborator

Only works for base (single dimension of 1) units right now of course. Need to add all the operator overloads to allow derived unit conversion

@Mobz87
Copy link
Author

Mobz87 commented Oct 15, 2018

You guys are awesome!

new Mass(1) // 1kg that will be a great new option!

@tmilnthorp
Copy link
Collaborator

I will look at that next. Right now it's just a system definition. I'd like to add a UnitSystem overload to the From/As methods.

@angularsen
Copy link
Owner

Closing this issue in favor of #547 on v4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants