Skip to content

Commit

Permalink
Rewrite curves release note to be more approachable and add a brief n…
Browse files Browse the repository at this point in the history
…ote about color curves (#1844)

Co-authored-by: Rich Churcher <[email protected]>
  • Loading branch information
alice-i-cecile and bas-ie authored Nov 24, 2024
1 parent 29827ed commit 7ff7814
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<!-- A Curve trait for general interoperation — Part I -->
<!-- https://github.com/bevyengine/bevy/pull/14630 -->

The new `Curve` trait provides a shared interface for curves.
The new [`Curve<T>`] trait provides a shared interface for curves, describing how values of type `T` change as we vary a `f32` parameter `t` over some domain.

`Curve<T>` defines a value of some type `T`
parametrized by a nonempty closed interval of real numbers. That parameter could,
for example, represent time, in which case a `Curve<T>` is thought of as a value
of type `T` that changes over time, as in animation. The parameter
could also represent something like distance or displacement, as in gradients and
spatial curves.
What's changing, and the domain that it's changing *over* are both incredibly flexible.
You might choose to set `T` to store anything from position, to damage to colors (like we did to create) a powerful abstraction for [color gradients](https://docs.rs/bevy/0.15.0/bevy/color/struct.ColorCurve.html).

The curves themselves may be defined in a variety of ways. For example, a curve may be:
As we vary the progress parameter `t`, we could be representing time (like for animation),
or something like distance as for curves that are mapped into 2D or 3D space,
or a fraction of progress between a starting and ending value.

## Constructing Curves

Each curve made be defined in a variety of ways. For example, a curve may be:

* defined by a function
* interpolated from samples
* constructed using splines
* produced by an easing function

Additionally, the `Curve` API provides adaptors for taking an existing curve and
modifying its output and/or parametrization. It is similar to the `Iterator`
interface in this way.
Take a look at the constructors on the [`Curve<T>`] trait for more details.

## Modifying curves

Procedurally modifying curves is a powerful tool for both creating curves with the desired behavior and dynamically altering them.

Bevy 0.15 provides a number of flexible adaptors for taking an existing curve and
modifying its output and/or parametrization.

For example:

```rust
let timed_angles = [
(0.0, 0.0),
Expand Down Expand Up @@ -49,11 +57,18 @@ A number of other adaptors are also available. For instance:
* two curves may be chained together to form a longer curve
* two curves may be zipped together to form a curve valued in tuples

The interface additionally provides facilities for rasterization. These allow
a curve to be resampled into an approximation derived from sample interpolation
on the original curve; in practice, this is useful when curves of diverse origin
need to be made uniform at the level of data - e.g. in serialization or when
applying numerical methods.
## Sampling from curves

Sampling is the process of asking "what is the value of this curve at some particular value of `t`".
Doing so is simple: just call [`Curve::sample`]!

Much like how vector graphics can be rasterized into pixels, curves can be rasterized into regular, discretized intervals.
By resampling into an approximation derived from sample interpolation
on the original curve, we can make curves of diverse origin
uniform at the level of data.

While this may seem exotic, this technique is critical for serializing curves or
approximating properties via numerical methods.

```rust
// A curve defined by a function, which may be challenging to store as data.
Expand All @@ -66,3 +81,6 @@ let exponential_curve = FunctionCurve::new(
// Internally, this just holds the samples and the parameter interval.
let raster_curve = exponential_curve.resample_auto(100).unwrap();
```

[`Curve<T>`]: https://docs.rs/bevy/0.15.0/bevy/math/trait.Curve.html
[`Curve::sample`]: https://docs.rs/bevy/0.15.0/bevy/math/trait.Curve.html#method.sample
11 changes: 2 additions & 9 deletions release-content/0.15/release-notes/_release-notes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ file_name = "15320_Retained_Rendering.md"
[[release_notes]]
title = "The Curve Trait"
authors = ["@mweatherley"]
contributors = ["@alice-i-cecile"]
prs = [14630]
contributors = ["@alice-i-cecile", "@RobWalt", "@mockersf", "@cart"]
prs = [14630, 14976, 15675, 16637]
file_name = "14630_A_Curve_trait_for_general_interoperation__Part_I.md"

[[release_notes]]
Expand All @@ -170,13 +170,6 @@ contributors = []
prs = [14106]
file_name = "14106_Cyclic_splines.md"

[[release_notes]]
title = "Color gradient curve"
authors = ["@RobWalt"]
contributors = ["@bushrat011899", "@mweatherley"]
prs = [14976]
file_name = "14976_Color_gradient_curve.md"

[[release_notes]]
title = "reflect: implement the unique reflect rfc"
authors = ["@soqb"]
Expand Down

0 comments on commit 7ff7814

Please sign in to comment.