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

Refactor the unit.py module to make it simplier and flexible #35

Open
o-murphy opened this issue Oct 18, 2023 · 2 comments
Open

Refactor the unit.py module to make it simplier and flexible #35

o-murphy opened this issue Oct 18, 2023 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@o-murphy
Copy link
Owner

  • make the opperations with raw values available
  • add an arithmetic support between units of the same type and between different unit types|
  • make the arithmetic operations to return stacked type of units if the operation returns unavailable unit in base
@o-murphy o-murphy added enhancement New feature or request help wanted Extra attention is needed labels Oct 18, 2023
@dbookstaber
Copy link
Contributor

Some notes on doing arithmetic on Units:

Example: We have a some_distance instance of Distance, and we want to double it.

Here is one kludge:
Distance(2*some_distance.raw_value, Distance.Inch) << some_distance.unit

Problem: We have to read through the Distance class to see that its raw_value is in units of Distance.Inch.

Solution: Give all AbstractUnits child classes a raw_units property (can be static) that returns the raw units for the subclass. For example, Distance.raw_units would return Distance.Inch. Then we could instead do:
Distance(2*some_distance.raw_value, some_distance.raw_units) << some_distance.unit

@o-murphy
Copy link
Owner Author

o-murphy commented Mar 15, 2024

I played with that, I want to realize __add__, __mul__, __div__ etc for AbstractUnits, to use it directly with this syntax

d_instance = Unit.Inch(10)
double_distance = 2*d_instance

but simple math operations would be available just between 2 instances of same class, we'll not be able to multiply Distance to Velocity

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

No branches or pull requests

2 participants