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

A Curve trait for general interoperation — Part II #14700

Merged
merged 25 commits into from
Aug 15, 2024

Conversation

mweatherley
Copy link
Contributor

Objective

Finish what we started in #14630. The Curve RFC is here.

Solution

This contains the rest of the library from my branch. The main things added here are:

  • Bulk sampling / resampling methods on Curve itself
  • Data structures supporting the above
  • The cores submodule that those data structures use to encapsulate sample interpolation

The weirdest thing in here is probably ChunkedUnevenCore in cores, which is not used by anything in the Curve library itself but which is required for efficient storage of glTF animation curves. (See #13105.) We can move it into a different PR if we want to; I don't have strong feelings either way.

Testing

New tests related to resampling are included. As I write this, I realize we could use some tests in cores itself, so I will add some on this branch before too long.

@mweatherley mweatherley added C-Feature A new feature, making something new possible A-Math Fundamental domain-agnostic mathematical operations D-Complex Quite challenging from either a design or technical perspective. Ask for help! A-Cross-Cutting Impacts the entire engine X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 10, 2024
@alice-i-cecile alice-i-cecile added this to the 0.15 milestone Aug 10, 2024
@IQuick143 IQuick143 self-requested a review August 11, 2024 09:38
/// Create a new [`EvenCore`] from the specified `domain` and `samples`. An error is returned
/// if there are not at least 2 samples or if the given domain is unbounded.
#[inline]
pub fn new(domain: Interval, samples: impl Into<Vec<T>>) -> Result<Self, EvenCoreError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

The samples parameter would be more generic if it's defined as impl IntoIterator<Item=T>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah; the point of this is that it's really simple and doesn't require defining an iterator, but I'm becoming increasingly convinced that we should have a version of this that accepts an iterator, at least. That's kind of hairy, though, so I'll leave it to follow-ups.

crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@RobWalt RobWalt left a comment

Choose a reason for hiding this comment

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

Great work and really nice documentation! I like the "sources at the bottom" kind of markdown links!

Most of the review comments are repetitive things where I just tried to catch all the places that need an update.

crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/cores.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@RobWalt RobWalt left a comment

Choose a reason for hiding this comment

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

Just some dogfooding ^^

crates/bevy_math/src/curve/mod.rs Outdated Show resolved Hide resolved
crates/bevy_math/src/curve/mod.rs Outdated Show resolved Hide resolved
///
/// # Invariants
/// This must always have a length of at least 2.
pub samples: Vec<T>,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not thrilled with leaving this as a pub field with invariants to uphold, but there's already some serious Here There Be Dragons vibes from this code, so I don't think this is a big footgun.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm not necessarily huge on it either, but I didn't really see a good alternative. As far as I can tell, the best thing to do is to signal as best we can that this module is primarily for library authors (e.g. with its docs, excluding it from reexports, and so on).


impl<T> EvenCore<T> {
/// Create a new [`EvenCore`] from the specified `domain` and `samples`. An error is returned
/// if there are not at least 2 samples or if the given domain is unbounded.
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this give an error if the samples are not evenly spaced, or am I misunderstanding something?

Copy link
Member

Choose a reason for hiding this comment

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

Actually checking this seems prohibitively expensive, but a debug_assert or something might be useful? If nothing else, a note in the docs about why this isn't checked (and in the associated error type) would be nice.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this give an error if the samples are not evenly spaced, or am I misunderstanding something?

I think the Even refers just to the time axis. It's an Interval which will be cut up into samples.len() - 1 evenly sized chunks.

Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

I have a few quibbles, but nothing blocking. I'd love to see practical end-to-end examples of these APIs for users, but that can wait: the existing tests are helpful to convince me that it plumbs together properly.

@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Aug 15, 2024
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Aug 15, 2024
Merged via the queue into bevyengine:main with commit 20a9b92 Aug 15, 2024
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Cross-Cutting Impacts the entire engine A-Math Fundamental domain-agnostic mathematical operations C-Feature A new feature, making something new possible D-Complex Quite challenging from either a design or technical perspective. Ask for help! S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it X-Blessed Has a large architectural impact or tradeoffs, but the design has been endorsed by decision makers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants