Skip to content
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

Add Angstrom unit #1042

Merged
merged 2 commits into from
Feb 11, 2022
Merged

Add Angstrom unit #1042

merged 2 commits into from
Feb 11, 2022

Conversation

JasLieb
Copy link
Contributor

@JasLieb JasLieb commented Feb 11, 2022

closes #1039

Happy to do it on my own and glad to help with my first PR on this project !

@codecov
Copy link

codecov bot commented Feb 11, 2022

Codecov Report

Merging #1042 (47eb710) into master (8e1240f) will increase coverage by 0.1%.
The diff coverage is 100.0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master   #1042     +/-   ##
========================================
+ Coverage    81.5%   81.5%   +0.1%     
========================================
  Files         308     308             
  Lines       48232   48241      +9     
========================================
+ Hits        39284   39293      +9     
  Misses       8948    8948             
Impacted Files Coverage Δ
...nsions/GeneratedCode/NumberToLengthExtensions.g.cs 100.0% <100.0%> (ø)
UnitsNet/GeneratedCode/Quantities/Length.g.cs 94.1% <100.0%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8e1240f...47eb710. Read the comment docs.

{
"SingularName": "Angstrom",
"PluralName": "Angstroms",
"FromUnitToBaseFunc": "{x}/1e-10",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angularsen I have been using spaces in the functions to match the styling of the rest of the code. Would you agree that the following is more consistent?

"FromUnitToBaseFunc": "{x} / 1e-10",
"FromBaseToUnitFunc": "{x} * 1e-10",

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, these are backwards. An Angstrom is 10e-10m. To go from Angstroms to meters, you must multiply.

      "FromUnitToBaseFunc": "{x} * 10e-10",
      "FromBaseToUnitFunc": "{x} / 10e-10",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm agree with you, your example is more consistent.
Also I didn't the follow the style guideline, other units are spaced like your example in the rest of the file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I would have to do a find/replace on all the json files to make it consistent with the rest of the code and generated code.

For example the generated prefixes have a lot of inconsistency:

unitConverter.SetConversionFunction<Length>(LengthUnit.Meter, LengthUnit.Nanometer, quantity => new Length((quantity.Value) / 1e-9d, LengthUnit.Nanometer));
unitConverter.SetConversionFunction<Length>(LengthUnit.Meter, LengthUnit.NauticalMile, quantity => new Length(quantity.Value/1852, LengthUnit.NauticalMile));

Consistent would look like:

unitConverter.SetConversionFunction<Length>(LengthUnit.Meter, LengthUnit.Nanometer, quantity => new Length((quantity.Value) / 1e-9d, LengthUnit.Nanometer));
unitConverter.SetConversionFunction<Length>(LengthUnit.Meter, LengthUnit.NauticalMile, quantity => new Length(quantity.Value / 1852, LengthUnit.NauticalMile));

Copy link
Contributor Author

@JasLieb JasLieb Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tmilnthorp and I'm confused about backwards : I followed this guide and I saw this example :

Multiply for FromBaseToUnit and divide for FromUnitToBase, so that Length.Centimeter is defined as "FromBaseToUnit": "x*100" and "FromUnitToBase": "x/100" where base unit is Meter

It is an error in the guide or I was on the right way ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angularsen I have been using spaces in the functions to match the styling of the rest of the code. Would you agree that the following is more consistent?

"FromUnitToBaseFunc": "{x} / 1e-10",
"FromBaseToUnitFunc": "{x} * 1e-10",

Sure, we can do that. We should update existing files to make it consistent and update the wiki guide too then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@angularsen I have been using spaces in the functions to match the styling of the rest of the code. Would you agree that the following is more consistent?

"FromUnitToBaseFunc": "{x} / 1e-10",
"FromBaseToUnitFunc": "{x} * 1e-10",

Sure, we can do that. We should update existing files to make it consistent and update the wiki guide too then.

Will do

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasLieb I updated the wiki to maybe help clarify.
image

@tmilnthorp's point was that the functions are reversed. You would typically see this in the test

 protected override double AngstromsInOneMeter => 1e-10;

Does one meter equal 1e-10 angstroms?

Copy link
Contributor Author

@JasLieb JasLieb Feb 11, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JasLieb I updated the wiki to maybe help clarify. image

@tmilnthorp's point was that the functions are reversed. You would typically see this in the test

 protected override double AngstromsInOneMeter => 1e-10;

Does one meter equal 1e-10 angstroms?

1 meters = 1e+10 Angstrom, So the overriden field should be :
protected override double AngstromsInOneMeter => 1e10;

If I change and if I apply @tmilnthorp review, I'm back on my feet, sound good to me and to the tests in this way.

@JasLieb
Copy link
Contributor Author

JasLieb commented Feb 11, 2022

@tmilnthorp Thank for your review ! But I ran into some issues if I follow all your comments : some tests are failing.
There is a screenshot of my failing tests.

image

There is something am I doing wrong ?

@tmilnthorp
Copy link
Collaborator

@tmilnthorp Thank for your review ! But I ran into some issues if I follow all your comments : some tests are failing. There is a screenshot of my failing tests.

image

There is something am I doing wrong ?

Uh oh. Looks like the BaseUnits is conflicting in the UnitSystem constructor since A happens to be first in the alphabetic list of quantity infos. This is a bug with our current UnitSystem code, not your PR.

Remove the BaseUnits code for now. I'll make an issue of that.

@tmilnthorp
Copy link
Collaborator

I added #1043 to track the issue with the UnitSystem code.

@tmilnthorp tmilnthorp merged commit 4d6083d into angularsen:master Feb 11, 2022
@angularsen
Copy link
Owner

@JasLieb Thanks for contributing, nuget should be out in a few minutes.

Release UnitsNet/4.120.0 · angularsen/UnitsNet

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

Successfully merging this pull request may close these issues.

Add Angstrom in available Length units
3 participants