fix(worldgen): resolve upstream Rust 1.90 Clippy boolean warnings

This commit is contained in:
Ganer
2026-10-23 16:55:08 -05:00
parent 455a9996d2
commit 4b1e298a44
10 changed files with 95 additions and 16 deletions
+2 -2
View File
@@ -471,10 +471,10 @@ impl<'r> BlockSurvivalRegistry<'r> {
.ignition_odds
.get(&state.name)
.is_some_and(|value| *value > 0)
&& !state
&& state
.properties
.get("waterlogged")
.is_some_and(|value| value == "true")
.is_none_or(|value| value != "true")
})
.collect(),
fence_gates: (0..registry.len())
+5 -3
View File
@@ -77,9 +77,11 @@ pub fn back_off_from_edge<W: EdgeBackoffWorld>(
);
world.no_collision(bounds).map_err(EdgeBackoffError::World)
};
if !grounded
&& !(input.fall_distance < step && !can_fall(0.0, 0.0, step - input.fall_distance)?)
{
// Keep the collision query's short circuit: on-ground movement must not
// consume any budget, and an unordered (NaN) fall distance skips it too.
let should_back_off = grounded
|| (input.fall_distance < step && !can_fall(0.0, 0.0, step - input.fall_distance)?);
if !should_back_off {
return Ok(input.movement);
}
let mut x = input.movement.x;
+1 -1
View File
@@ -952,7 +952,7 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
if crate::level::query::axis_of(spread) == crate::level::query::axis_of(from) {
return None;
}
if !(self.multiface_has_face(state, from) && !self.multiface_has_face(state, spread)) {
if !self.multiface_has_face(state, from) || self.multiface_has_face(state, spread) {
return None;
}
let block = self.b.block(state);
+2 -2
View File
@@ -276,8 +276,8 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
if value > 0.175_781_25 {
return;
}
if !(self.speleothem_with(state, Direction::Down)
&& !b.is_block(self.above_state(pos), b.block(state)))
if !self.speleothem_with(state, Direction::Down)
|| b.is_block(self.above_state(pos), b.block(state))
{
return;
}
+2 -1
View File
@@ -565,7 +565,8 @@ impl<L: LevelAccess + ?Sized> Sim<'_, L> {
return;
}
}
let burnout = self.level.dimension() == super::Dimension::Nether && false;
// Nether burnout is intentionally disabled: keep its behavior explicit.
let burnout = false;
let extra = if burnout { -50 } else { 0 };
for (direction, chance) in [
(Direction::East, 300),
@@ -447,7 +447,7 @@ impl<P: FluidPicker, F: PositionalRandom, B: AquiferBlockStates> NoiseBasedAquif
let n = 3. + edge;
if n > 0. { n / 3. } else { n / 10. }
};
let barrier = if q < -2. || q > 2. {
let barrier = if pressure_outside_interval(q) {
0.
} else {
if memo.is_nan() {
@@ -603,6 +603,35 @@ impl<P: FluidPicker, F: PositionalRandom, B: AquiferBlockStates> NoiseBasedAquif
Ok(Some(candidate))
}
}
/// Preserve ordered floating-point comparisons, including NaN (which lies
/// neither below -2 nor above 2). Negating `RangeInclusive::contains` alone
/// would incorrectly treat NaN as outside the interval.
fn pressure_outside_interval(q: f64) -> bool {
!q.is_nan() && !(-2.0..=2.0).contains(&q)
}
fn similarity(a: i32, b: i32) -> f64 {
1. - b.wrapping_sub(a) as f64 / 25.
}
#[cfg(test)]
mod pressure_interval_tests {
use super::pressure_outside_interval;
#[test]
fn outside_range_preserves_ordered_float_boundary_and_nan_behavior() {
for (q, expected) in [
(f64::NAN, false),
(f64::NEG_INFINITY, true),
(-2.1, true),
(-2.0, false),
(-0.0, false),
(0.0, false),
(2.0, false),
(2.1, true),
(f64::INFINITY, true),
] {
assert_eq!(pressure_outside_interval(q), expected, "q={q:?}");
}
}
}
@@ -519,7 +519,7 @@ impl<'r, B: TerrainBlockStates, F> TerrainFeatureAccess<'_, 'r, B, F> {
})
}
};
Ok(!height.is_some_and(|height| !height.contains(position[1])))
Ok(height.is_none_or(|height| height.contains(position[1])))
}
}
impl<'r, B: TerrainBlockStates, F> PlacementContext for TerrainFeatureAccess<'_, 'r, B, F>
@@ -445,7 +445,7 @@ impl PlacementModifier {
if !include_edges && (u8::from(bx) + u8::from(by) + u8::from(bz)) >= 2 {
continue;
}
if !include_interior && !(bx || by || bz) {
if !(*include_interior || bx || by || bz) {
continue;
}
emit(
@@ -196,7 +196,7 @@ impl RingSections {
let squared = x.wrapping_mul(x).wrapping_add(z.wrapping_mul(z));
let distance = f64::from(squared).sqrt() as i32;
let section = distance.wrapping_add(self.thickness - self.first) / self.thickness;
!self.max.is_some_and(|max| section > max) && section % 2 == 1
self.max.is_none_or(|max| section <= max) && section % 2 == 1
}
}
+50 -3
View File
@@ -4,6 +4,7 @@ use horizon_world::edge_backoff::{
};
struct World {
calls: usize,
grounded: bool,
}
impl EdgeBackoffWorld for World {
type Error = std::convert::Infallible;
@@ -14,7 +15,7 @@ impl EdgeBackoffWorld for World {
Ok(true)
}
fn on_ground(&mut self) -> Result<bool, Self::Error> {
Ok(true)
Ok(self.grounded)
}
fn no_collision(&mut self, _: Aabb) -> Result<bool, Self::Error> {
self.calls += 1;
@@ -33,7 +34,10 @@ fn input() -> EdgeBackoffInput {
}
#[test]
fn nonconverging_motion_exhausts_budget_without_successful_displacement() {
let mut world = World { calls: 0 };
let mut world = World {
calls: 0,
grounded: true,
};
assert!(matches!(
back_off_from_edge(&mut world, input()),
Err(EdgeBackoffError::QueryBudget)
@@ -42,7 +46,10 @@ fn nonconverging_motion_exhausts_budget_without_successful_displacement() {
}
#[test]
fn zero_budget_only_fails_when_a_probe_is_needed() {
let mut world = World { calls: 0 };
let mut world = World {
calls: 0,
grounded: true,
};
let mut request = input();
request.query_budget = 0;
request.flying = true;
@@ -60,3 +67,43 @@ fn zero_budget_only_fails_when_a_probe_is_needed() {
));
assert_eq!(world.calls, 0);
}
#[test]
fn edge_check_preserves_grounded_and_unordered_fall_distance_short_circuit() {
// Neither already-grounded players nor NaN fall distances should query
// the world at all. The original `fall_distance < step` is false on NaN.
let mut world = World {
calls: 0,
grounded: true,
};
let mut request = input();
request.query_budget = 0;
request.movement = Vec3::new(0.0, 0.0, 0.0);
assert_eq!(
back_off_from_edge(&mut world, request).unwrap(),
Vec3::new(0.0, 0.0, 0.0)
);
assert_eq!(world.calls, 0);
world.grounded = false;
let mut request = input();
request.query_budget = 0;
request.movement = Vec3::new(0.0, 0.0, 0.0);
request.fall_distance = f64::NAN;
assert_eq!(
back_off_from_edge(&mut world, request).unwrap(),
Vec3::new(0.0, 0.0, 0.0)
);
assert_eq!(world.calls, 0);
// An airborne player inside the step range must still attempt the
// collision query and report budget exhaustion rather than succeed.
let mut request = input();
request.query_budget = 0;
request.fall_distance = 0.0;
assert!(matches!(
back_off_from_edge(&mut world, request),
Err(EdgeBackoffError::QueryBudget)
));
assert_eq!(world.calls, 0);
}