Skip to content

Commit

Permalink
Put curve-related stuff behind a feature (#15790)
Browse files Browse the repository at this point in the history
# Objective

A bunch of code is used only if you care about the `Curve` trait. Put it
behind a feature so it can be ignored if wanted.

## Solution

Added a default feature `curve` to `bevy_math` which feature-gates the
`curve` module and internal integrations.

## Testing

Tested compiling with the feature enabled and disabled.
  • Loading branch information
mweatherley authored Oct 9, 2024
1 parent 7d40e3e commit 123a19a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
5 changes: 3 additions & 2 deletions crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ rand = { version = "0.8", features = [
], default-features = false, optional = true }
rand_distr = { version = "0.4.3", optional = true }
smallvec = { version = "1.11" }

bevy_reflect = { path = "../bevy_reflect", version = "0.15.0-dev", features = [
"glam",
], optional = true }
Expand All @@ -41,7 +40,7 @@ bevy_math = { path = ".", version = "0.15.0-dev", features = ["approx"] }
glam = { version = "0.29", features = ["approx"] }

[features]
default = ["rand", "bevy_reflect"]
default = ["rand", "bevy_reflect", "curve"]
serialize = ["dep:serde", "glam/serde"]
# Enable approx for glam types to approximate floating point equality comparisons and assertions
approx = ["dep:approx", "glam/approx"]
Expand All @@ -56,6 +55,8 @@ glam_assert = ["glam/glam-assert"]
debug_glam_assert = ["glam/debug-glam-assert"]
# Enable the rand dependency for shape_sampling
rand = ["dep:rand", "dep:rand_distr", "glam/rand"]
# Include code related to the Curve trait
curve = []

[lints]
workspace = true
Expand Down
13 changes: 8 additions & 5 deletions crates/bevy_math/src/cubic_splines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

use core::{fmt::Debug, iter::once};

use crate::{
curve::{Curve, Interval},
ops::FloatPow,
Vec2, VectorSpace,
};
use crate::{ops::FloatPow, Vec2, VectorSpace};

use derive_more::derive::{Display, Error};
use itertools::Itertools;

#[cfg(feature = "curve")]
use crate::curve::{Curve, Interval};

#[cfg(feature = "bevy_reflect")]
use bevy_reflect::{std_traits::ReflectDefault, Reflect};

Expand Down Expand Up @@ -1062,6 +1061,7 @@ impl CubicSegment<Vec2> {
}
}

#[cfg(feature = "curve")]
impl<P: VectorSpace> Curve<P> for CubicSegment<P> {
#[inline]
fn domain(&self) -> Interval {
Expand Down Expand Up @@ -1199,6 +1199,7 @@ impl<P: VectorSpace> CubicCurve<P> {
}
}

#[cfg(feature = "curve")]
impl<P: VectorSpace> Curve<P> for CubicCurve<P> {
#[inline]
fn domain(&self) -> Interval {
Expand Down Expand Up @@ -1370,6 +1371,7 @@ impl<P: VectorSpace> RationalSegment<P> {
}
}

#[cfg(feature = "curve")]
impl<P: VectorSpace> Curve<P> for RationalSegment<P> {
#[inline]
fn domain(&self) -> Interval {
Expand Down Expand Up @@ -1526,6 +1528,7 @@ impl<P: VectorSpace> RationalCurve<P> {
}
}

#[cfg(feature = "curve")]
impl<P: VectorSpace> Curve<P> for RationalCurve<P> {
#[inline]
fn domain(&self) -> Interval {
Expand Down
20 changes: 14 additions & 6 deletions crates/bevy_math/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ pub mod bounding;
pub mod common_traits;
mod compass;
pub mod cubic_splines;
pub mod curve;
mod direction;
mod float_ord;
mod isometry;
Expand All @@ -26,24 +25,30 @@ pub mod primitives;
mod ray;
mod rects;
mod rotation2d;

#[cfg(feature = "curve")]
pub mod curve;

#[cfg(feature = "rand")]
pub mod sampling;
pub use compass::{CompassOctant, CompassQuadrant};

pub use affine3::*;
pub use aspect_ratio::AspectRatio;
pub use common_traits::*;
pub use compass::{CompassOctant, CompassQuadrant};
pub use direction::*;
pub use float_ord::*;
pub use isometry::{Isometry2d, Isometry3d};
pub use ops::FloatPow;
pub use ray::{Ray2d, Ray3d};
pub use rects::*;
pub use rotation2d::Rot2;

#[cfg(feature = "curve")]
pub use curve::Curve;

#[cfg(feature = "rand")]
pub use sampling::FromRng;
#[cfg(feature = "rand")]
pub use sampling::ShapeSample;
pub use sampling::{FromRng, ShapeSample};

/// The math prelude.
///
Expand All @@ -56,7 +61,6 @@ pub mod prelude {
CubicHermite, CubicNurbs, CubicNurbsError, CubicSegment, CyclicCubicGenerator,
RationalCurve, RationalGenerator, RationalSegment,
},
curve::*,
direction::{Dir2, Dir3, Dir3A},
ops,
primitives::*,
Expand All @@ -65,6 +69,10 @@ pub mod prelude {
UVec2, UVec3, UVec4, Vec2, Vec2Swizzles, Vec3, Vec3Swizzles, Vec4, Vec4Swizzles,
};

#[doc(hidden)]
#[cfg(feature = "curve")]
pub use crate::curve::*;

#[doc(hidden)]
#[cfg(feature = "rand")]
pub use crate::sampling::{FromRng, ShapeSample};
Expand Down

0 comments on commit 123a19a

Please sign in to comment.