-
-
Notifications
You must be signed in to change notification settings - Fork 23.3k
Add static method from_scalar
to vector 2/3 types.
#109692
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
Conversation
f9def70
to
771f81f
Compare
Why is this needed for your project? Historically, we've been explicit on casting vectors. Can you write a proposal for this enhancement? |
771f81f
to
996e4a8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
|
It's nearly the same as using the constructors, no need to write a proposal unless it proves it's useful. @tool
extends Node2D
func _ready() -> void:
var time: int = Time.get_ticks_msec()
for i in 10000000:
var v1 = Vector2(78 * 2.558, 78 * 2.558)
var v2 = Vector2(1, 1) * 255.867 * sqrt(2)
var f = sqrt(4) * 45.5
var v3 = Vector2(f, f)
print("Time Before: ", Time.get_ticks_msec() - time)
time = Time.get_ticks_msec()
for i in 10000000:
var v1 = Vector2.from_scalar(78 * 2.558)
var v2 = Vector2.from_scalar(255.867 * sqrt(2))
var v3 = Vector2.from_scalar(sqrt(4) * 45.5)
print("Time After: ", Time.get_ticks_msec() - time) Time Before: 6868 |
Why not for |
I didn’t add it because I couldn’t find any use cases for it in the Godot source at the time. Of course, if you think it would be useful, it can definitely be added, I just wanted to avoid introducing extra API that might not get used. |
I think it would be the most useful there and it'd be very confusing to have it in two but not the third |
|
Can be optionally implemented later after #110743. |
Refactors vector initializations by replacing repeated scalar arguments and redundant operations with
from_scalar
, making the code shorter, easier to read, and slightly more efficient.A shorter, more concise name would be appreciated, such as
fill
,splat
, oruniform
.Use cases:
Size2i(options6.ShadingRateImageTileSize, options6.ShadingRateImageTileSize)
Size2i::from_scalar(options6.ShadingRateImageTileSize)
Vector3::from_scalar(cascade.cell_size * probe_cells);