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

fix typing in arcade.math.clamp #2377

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

DigiDuncan
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@DragonMoffon DragonMoffon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am curious if there are other methods in arcade that could get this improved typing treatment? Stuff like the lerp function.

@pushfoo
Copy link
Member

pushfoo commented Oct 1, 2024

I'm considering including something like useful_types. There was some part of it I didn't like for some reason. It was more than just another tiny dependency in our heaping pile. Looking at their PR queue, it may have been that the project is bit slow to merge.

stuff like the lerp function

😎 Beat you to that one.
👇

arcade/arcade/math.py

Lines 49 to 78 in 553894e

# This TypeVar helps match v1 and v2 as the same type below in lerp's
# signature. If we used HasAddSubMul, they could be different.
L = TypeVar("L", bound=HasAddSubMul)
def lerp(v1: L, v2: L, u: float) -> L:
"""Linearly interpolate two values which support arithmetic operators.
Both ``v1`` and ``v2`` must be of compatible types and support
the following operators:
* ``+`` (:py:meth:`~object.__add__`)
* ``-`` (:py:meth:`~object.__sub__`)
* ``*`` (:py:meth:`~object.__mul__`)
This means that in certain cases, you may want to use another
function:
* For angles, use :py:func:`lerp_angle`.
* To convert points as arbitary sequences, use:
* :py:func:`lerp_2d`
* :py:func:`lerp_3d`
Args:
v1 (HasAddSubMul): The first value
v2 (HasAddSubMul): The second value
u: The interpolation value `(0.0 to 1.0)`
"""
return v1 + ((v2 - v1) * u)

@Cleptomania Cleptomania merged commit 85eb020 into pythonarcade:development Oct 3, 2024
7 checks passed
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.

4 participants