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

Vector2/Vector3: Add squared distance. #2376

Merged
merged 1 commit into from
Mar 9, 2022

Conversation

AnilBK
Copy link
Contributor

@AnilBK AnilBK commented Mar 9, 2022

Needed to sort polygons with distance to camera. In such cases, where we just do comparisons, squared distance seems good.
Might be useful as a general API.

Not sure if this is considered bloat, but as we can see vector2/3 has length and squared length functions.

raylib/src/raymath.h

Lines 249 to 263 in 43dbe67

// Calculate vector length
RMAPI float Vector2Length(Vector2 v)
{
float result = sqrtf((v.x*v.x) + (v.y*v.y));
return result;
}
// Calculate vector square length
RMAPI float Vector2LengthSqr(Vector2 v)
{
float result = (v.x*v.x) + (v.y*v.y);
return result;
}

@raysan5 raysan5 merged commit cda1324 into raysan5:master Mar 9, 2022
@raysan5
Copy link
Owner

raysan5 commented Mar 9, 2022

@AnilBK I consider it a bit bloat but I'm adding it...

@AnilBK
Copy link
Contributor Author

AnilBK commented Mar 9, 2022

Thanks. <3
Will surely contribute to no bloat stuffs, if I can :D

@AnilBK AnilBK deleted the add-distance-squared branch March 9, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants