Tsjunne / Physics

MIT License
12 stars 4 forks source link

Quantity from string #1

Closed bcachet closed 3 years ago

bcachet commented 9 years ago

Hello,

I really like your library design. Most of the libraries I found on NuGet (https://github.com/objorke/QuantityTypes) do not define a Dimension. So you have to define the operators /,* for all the conversions you are interested in.

I see that it is possible to convert a string to a Unit. Is it possible to perform a conversion from string to Quantity ? If not, what approach do you recommand ?

Thanks for your excellent work

Bertrand

Tsjunne commented 9 years ago

I think it would be feasible to just parse out the string into a value and unit string. You'd be best to just keep them in separate fields or concatenate them using a known separator. I'll try to integrate some quantity parsing logic in the next version, but i'm not to keen on that. If you are looking for a way to easily serialize and deserialize to a string format, you might want to use the JSON serializer. See unittests 'WhenMappingQuantity'

Tsjunne commented 9 years ago

What is the usecase you are looking for?

bcachet commented 9 years ago

I want to create a formula interpreter with support of SI units. User will be able to enter 2ms * 2m/s and get 4mm as result. I am already able to parse/eval a formula that do not have physical units. Instead of parsing numbers as Integer/Real numbers, I wan to use a Physics parser.