Skip to content

Commit

Permalink
Make BSpline matrix an expression
Browse files Browse the repository at this point in the history
Assembly analysis shows that using an expression instead of applying the
div 6.0 operation using an iterator produces smaller and probably more
efficient code. The division by 6.0 was left in the matrix on all values
to explicitly show that all values are divided by it. Manually
simplifying some values doesn't result in any difference in the compiled code.
Godbolt: https://godbolt.org/z/MMfMhnMsq
  • Loading branch information
JohnTheCoolingFan committed Jan 28, 2024
1 parent 9e50087 commit 7239dd2
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions crates/bevy_math/src/cubic_splines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,13 @@ impl<P: Point> CubicBSpline<P> {
impl<P: Point> CubicGenerator<P> for CubicBSpline<P> {
#[inline]
fn to_curve(&self) -> CubicCurve<P> {
let mut char_matrix = [
[1.0, 4.0, 1.0, 0.0],
[-3.0, 0.0, 3.0, 0.0],
[3.0, -6.0, 3.0, 0.0],
[-1.0, 3.0, -3.0, 1.0],
let char_matrix = [
[1.0 / 6.0, 4.0 / 6.0, 1.0 / 6.0, 0.0 / 6.0],
[-3.0 / 6.0, 0.0 / 6.0, 3.0 / 6.0, 0.0 / 6.0],
[3.0 / 6.0, -6.0 / 6.0, 3.0 / 6.0, 0.0 / 6.0],
[-1.0 / 6.0, 3.0 / 6.0, -3.0 / 6.0, 1.0 / 6.0],
];

char_matrix
.iter_mut()
.for_each(|r| r.iter_mut().for_each(|c| *c /= 6.0));

let segments = self
.control_points
.windows(4)
Expand Down

0 comments on commit 7239dd2

Please sign in to comment.