mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -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:
@@ -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);
|
||||
|
||||
|
||||
@@ -84,7 +84,10 @@ impl Rot2 {
|
||||
c: self.c / l,
|
||||
s: self.s / l,
|
||||
};
|
||||
debug_assert!(ret.is_finite());
|
||||
debug_assert!(
|
||||
ret.is_finite(),
|
||||
"Rot2::normalized produced a non-finite result"
|
||||
);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,10 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 {
|
||||
if !max.is_finite() {
|
||||
return min;
|
||||
}
|
||||
debug_assert!(min.is_finite() && max.is_finite());
|
||||
debug_assert!(
|
||||
min.is_finite() && max.is_finite(),
|
||||
"min: {min:?}, max: {max:?}"
|
||||
);
|
||||
|
||||
let min_exponent = min.log10();
|
||||
let max_exponent = max.log10();
|
||||
@@ -101,7 +104,10 @@ fn from_decimal_string(s: &[i32]) -> f64 {
|
||||
|
||||
/// Find the simplest integer in the range [min, max]
|
||||
fn simplest_digit_closed_range(min: i32, max: i32) -> i32 {
|
||||
debug_assert!(1 <= min && min <= max && max <= 9);
|
||||
debug_assert!(
|
||||
1 <= min && min <= max && max <= 9,
|
||||
"min should be in [1, 9], but was {min:?} and max should be in [min, 9], but was {max:?}"
|
||||
);
|
||||
if min <= 5 && 5 <= max {
|
||||
5
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user