angularsen / UnitsNet

Makes life working with units of measurement just a little bit better.
https://www.nuget.org/packages/UnitsNet/
MIT No Attribution
2.19k stars 380 forks source link

Mass from LinearDensity and Length #1250

Closed HakonJohannessen closed 1 year ago

HakonJohannessen commented 1 year ago

Hi :)

When working with linear densities and lengths it would be great to have at least a built in * (multiplication) operator for converting into mass.

As an example, consider a type of steel pipe with a linear density of 10kilograms / meter, now I produce 100 meters of this pipe and would like to know the total weight (mass): 10kilograms / meter * 100 meters = 1000 kilograms.

/// <summary>Get <see cref="Mass"/> from <see cref="LinearDensity"/> times <see cref="Length"/>.</summary>
public static Mass operator *(LinearDensity linearDensity, Length length)
{
     return Mass.FromKilograms(linearDensity.KilogramsPerMeter * length.Meters);
}

I would have liked to see something like this implemented in a future version. Anyway, thank you all for making and maintaining this project <3

angularsen commented 1 year ago

Hi, this seems useful. Would you be interested in attempting a pull request? I'm happy to assist.

You should be able to just put it in here: https://github.com/angularsen/UnitsNet/blob/master/UnitsNet/CustomCode/Quantities/LinearDensity.extra.cs