haimkastner / unitsnet-js

A better way to hold unit variables and easily convert to the destination unit
https://www.npmjs.com/package/unitsnet-js
MIT License
23 stars 8 forks source link

Length.multiply() multiplicator #28

Open gedlbauer opened 7 months ago

gedlbauer commented 7 months ago

Hey,

I noticed that you can muliply a length unit by another length:

const length1 = Length.FromMeters(10);
const length3 = Length.FromMeters(3);
const results3 = length1.multiply(length3);

console.log(results3.toString(LengthUnits.Meters)) // 30 m

In my oppinion this is not correct. The result should not be 30 meters, but 30 squaremeters if we want to stay mathematically correct.

The param for length.multiply() should just be a number (as the multiplicator). This would cause in mathematically correct behavior.

Kind regards, Georg

haimkastner commented 7 months ago

Hi @gedlbauer

Thank you for your comment.

I do understand your approach but this package is designed to provide an easy, scale-agnostic way to handle/convert same-unit different-scale (i.e., mm, cm, km, etc.) but not different-type units (length vs area, for example)

The above code is equivalent to this:

const length1 = 10;
const length3 = 3;
const results3 = length1 * length3; // 30

Using Length abstraction for the unit type still should work the same as the above code and be 30.

I think what you're suggesting would be a better fit for something like Area.fromMeterage()?

There is already a request for a new feature to support arithmetic operations between units see #26 & haimkastner/unitsnet-py#12.

Hope to gather some time to implement it in the future :)

CC: @yuval-po