-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Allow clamping vectors and colors in addition to floats and ints #45624
Conversation
@aaronfranke: btw, WDYT about setting standard |
@Chaosus No objection, and if done for |
@Chaosus I implemented your idea of having the clamp defaults be 0 to 1 everywhere (see the 3rd commit in this PR, I had to add a new macro to EDIT: This has been reverted, now the PR is only 2 commits. For reference, here was that third commit: aaronfranke@9e04100 |
Yeah, I think it's useful in some cases - this actually what |
I think the syntax should be fixed before merge:
|
@AndreaCatania Maybe. None of the exposed struct methods mutate the struct. We also have |
@aaronfranke While for some of them I would not do that (like However, we already have:
So I think that |
@AndreaCatania If there was both |
@aaronfranke Though, I think that I would use it extensively: func _process(delta):
velocity.clamp(max_velocity, max_velocity) Which is much better than: func _process(delta):
velocity = velocity.clamp(max_velocity, max_velocity) That also performs more operations for no reason. |
Do any of these operations run by default and destroy HDR (< 0 and > 1) values? |
@fire No, none of these run by default. The clamp methods only run if you explicitly call |
Thanks! |
Implements and closes #13926. Specifically, implements the API described in this comment in both core and C#:
Rename
Vector2.clamped
toVector2.limit_length
. I also gave it a default value of1.0
.Add
Vector3.limit_length
to be consistent withVector2
. This part closes Add "clamped" method to Vector3 #30058.Add
Vector2.clamp(min, max)
wheremin
andmax
are of typeVector2
.Add
Vector2i.clamp(min, max)
wheremin
andmax
are of typeVector2i
.Add
Vector3.clamp(min, max)
wheremin
andmax
are of typeVector3
.Add
Vector3i.clamp(min, max)
wheremin
andmax
are of typeVector3i
.Add
Color.clamp(min, max)
wheremin
andmax
are of typeColor
.Color.clamp
has default values ofmin = Color(0, 0, 0, 0)
andmax = Color(1, 1, 1, 1)
, since clamping a color to this range seems like it would be a relatively common operation. You can also specify onlymin
asColor.black
to clamp to non-transparent colors, since black isColor(0, 0, 0, 1)
and so alpha will always be 1.This PR used to have 3 commits, but the third was un-done. For reference, here was that third commit: aaronfranke@9e04100