Curve implementation for cubic curves#13068
Closed
mweatherley wants to merge 7 commits intobevyengine:mainfrom
Closed
Curve implementation for cubic curves#13068mweatherley wants to merge 7 commits intobevyengine:mainfrom
Curve implementation for cubic curves#13068mweatherley wants to merge 7 commits intobevyengine:mainfrom
Conversation
Curve implementation for cubic curves
IQuick143
reviewed
May 8, 2024
| } | ||
|
|
||
| /// A trait for marker types which express the level of the curves they can provide. | ||
| pub trait Smoothness: Clone + Copy {} |
Contributor
Author
|
Killing this in favor of #14306. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is an in-progress prototype implementation of
Curvefor the geometric curves created inbevy_math. Everything here is subject to heavy renaming; I just wanted to get something functional up and running. Notably, this design presently excludes NURBS curves, which is a whole new bag of worms.Objective
Add support for returning data in the form of a
Curve(in the sense of the curve-trait RFC) to thebevy_mathcubic curves.The output data of these curves is somewhat stratified. For example, the output of the
CubicBezierbuilder has very few guarantees on its output compared toCubicBSpline; in the first case, it doesn't make too much sense to ask about derivatives globally, in general (since there is no reason for them to match up between segments), whereas in the latter, one always has globally valid first and second derivatives. The aim is for the API to reflect this in some way without getting in the user's way excessively.Solution
Technical changes
This particular prototype represents, essentially, the most "overengineered" part of the solution space, since it provides explicit type-level safeguards that prevent users from, for instance, accessing a
Curveholding both the position and velocity for curve constructions which are not globally C1 (although this limitation can be bypassed). It consists of a number of moving parts to accomplish this:CubicCurvenow has a second parameter which serves as a marker. This is limited to a set of marker types which satisfy a marker trait,Smoothness, and the set of all of them consists ofNoGuarantees,C0,C1, andC2.TinCurve<T>; these combine position, velocity, and acceleration data into convenient packages to be used together; e.g.:ToC1Curveis implemented by anyCubicCurvewith a marker value at least C1 (so,C1andC2in that case):Smoothnessparameter can be raised explicitly by usingblessfunctions which otherwise have no effect. This allows, for example,C1data to be accessed on a curve whose continuity of derivatives cannot be guaranteed at the type level (either for hacky reasons or because the type jsut fails to capture enough knowledge); these have signatures that end up looking like this (although they are actually implemented using traits):Usage
What this actually ends up looking like for users is this; let's suppose, for example, that we want to extract a
Curvefrom a cubic B-spline:On the other hand, suppose that we have something like a Hermite interpolation:
(As you can see, the terminology is presently quite suboptimal.)
Changelog
Migration Guide
Any external code explicitly using the
CubicCurvetype (e.g. as part of a Component) will need to be demarcated with a marker type depending on how it is used.Discussion
As I wrote above, this feels slightly overengineered to me, and the places where that actually comes through negatively, in my opinion, are:
C0Data,C1Data, etc. bundling doesn't feel necessarily natural from a user perspective (especially with names liketo_curve_c1, but perhaps that can be remedied somehow).Another direction I could see going with this is just not bundling the position/velocity/acceleration data together, and instead just having separate methods splitting out
Curve<P>s for the position, velocity, and acceleration separately. This has the advantage that it requires potentially less interfacing with technical jargon, but users would often need to zip the data together to use it in other processes (e.g. basically anything that requires the velocity would probably require position as well). Of course, this could still be gated behind the "smoothness" bounds in essentially the same way.