Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Add .move_towards() for Vector2 and Vector3#2929

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
MyreMylar merged 29 commits intopygame:mainfromandrewhong04:novial-move_towards
Feb 20, 2022
Merged

Add .move_towards() for Vector2 and Vector3#2929

MyreMylar merged 29 commits intopygame:mainfromandrewhong04:novial-move_towards
Feb 20, 2022

Conversation

@andrewhong04
Copy link
Contributor

@andrewhong04andrewhong04 commentedDec 19, 2021
edited
Loading

@andrewhong04
Copy link
ContributorAuthor

I noticed thatmove_toward is not grammatically correct, but I think some other people will have a better name thanmove_towards, so I'll leave it for now until there are some better name suggestions.

@andrewhong04
Copy link
ContributorAuthor

andrewhong04 commentedDec 29, 2021
edited
Loading

Alright, I'm done with themove_towards().
I did some performance testing with the Python version.

importpygameimporttimestart=time.perf_counter()defvector2_move_towards(origin,target,speed:float):"""Moves towards the target Vector2 by the movement speed.    Must be put in a loop until its reached its target.    Parameters:        origin: The original position        target: The target position.        speed: The movement speed.    """delta=target-origindist=delta.magnitude()if (dist<=speedordist==0):returntargetreturnorigin+delta/dist*speedvec1=pygame.Vector2(10,20)vec2=pygame.Vector2(30,30)speed=1vec3=vector2_move_towards(vec1,vec2,speed)print(vec3)end=time.perf_counter()print(end-start)

Here are the results:

C:0.00005339999Python:0.00011449999874457717

Time to work onmove_towards_ip()!

Edit: It looks like after I gotmove_towards() working,move_towards_ip started working... lol.

Copy link
Contributor

@ankith26ankith26 left a comment

Choose a reason for hiding this comment

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

This also needs unittests and type stubs

andrewhong04 reacted with thumbs up emoji
@andrewhong04
Copy link
ContributorAuthor

This also needs unittests and type stubs

Done!

Copy link
Contributor

@ankith26ankith26 left a comment

Choose a reason for hiding this comment

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

Lots of changes 😅

@andrewhong04
Copy link
ContributorAuthor

Lots of changes 😅

Whoops, looks like I rushed things lol.

ankith26
ankith26 previously requested changesJan 1, 2022
Copy link
Contributor

@ankith26ankith26 left a comment

Choose a reason for hiding this comment

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

This PR is almost looking good to go! Before merge, you must runpython3 setup.py format and commit the autoformat changes, and all these commits can be squashed and merged

Copy link
Member

@illumeillume left a comment

Choose a reason for hiding this comment

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

🎉 👍 thanks :)

@Starbuck5
Copy link
Contributor

There's a problem with input parsing

>>>a=pygame.math.Vector2((0,0))>>>a.move_towards((10,10),2)<Vector2(1.41421,1.41421)>>>>b=pygame.math.Vector3(0)>>>b<Vector3(0,0,0)>>>>b.move_towards(a,2)<Vector3(0,0,1.42421e-306)>>>>a.move_towards((1,2,3,4,5,6,7,8),10)Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>TypeError:ExpectedVectorasargument1

If the dimensions aren't equal, it should fail, presumably

And if the input is rejected, it shouldn't say it expected a Vector, since it can take vector-like. Pygame rect functions would call this "Rect-style," so that could be used here as "Vector2-style" or "Vector3-style"

Also I'm putting in a commit that fixes a couple things with the example.
It adds it to the examples listing, and it makes it a size that will work on people's 125% scaled displays (like mine), and it does pygame.quit() properly.

andrewhong04 reacted with thumbs up emoji

Andrew Hongand others added18 commitsFebruary 18, 2022 16:05
Co-authored-by: Ankith <46915066+ankith26@users.noreply.github.com>
Co-authored-by: Ankith <46915066+ankith26@users.noreply.github.com>
Co-authored-by: Ankith <46915066+ankith26@users.noreply.github.com>
Co-authored-by: Ankith <46915066+ankith26@users.noreply.github.com>
…alriptide/pygame into novial-move_towards"This reverts commit771df5e, reversingchanges made toe6e5992.
Formatting
@illumeillume added this to the2.1.3 milestoneFeb 19, 2022
target=Vector2(12.30,2021.0)
change_ip=Vector2(7.22,2004.0)

change=origin.move_towards(target,-3)
Copy link
Contributor

Choose a reason for hiding this comment

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

feels like contradicting: move_towards but actually it moves away with the negative

resolve at will

dr0id reacted with laugh emoji
Copy link
Member

Choose a reason for hiding this comment

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

It's a pretty good point. Even though we've gone over naming this method more than anything else in the story of pygame, and perhaps any method named anywhere ever...

Did we consider "to"?v.to(v2, -1.1).

Copy link
Contributor

@dr0iddr0id left a comment

Choose a reason for hiding this comment

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

I left some suggestions. No need to change them in this PR or at all. Approving anyway.

@andrewhong04
Copy link
ContributorAuthor

I left some suggestions. No need to change them in this PR or at all. Approving anyway.

Thanks! I'll be looking to resolving these later today.

Copy link
Contributor

@ankith26ankith26 left a comment

Choose a reason for hiding this comment

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

Finally approving this PR 🥳
There is a CI fail but it's unrelated.
Also, side note to the person merging the PR, squash and merge, and remember to remove co-author tags while doing so, so that me and starbuck don't come as PR authors here :)

Copy link
Member

@illumeillume left a comment

Choose a reason for hiding this comment

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

👍 thanks for this, and for being such a good sport about all the naming conversations.

andrewhong04 reacted with heart emoji
@illumeillume added the New APIThis pull request may need extra debate as it adds a new class or function to pygame labelOct 23, 2022
@VegaPac
Copy link

As of 2023 it works perfectly and never gives any problem. Good job guys.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@illumeillumeillume approved these changes

@Starbuck5Starbuck5Awaiting requested review from Starbuck5

+3 more reviewers

@lordmauvelordmauvelordmauve left review comments

@dr0iddr0iddr0id approved these changes

@ankith26ankith26ankith26 approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

enhancementmathpygame.mathNew APIThis pull request may need extra debate as it adds a new class or function to pygame

Projects

None yet

Milestone

2.1.3

Development

Successfully merging this pull request may close these issues.

Add pygame.Vector2.move_towards()

8 participants

@andrewhong04@Starbuck5@VegaPac@illume@dr0id@lordmauve@ankith26@MyreMylar

[8]ページ先頭

©2009-2025 Movatter.jp