Skip to content

Switch arcade.math.lerp to use a Protocol bound to a TypeVar #2310

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

Merged
merged 17 commits into from
Jul 26, 2024

Conversation

pushfoo
Copy link
Member

@pushfoo pushfoo commented Jul 25, 2024

TL;DR: Add HasAddSubMul protocol and update Lerp functions to return Vec* where appropriate

Changes

  • Add HasAddSubMul protocol type + L TypeVar in arcade.math
  • Annotate arcade.math.lerp cleanly to allow arbitarary lerpables
  • Make lerp_2d return Vec2
  • Make lerp_3d return Vec3
  • Docstring updates
  • Cross-references for lerp_angle

Follow-up work

  • Should we have lerp check for an object.lerp method?
  • How do we integrate that into type annotations?

One option for the latter is something like this:

# Assume HasAddSubMul is the same as now

class HasLerp(Protocol[_T, _R]):
    def lerp(other: _T) -> _R:
  • Weigh upstreaming the positional slash for maximum fidelity to math built-ins?

@pushfoo pushfoo marked this pull request as ready for review July 25, 2024 14:33
@pushfoo pushfoo changed the title Lerpables Switch arcade.math.lerp to use a Protocol bound to a TypeVar Jul 25, 2024
@pushfoo
Copy link
Member Author

pushfoo commented Jul 25, 2024

As an update to this, it looks like only pyglet vector objects have the lerp method. The matrices do not.

@pushfoo pushfoo merged commit 7d9a26d into development Jul 26, 2024
8 checks passed
@einarf einarf deleted the lerpables branch July 28, 2024 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants