Skip to content

Zero animation time for SwitchRound causes ZeroDivisionError #75

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

Closed
The-Compiler opened this issue Oct 2, 2022 · 5 comments
Closed
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest DigitalOcean's Hacktoberfest

Comments

@The-Compiler
Copy link

The docs claim that it's possible to set animation_time to zero:

animation: Set animation_time to the duration (in seconds) it will take to transition the switch, set zero if you want it to snap into position immediately

However, the code doesn't actually handle that case, thus leading to a ZeroDivisionError here:

position = (elapsed_time) / self._animation_time # fraction from 0 to 1

Traceback:

Traceback (most recent call last):
  [...]
  File "adafruit_displayio_layout/widgets/switch_round.py", line 830, in value
  File "adafruit_displayio_layout/widgets/switch_round.py", line 792, in selected
  File "adafruit_displayio_layout/widgets/switch_round.py", line 767, in _animate_switch
@tekktrik tekktrik added bug Something isn't working good first issue Good for newcomers labels Oct 3, 2022
@tekktrik
Copy link
Member

tekktrik commented Oct 5, 2022

Adding this a good first issue so maybe someone will pick it up for Hacktoberfest. The fix is to make sure that if the animation time is zero that the animation process is skipped. This should look something like a check to see if _animation_time is zero, and if it is, calculate the final position, and avoid dividing by the animation time entirely.

I'll pick this up soon-ish if no one does soon!

@adafruit-adabot adafruit-adabot added the Hacktoberfest DigitalOcean's Hacktoberfest label Oct 5, 2022
@The-Debarghya
Copy link
Contributor

Can you specify which files are involved?
I can work on this then.

@The-Compiler
Copy link
Author

The-Compiler commented Oct 6, 2022

@The-Debarghya See the file I linked in my issue description - that _animate_switch method should be the only place needing a change. Often, changes will also require corresponding doc or tests changes. However, in this case, the docs are already correct, and there seem to be no existing tests (so I'm assuming you won't be expected to add a new one for this change).

@The-Debarghya
Copy link
Contributor

Ok thanks, I'm trying to fix this.

@tekktrik
Copy link
Member

Fixed via #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest DigitalOcean's Hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants