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

Add lerp & smoothstep to math module #2254

Merged
merged 6 commits into from
Nov 26, 2023

Conversation

robertpfeiffer
Copy link
Contributor

@robertpfeiffer robertpfeiffer commented Jun 15, 2023

e.g.

import pygame

a = 0.0
b = 10.0
pygame.math.lerp(a, b, 0.5)

>>> 5.0

@robertpfeiffer robertpfeiffer requested a review from a team as a code owner June 15, 2023 19:46
@yunline yunline added New API This pull request may need extra debate as it adds a new class or function to pygame math pygame.math labels Jun 16, 2023
src_c/math.c Outdated Show resolved Hide resolved
@robertpfeiffer robertpfeiffer force-pushed the vector-lerp branch 2 times, most recently from 545d673 to b980dcc Compare June 16, 2023 09:28
@Starbuck5
Copy link
Member

I'm surprised that these functions do vectors and numbers. It seems reasonable to have the module functions just do numbers and the vector methods do vectors. There's already a way to lerp two vectors together, with vector.lerp.

@MyreMylar
Copy link
Member

I agree with Starbuck. We should add a .smoothstep() method to the two vector classes and then have scalar/number only versions at the submodule function level.

That way there is one clear way to do it with either type of thing.

Copy link
Member

@MyreMylar MyreMylar left a comment

Choose a reason for hiding this comment

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

As commented above. Please make the module level functions for scalars only, and - if you like add the vector code for smoothstep as a method for the Vector classes.

This is to keep it consistent with the already existing Vector2.lerp() & Vector3.lerp().

It has been a long ass time, for me to get around to reviewing this so also happy to take this over if you don't want to make any changes.

docs/reST/ref/math.rst Outdated Show resolved Hide resolved
docs/reST/ref/math.rst Outdated Show resolved Hide resolved
src_c/math.c Outdated Show resolved Hide resolved
@MyreMylar MyreMylar changed the title WIP: vector lerp and smoothstep Add lerp & smoothstep to math module Nov 26, 2023
@MyreMylar MyreMylar requested review from dr0id and Starbuck5 November 26, 2023 12:06
@MyreMylar
Copy link
Member

Tidied this up a bit to respond to reviews.

@MyreMylar MyreMylar self-assigned this Nov 26, 2023
Copy link
Member

@Matiiss Matiiss left a comment

Choose a reason for hiding this comment

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

Code looks great, seems to run fine, these are wonderful additions. Although I'm not sure why the vector methods don't use METH_FASTCALL too, but that can be changed later if necessary.

@MyreMylar MyreMylar merged commit 9d76a10 into pygame-community:main Nov 26, 2023
29 checks passed
@MyreMylar MyreMylar added this to the 2.4.0 milestone Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
math pygame.math New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants