X Tutup
Skip to content

Improve IsNormalized() in C##108974

Merged
Repiteo merged 1 commit intogodotengine:masterfrom
Joy-less:Improve-`IsNormalized()`
Sep 22, 2025
Merged

Improve IsNormalized() in C##108974
Repiteo merged 1 commit intogodotengine:masterfrom
Joy-less:Improve-`IsNormalized()`

Conversation

@Joy-less
Copy link
Contributor

@Joy-less Joy-less commented Jul 25, 2025

These are some minor clarity improvements for the IsNormalized() implementations in C# to make them easier to understand.
These now match the C++ implementations:

return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON);

return Math::is_equal_approx(length_squared(), 1, (real_t)UNIT_EPSILON); //use less epsilon

In terms of performance, the differences are minimal. Here's a makeshift benchmark for 1 million iterations:

non-normalized is normalized:
False
normalized is normalized:
True
non-normalized old:
10.6845ms
non-normalized new:
11.6897ms
normalized old:
10.7924ms
normalized new:
9.1759ms

@Joy-less Joy-less requested a review from a team as a code owner July 25, 2025 16:57
@AThousandShips AThousandShips added this to the 4.x milestone Jul 28, 2025
Copy link
Member

@paulloz paulloz 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 your contribution!

The optimization is marginal, but I think this PR makes sense if only to improve consistency across implementations.

@raulsntos raulsntos modified the milestones: 4.x, 4.6 Aug 9, 2025
@Repiteo Repiteo merged commit d8b057d into godotengine:master Sep 22, 2025
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Sep 22, 2025

Thanks!

@Joy-less Joy-less deleted the Improve-`IsNormalized()` branch September 22, 2025 17:14
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.

5 participants

X Tutup