Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix typing in arcade.math.clamp#2377

Merged
Cleptomania merged 3 commits into
pythonarcade:developmentpythonarcade/arcade:developmentfrom
DigiDuncan:fix_clamp_typingDigiDuncan/arcade:fix_clamp_typingCopy head branch name to clipboard
Oct 3, 2024
Merged

fix typing in arcade.math.clamp#2377
Cleptomania merged 3 commits into
pythonarcade:developmentpythonarcade/arcade:developmentfrom
DigiDuncan:fix_clamp_typingDigiDuncan/arcade:fix_clamp_typingCopy head branch name to clipboard

Conversation

@DigiDuncan

Copy link
Copy Markdown
Collaborator

No description provided.

@DragonMoffon DragonMoffon left a comment

Copy link
Copy Markdown
Collaborator

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

pushfoo commented Oct 1, 2024

Copy link
Copy Markdown
Member

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
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.