From 8d2df5491ed7820a20ca45a611bfb034d73324b4 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Mon, 15 Jul 2024 11:20:22 +0200 Subject: [PATCH] Remove some debug asserts (#4826) * Closes https://github.com/emilk/egui/issues/4825 --- crates/ecolor/src/color32.rs | 4 ++-- crates/egui/src/layout.rs | 2 -- crates/egui/src/placer.rs | 5 ++++- crates/egui/src/ui.rs | 3 ++- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/ecolor/src/color32.rs b/crates/ecolor/src/color32.rs index 4e7153dc1b8..ca257303dae 100644 --- a/crates/ecolor/src/color32.rs +++ b/crates/ecolor/src/color32.rs @@ -201,7 +201,7 @@ impl Color32 { /// This is perceptually even, and faster that [`Self::linear_multiply`]. #[inline] pub fn gamma_multiply(self, factor: f32) -> Self { - debug_assert!(0.0 <= factor && factor <= 1.0); + debug_assert!(0.0 <= factor && factor.is_finite()); let Self([r, g, b, a]) = self; Self([ (r as f32 * factor + 0.5) as u8, @@ -217,7 +217,7 @@ impl Color32 { /// You likely want to use [`Self::gamma_multiply`] instead. #[inline] pub fn linear_multiply(self, factor: f32) -> Self { - debug_assert!(0.0 <= factor && factor <= 1.0); + debug_assert!(0.0 <= factor && factor.is_finite()); // As an unfortunate side-effect of using premultiplied alpha // we need a somewhat expensive conversion to linear space and back. Rgba::from(self).multiply(factor).into() diff --git a/crates/egui/src/layout.rs b/crates/egui/src/layout.rs index 15ed2fef079..a303509de5d 100644 --- a/crates/egui/src/layout.rs +++ b/crates/egui/src/layout.rs @@ -417,7 +417,6 @@ impl Layout { pub(crate) fn region_from_max_rect(&self, max_rect: Rect) -> Region { debug_assert!(!max_rect.any_nan()); - debug_assert!(max_rect.is_finite()); let mut region = Region { min_rect: Rect::NOTHING, // temporary max_rect, @@ -452,7 +451,6 @@ impl Layout { fn available_from_cursor_max_rect(&self, cursor: Rect, max_rect: Rect) -> Rect { debug_assert!(!cursor.any_nan()); debug_assert!(!max_rect.any_nan()); - debug_assert!(max_rect.is_finite()); // NOTE: in normal top-down layout the cursor has moved below the current max_rect, // but the available shouldn't be negative. diff --git a/crates/egui/src/placer.rs b/crates/egui/src/placer.rs index 0be6b413b22..f83076f02c9 100644 --- a/crates/egui/src/placer.rs +++ b/crates/egui/src/placer.rs @@ -106,7 +106,10 @@ impl Placer { /// This is what you then pass to `advance_after_rects`. /// Use `justify_and_align` to get the inner `widget_rect`. pub(crate) fn next_space(&self, child_size: Vec2, item_spacing: Vec2) -> Rect { - debug_assert!(child_size.is_finite() && child_size.x >= 0.0 && child_size.y >= 0.0); + debug_assert!( + 0.0 <= child_size.x && 0.0 <= child_size.y, + "Negative child size: {child_size:?}" + ); self.region.sanity_check(); if let Some(grid) = &self.grid { grid.next_cell(self.region.cursor, child_size) diff --git a/crates/egui/src/ui.rs b/crates/egui/src/ui.rs index 2454c7cb1b6..18f6bff4399 100644 --- a/crates/egui/src/ui.rs +++ b/crates/egui/src/ui.rs @@ -1144,6 +1144,7 @@ impl Ui { } /// Allocated the given rectangle and then adds content to that rectangle. + /// /// If the contents overflow, more space will be allocated. /// When finished, the amount of space actually used (`min_rect`) will be allocated. /// So you can request a lot of space and then use less. @@ -2607,7 +2608,7 @@ impl Ui { /// }); /// # }); /// ``` - /// + /// /// /// See also: [`Self::close_menu`] and [`Response::context_menu`]. #[inline]