Remove some debug asserts (#4826)

* Closes https://github.com/emilk/egui/issues/4825
This commit is contained in:
Emil Ernerfeldt 2024-07-15 11:20:22 +02:00 committed by GitHub
parent 1bee7bfefa
commit 8d2df5491e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 8 additions and 6 deletions

View File

@ -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()

View File

@ -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.

View File

@ -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)

View File

@ -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]