-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 CubicCurve::segment_count
+ iter_samples
adjustment
#8711
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Previously, the only way to iterate over an evenly spaced set of points on a CubicCurve was to use one of the iter_* methods. The return value of those methods were bound by &self lifetime, making them unusable in certain contexts. Furthermore, other CubicCurve methods (position, velocity, acceleration) required normalizing `t` over the CubicCurve's internal segment count. There were no way to access this segment count, making those methods pretty much unusable. The newly added `segment_count` allows accessing the segment count. `iter_samples` used to accept a `fn`, a function pointer. This is surprising and contrary to the rust stdlib APIs, which accept `Fn` traits for `Iterator` combinators. `iter_samples` now accepts a `FnMut`.
nicopap
added
C-Performance
A change motivated by improving speed, memory usage or compile times
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
A-Animation
Make things move and change over time
A-Math
Fundamental domain-agnostic mathematical operations
labels
May 29, 2023
alice-i-cecile
approved these changes
May 29, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docs are great, API seems useful and much more idiomatic, lifetimes make sense to me.
nicopap
commented
May 29, 2023
aevyrie
approved these changes
May 30, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Some minor bikeshed/nit feedback. Nice speedup. 🙂
nicopap
added
the
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
label
May 31, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-Animation
Make things move and change over time
A-Math
Fundamental domain-agnostic mathematical operations
C-Performance
A change motivated by improving speed, memory usage or compile times
C-Usability
A targeted quality-of-life change that makes Bevy easier to use
S-Ready-For-Final-Review
This PR has been approved by the community. It's ready for a maintainer to consider merging it
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
CubicCurve
non-iter methodsFnMut
over afn
pointer oniter_samples
build_*_cubic_100_points
benchmark by -45% (this means they are twice as fast)Solution
Previously, the only way to iterate over an evenly spaced set of points on a
CubicCurve
was to use one of theiter_*
methods.The return value of those methods were bound by
&self
lifetime, making them unusable in certain contexts.Furthermore, other
CubicCurve
methods (position
,velocity
,acceleration
) required normalizingt
over theCubicCurve
's internal segment count.There were no way to access this segment count, making those methods pretty much unusable.
The newly added
segment_count
allows accessing the segment count.iter_samples
used to accept afn
, a function pointer. This is surprising and contrary to the rust stdlib APIs, which acceptFn
traits forIterator
combinators.iter_samples
now accepts aFnMut
.I don't trust a bit the bevy benchmark suit, but according to it, this doubles (-45%) the performance on the
build_pos_cubic_100_points
andbuild_accel_cubic_100_points
benchmarks.Changelog
CubicCurve::segments
method to access the underlying segments of a cubic curveCubicCurve::iter_samples
sample_function
argument.