From 58ebb217dcc97e3ccf2b86197868b8f9f5da8c55 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 20 Apr 2021 10:05:47 +0200 Subject: [PATCH] Tesselator: ignore zero-sized clip rects Improves https://github.com/emilk/egui/issues/328 --- egui/src/layout.rs | 4 ++-- emath/src/rect.rs | 13 +++++++++---- epaint/src/tessellator.rs | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/egui/src/layout.rs b/egui/src/layout.rs index ef9e0403..383b8a83 100644 --- a/egui/src/layout.rs +++ b/egui/src/layout.rs @@ -333,7 +333,7 @@ impl Layout { impl Layout { pub fn align_size_within_rect(&self, size: Vec2, outer: Rect) -> Rect { debug_assert!(size.x >= 0.0 && size.y >= 0.0); - debug_assert!(outer.is_non_negative()); + debug_assert!(!outer.is_negative()); self.align2().align_size_within_rect(size, outer) } @@ -571,7 +571,7 @@ impl Layout { /// Apply justify (fill width/height) and/or alignment after calling `next_space`. pub(crate) fn justify_and_align(&self, frame: Rect, mut child_size: Vec2) -> Rect { debug_assert!(child_size.x >= 0.0 && child_size.y >= 0.0); - debug_assert!(frame.is_non_negative()); + debug_assert!(!frame.is_negative()); if self.horizontal_justify() { child_size.x = child_size.x.at_least(frame.width()); // fill full width diff --git a/emath/src/rect.rs b/emath/src/rect.rs index 7875cd5c..1073c22b 100644 --- a/emath/src/rect.rs +++ b/emath/src/rect.rs @@ -297,16 +297,21 @@ impl Rect { self.max.x < self.min.x || self.max.y < self.min.y } - /// `max.x < min.x` or `max.y < min.y`. + /// `width < 0 || height < 0` #[inline(always)] pub fn is_negative(&self) -> bool { self.max.x < self.min.x || self.max.y < self.min.y } - /// `min.x <= max.x && min.y <= max.y`. - #[inline(always)] + #[deprecated = "Use !is_negative() instead"] pub fn is_non_negative(&self) -> bool { - self.min.x <= self.max.x && self.min.y <= self.max.y + !self.is_negative() + } + + /// `width > 0 && height > 0` + #[inline(always)] + pub fn is_positive(&self) -> bool { + self.min.x < self.max.x && self.min.y < self.max.y } /// True if all members are also finite. diff --git a/epaint/src/tessellator.rs b/epaint/src/tessellator.rs index 135e219f..6292a322 100644 --- a/epaint/src/tessellator.rs +++ b/epaint/src/tessellator.rs @@ -742,7 +742,7 @@ pub fn tessellate_shapes( let mut clipped_meshes: Vec = Vec::default(); for ClippedShape(clip_rect, shape) in shapes { - if !clip_rect.is_non_negative() { + if !clip_rect.is_positive() { continue; // skip empty clip rectangles }