1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 06:40:06 -04:00

Add assert messages and print bad argument values in asserts (#5216)

Enabled the `missing_assert_message` lint

* [x] I have followed the instructions in the PR template

---------

Co-authored-by: Lucas Meurer <lucasmeurer96@gmail.com>
This commit is contained in:
Nicolas
2025-03-25 09:20:29 +01:00
committed by GitHub
parent 903bd81313
commit 58b2ac88c0
35 changed files with 331 additions and 108 deletions

View File

@@ -149,7 +149,10 @@ where
{
let from = from.into();
let to = to.into();
debug_assert!(from.start() != from.end());
debug_assert!(
from.start() != from.end(),
"from.start() and from.end() should not be equal"
);
let t = (x - *from.start()) / (*from.end() - *from.start());
lerp(to, t)
}
@@ -173,7 +176,10 @@ where
} else if *from.end() <= x {
*to.end()
} else {
debug_assert!(from.start() != from.end());
debug_assert!(
from.start() != from.end(),
"from.start() and from.end() should not be equal"
);
let t = (x - *from.start()) / (*from.end() - *from.start());
// Ensure no numerical inaccuracies sneak in:
if T::ONE <= t {
@@ -200,8 +206,14 @@ pub fn format_with_minimum_decimals(value: f64, decimals: usize) -> String {
pub fn format_with_decimals_in_range(value: f64, decimal_range: RangeInclusive<usize>) -> String {
let min_decimals = *decimal_range.start();
let max_decimals = *decimal_range.end();
debug_assert!(min_decimals <= max_decimals);
debug_assert!(max_decimals < 100);
debug_assert!(
min_decimals <= max_decimals,
"min_decimals should be <= max_decimals, but got min_decimals: {min_decimals}, max_decimals: {max_decimals}"
);
debug_assert!(
max_decimals < 100,
"max_decimals should be < 100, but got {max_decimals}"
);
let max_decimals = max_decimals.min(16);
let min_decimals = min_decimals.min(max_decimals);