From e4acbe17536b9993563cc75d21b6523e1687536c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Mockers?= Date: Sat, 13 Mar 2021 17:13:32 +0100 Subject: [PATCH] use std clamp --- crates/bevy_core/src/task_pool_options.rs | 9 +++------ crates/bevy_math/src/clamp.rs | 19 ------------------- crates/bevy_math/src/lib.rs | 2 -- .../bevy_sprite/src/texture_atlas_builder.rs | 4 ++-- 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 crates/bevy_math/src/clamp.rs diff --git a/crates/bevy_core/src/task_pool_options.rs b/crates/bevy_core/src/task_pool_options.rs index 80b9ad7f78023..19c9dad5bfe2f 100644 --- a/crates/bevy_core/src/task_pool_options.rs +++ b/crates/bevy_core/src/task_pool_options.rs @@ -27,7 +27,7 @@ impl TaskPoolThreadAssignmentPolicy { // Clamp by min_threads, max_threads. (This may result in us using more threads than are // available, this is intended. An example case where this might happen is a device with // <= 2 threads. - bevy_math::clamp(desired, self.min_threads, self.max_threads) + desired.clamp(self.min_threads, self.max_threads) } } @@ -94,11 +94,8 @@ impl DefaultTaskPoolOptions { /// Inserts the default thread pools into the given resource map based on the configured values pub fn create_default_pools(&self, world: &mut World) { - let total_threads = bevy_math::clamp( - bevy_tasks::logical_core_count(), - self.min_total_threads, - self.max_total_threads, - ); + let total_threads = + bevy_tasks::logical_core_count().clamp(self.min_total_threads, self.max_total_threads); trace!("Assigning {} cores to default task pools", total_threads); let mut remaining_threads = total_threads; diff --git a/crates/bevy_math/src/clamp.rs b/crates/bevy_math/src/clamp.rs deleted file mode 100644 index 92807e54f179e..0000000000000 --- a/crates/bevy_math/src/clamp.rs +++ /dev/null @@ -1,19 +0,0 @@ -/// A value bounded by a minimum and a maximum -/// -/// If input is less than min then this returns min. -/// If input is greater than max then this returns max. -/// Otherwise this returns input. -/// -/// **Panics** in debug mode if `!(min <= max)`. -/// -/// Original implementation from num-traits licensed as MIT -pub fn clamp(input: T, min: T, max: T) -> T { - debug_assert!(min <= max, "min must be less than or equal to max"); - if input < min { - min - } else if input > max { - max - } else { - input - } -} diff --git a/crates/bevy_math/src/lib.rs b/crates/bevy_math/src/lib.rs index 12a2579f97841..f7315b35d50be 100644 --- a/crates/bevy_math/src/lib.rs +++ b/crates/bevy_math/src/lib.rs @@ -1,8 +1,6 @@ -mod clamp; mod face_toward; mod geometry; -pub use clamp::*; pub use face_toward::*; pub use geometry::*; pub use glam::*; diff --git a/crates/bevy_sprite/src/texture_atlas_builder.rs b/crates/bevy_sprite/src/texture_atlas_builder.rs index 7957c52759f9e..0c8fcc85641ff 100644 --- a/crates/bevy_sprite/src/texture_atlas_builder.rs +++ b/crates/bevy_sprite/src/texture_atlas_builder.rs @@ -177,8 +177,8 @@ impl TextureAtlasBuilder { Some(rect_placements) } Err(rectangle_pack::RectanglePackError::NotEnoughBinSpace) => { - current_height = bevy_math::clamp(current_height * 2, 0, max_height); - current_width = bevy_math::clamp(current_width * 2, 0, max_width); + current_height = (current_height * 2).clamp(0, max_height); + current_width = (current_width * 2).clamp(0, max_width); None } };