Skip to content

Conversation

bc913
Copy link
Contributor

@bc913 bc913 commented Jul 16, 2021

Added Reciprocal (Inverse) Length quantity and unit.

  • Implemented for meter, centimeter, millimeter, mile, yard, foot, UsSurveyFoot, inch, mil and microinch.
  • Some arithmetic operator overloads are provided for Force, ForcePerLength and Pressure to interact with the ReciprocalLength quantity for convenience.
  • Inverse method is implemented for Length quantity for convenience.

Copy link
Owner

@angularsen angularsen left a comment

Choose a reason for hiding this comment

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

Thanks! It looks good, just some suggestions below:

"Units": [
{
"SingularName": "InverseMeter",
"PluralName": "InverseMeter",
Copy link
Owner

Choose a reason for hiding this comment

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

InverseMeters

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

[InlineData(0.0, 0.0)]
[InlineData(1.0, 1.0)]
[InlineData(2.0, 0.5)]
public static void InverseTest(double value, double expected)
Copy link
Owner

Choose a reason for hiding this comment

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

I see you already copied this test to UnitsNet.Tests/CustomCode/ReciprocalLengthTests.cs, so you can remove this.

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 thought this test was part of the LengthTests so an optical illusion happened for me :). Made this test a part of the LengthTests.

[InlineData(0.0, 0.0)]
[InlineData(1.0, 1.0)]
[InlineData(2.0, 0.5)]
public static void InverseTest(double value, double expected)
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick, but you could rename this InverseReturnsLength.


protected override double InverseMeterInOneInverseMeter => 1;
protected override double InverseCentimeterInOneInverseMeter => 1E-2;
protected override double InverseMillimeterInOneInverseMeter => 1E-3;
Copy link
Owner

Choose a reason for hiding this comment

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

protected override double InverseCentimeterInOneInverseMeter => 1E-2;
protected override double InverseMillimeterInOneInverseMeter => 1E-3;

protected override double InverseMileInOneInverseMeter => 1 / 0.000621371;
Copy link
Owner

Choose a reason for hiding this comment

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

Please use constants looked up in an external reference, instead of calculations.

This is meant to serve as a double check that we got it right, since it is very easy to get it inverse and still pass all tests.

According to this converter, InverseMileInOneInverseMeter should be 1609.344.
https://www.unitsconverters.com/en/Reciprocal-Length-Conversions/Measurement-1182

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I was not sure at the beginning and there is an inconsistency throughout the repo so I've picked the fraction way. Now fixed.

public partial struct ReciprocalLength
{
/// <summary>
/// Calculates the inverse or <see cref="Length"/> of this unit.
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick, but ReciprocalLength is a quantity and not a unit. And since we don't map from InverseYard to Yard, maybe we could describe it like this:

Returns the inverse quantity <see cref="Length"/> with the unit <see cref="LengthUnit.Meter />.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

This was referenced Jul 18, 2021
@angularsen angularsen changed the title Added Reciprocal (Inverse) Length quantity and unit Add ReciprocalLength Jul 20, 2021
@angularsen angularsen merged commit 607a40e into angularsen:master Jul 20, 2021
@angularsen
Copy link
Owner

Great work! Nuget is on the way out.

Release UnitsNet/4.99.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.

2 participants