-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
A Curve trait for general interoperation — Part II #14700
Conversation
Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
…e::reparametrize_linear
628b91a
to
d295abe
Compare
crates/bevy_math/src/curve/cores.rs
Outdated
/// 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> { |
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.
The samples
parameter would be more generic if it's defined as impl IntoIterator<Item=T>
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.
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.
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.
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.
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.
Just some dogfooding ^^
Co-authored-by: Robert Walter <26892280+RobWalt@users.noreply.github.com>
/// | ||
/// # Invariants | ||
/// This must always have a length of at least 2. | ||
pub samples: Vec<T>, |
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.
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.
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.
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).
crates/bevy_math/src/curve/cores.rs
Outdated
|
||
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. |
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.
Shouldn't this give an error if the samples are not evenly spaced, or am I misunderstanding something?
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.
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.
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.
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.
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.
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.
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:
Curve
itselfcores
submodule that those data structures use to encapsulate sample interpolationThe weirdest thing in here is probably
ChunkedUnevenCore
incores
, 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.