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

Idea: MultiMeasure (m/s, kg/ha etc.) #5

Open
varna opened this issue Jul 23, 2019 · 3 comments
Open

Idea: MultiMeasure (m/s, kg/ha etc.) #5

varna opened this issue Jul 23, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@varna
Copy link
Owner

varna commented Jul 23, 2019

Idea: type of Measure, that could handle multi dimensional units of different types.

const distance = new Measure(1, 'km')
const time = new Measure(1, 'h')
const speed = new MultiMeasure(distance, time)
String(speed) // "1 km/h"
speed.to('m/s') // "0.28 m/s"
@varna varna added the enhancement New feature or request label Jul 23, 2019
@varna
Copy link
Owner Author

varna commented Jul 23, 2019

const distance = new Measure(1, 'km')
const time = new Measure(1, 'h')
const speed = distance / time // new MultiMeasure(distance, time)
const distance = new Measure(1, 'km')
const moreDistance = distance * 10 // new Measure(10, 'km')
const area = distance * distance // new Measure(1, "km2")

This would be cool. Don't know if possible, should do a research on how operators work in JS.

@varna
Copy link
Owner Author

varna commented Jul 24, 2019

It seems that JavaScript Operator Overloading is impossible.

@varna
Copy link
Owner Author

varna commented Jul 24, 2019

Workaround with methods:

const distance = new Measure(1, 'km')
const area = distance.multiply(distance)  // new Measure(1, "km2")
const distance = new Measure(1, 'km')
const time = new Measure(1, 'h')
const speed = distance.divide(time) // new Measure(1, "km/h")

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

No branches or pull requests

1 participant