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 length and length_squared to Vector2i/3i #53618

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Oct 10, 2021

See godotengine/godot-proposals#2297 (does not close it).

@aaronfranke aaronfranke added this to the 4.0 milestone Oct 10, 2021
@aaronfranke aaronfranke requested a review from a team October 10, 2021 02:44
@aaronfranke aaronfranke requested review from a team as code owners October 10, 2021 02:44
@akien-mga
Copy link
Member

It would be good to add tests to validate that the methods work properly.

modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs Outdated Show resolved Hide resolved
modules/mono/glue/GodotSharp/GodotSharp/Core/Vector3i.cs Outdated Show resolved Hide resolved
doc/classes/Vector3i.xml Outdated Show resolved Hide resolved
doc/classes/Vector3i.xml Outdated Show resolved Hide resolved
Comment on lines 135 to 141
double Vector3i::length() const {
int64_t x2 = x * int64_t(x);
int64_t y2 = y * int64_t(y);
int64_t z2 = z * int64_t(z);

return Math::sqrt(double(x2 + y2 + z2));
}
Copy link
Member

Choose a reason for hiding this comment

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

Could be sqrt of length_squared() I guess unless we're really concerned that it wouldn't be inlined?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was done this way to be consistent with how it's currently done in Vector3, but I agree that it's simpler to just take the sqrt of length_squared(), so updated. I left Vector3 alone.

@akien-mga
Copy link
Member

PR meeting: We decided to only implement length and length_squared for now as the use case for dot/cross and angle methods on integer vectors is not clearly established yet. Can be revisited in the future if that changes.

@aaronfranke aaronfranke changed the title Add cross, dot, angle_to, signed_angle_to, and length to Vector3i Add length and length_squared to Vector2i/3i Jan 6, 2022
@akien-mga akien-mga merged commit e1766da into godotengine:master Jan 7, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants