1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 05:10:03 -04:00

Remove extra_asserts and extra_debug_asserts feature flags (#4478)

Removes `egui_assert` etc and replaces it with normal `debug_assert`
calls.

Previously you could opt-in to more runtime checks using feature flags.
Now these extra runtime checks are always enabled for debug builds.

You are most likely to encounter them if you use negative sizes or NaNs
or other similar bugs.
These usually indicate bugs in user space.
This commit is contained in:
Emil Ernerfeldt
2024-05-10 19:39:08 +02:00
committed by GitHub
parent 155e138998
commit f19f99180e
32 changed files with 90 additions and 182 deletions

View File

@@ -126,7 +126,7 @@ where
/// Values must be added with a monotonically increasing time, or at least not decreasing.
pub fn add(&mut self, now: f64, value: T) {
if let Some((last_time, _)) = self.values.back() {
crate::emath_assert!(now >= *last_time, "Time shouldn't move backwards");
debug_assert!(*last_time <= now, "Time shouldn't move backwards");
}
self.total_count += 1;
self.values.push_back((now, value));

View File

@@ -146,7 +146,7 @@ where
{
let from = from.into();
let to = to.into();
crate::emath_assert!(from.start() != from.end());
debug_assert!(from.start() != from.end());
let t = (x - *from.start()) / (*from.end() - *from.start());
lerp(to, t)
}
@@ -170,7 +170,7 @@ where
} else if *from.end() <= x {
*to.end()
} else {
crate::emath_assert!(from.start() != from.end());
debug_assert!(from.start() != from.end());
let t = (x - *from.start()) / (*from.end() - *from.start());
// Ensure no numerical inaccuracies sneak in:
if T::ONE <= t {
@@ -194,8 +194,8 @@ 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();
crate::emath_assert!(min_decimals <= max_decimals);
crate::emath_assert!(max_decimals < 100);
debug_assert!(min_decimals <= max_decimals);
debug_assert!(max_decimals < 100);
let max_decimals = max_decimals.min(16);
let min_decimals = min_decimals.min(max_decimals);
@@ -430,19 +430,3 @@ pub fn ease_in_ease_out(t: f32) -> f32 {
let t = t.clamp(0.0, 1.0);
(3.0 * t * t - 2.0 * t * t * t).clamp(0.0, 1.0)
}
// ----------------------------------------------------------------------------
/// An assert that is only active when `emath` is compiled with the `extra_asserts` feature
/// or with the `extra_debug_asserts` feature in debug builds.
#[macro_export]
macro_rules! emath_assert {
($($arg: tt)*) => {
if cfg!(any(
feature = "extra_asserts",
all(feature = "extra_debug_asserts", debug_assertions),
)) {
assert!($($arg)*);
}
}
}

View File

@@ -84,7 +84,7 @@ impl Rot2 {
c: self.c / l,
s: self.s / l,
};
crate::emath_assert!(ret.is_finite());
debug_assert!(ret.is_finite());
ret
}
}

View File

@@ -33,7 +33,7 @@ pub fn best_in_range_f64(min: f64, max: f64) -> f64 {
if !max.is_finite() {
return min;
}
crate::emath_assert!(min.is_finite() && max.is_finite());
debug_assert!(min.is_finite() && max.is_finite());
let min_exponent = min.log10();
let max_exponent = max.log10();
@@ -82,7 +82,7 @@ fn is_integer(f: f64) -> bool {
}
fn to_decimal_string(v: f64) -> [i32; NUM_DECIMALS] {
crate::emath_assert!(v < 10.0, "{:?}", v);
debug_assert!(v < 10.0, "{v:?}");
let mut digits = [0; NUM_DECIMALS];
let mut v = v.abs();
for r in &mut digits {
@@ -104,7 +104,7 @@ 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 {
crate::emath_assert!(1 <= min && min <= max && max <= 9);
debug_assert!(1 <= min && min <= max && max <= 9);
if min <= 5 && 5 <= max {
5
} else {