fix clamp clippy errors

This commit is contained in:
Marcel Märtens 2022-11-28 13:12:24 +01:00
parent 0ab7a2543e
commit dad73ba2a3
46 changed files with 108 additions and 174 deletions

View File

@ -992,6 +992,7 @@ impl Client {
&mut self, &mut self,
view_distances: common::ViewDistances, view_distances: common::ViewDistances,
) -> common::ViewDistances { ) -> common::ViewDistances {
#[allow(clippy::manual_clamp)]
let view_distances = common::ViewDistances { let view_distances = common::ViewDistances {
terrain: view_distances terrain: view_distances
.terrain .terrain
@ -1004,6 +1005,7 @@ impl Client {
} }
pub fn set_lod_distance(&mut self, lod_distance: u32) { pub fn set_lod_distance(&mut self, lod_distance: u32) {
#[allow(clippy::manual_clamp)]
let lod_distance = lod_distance.max(0).min(1000) as f32 / lod::ZONE_SIZE as f32; let lod_distance = lod_distance.max(0).min(1000) as f32 / lod::ZONE_SIZE as f32;
self.lod_distance = lod_distance; self.lod_distance = lod_distance;
} }

View File

@ -591,10 +591,10 @@ impl ComponentRecipe {
let mut slot_claims = HashMap::new(); let mut slot_claims = HashMap::new();
let mut unsatisfied_requirements = Vec::new(); let mut unsatisfied_requirements = Vec::new();
fn handle_requirement<'a, 'b, I: Iterator<Item = InvSlotId>>( fn handle_requirement<'a, I: Iterator<Item = InvSlotId>>(
slot_claims: &mut HashMap<InvSlotId, u32>, slot_claims: &mut HashMap<InvSlotId, u32>,
unsatisfied_requirements: &mut Vec<(&'a RecipeInput, u32)>, unsatisfied_requirements: &mut Vec<(&'a RecipeInput, u32)>,
inv: &'b Inventory, inv: &Inventory,
input: &'a RecipeInput, input: &'a RecipeInput,
amount: u32, amount: u32,
input_slots: I, input_slots: I,

View File

@ -110,6 +110,7 @@ impl SkillSetBuilder {
/// 2) If added skill already applied /// 2) If added skill already applied
/// 3) If added skill wasn't applied at the end /// 3) If added skill wasn't applied at the end
pub fn with_skill(mut self, skill: Skill, level: u16) -> Self { pub fn with_skill(mut self, skill: Skill, level: u16) -> Self {
let group = if let Some(skill_group) = skill.skill_group_kind() { let group = if let Some(skill_group) = skill.skill_group_kind() {
skill_group skill_group
} else { } else {

View File

@ -43,10 +43,10 @@ impl Iterator for Spiral2d {
let layer_size = (self.layer * 8 + 4 * self.layer.min(1) - 4).max(1); let layer_size = (self.layer * 8 + 4 * self.layer.min(1) - 4).max(1);
let pos = Vec2::new( let pos = Vec2::new(
-self.layer + (self.i - (layer_size / 4) * 0).max(0).min(self.layer * 2) -self.layer + (self.i - (layer_size / 4) * 0).clamp(0, self.layer * 2)
- (self.i - (layer_size / 4) * 2).max(0).min(self.layer * 2), - (self.i - (layer_size / 4) * 2).clamp(0, self.layer * 2),
-self.layer + (self.i - (layer_size / 4) * 1).max(0).min(self.layer * 2) -self.layer + (self.i - (layer_size / 4) * 1).clamp(0, self.layer * 2)
- (self.i - (layer_size / 4) * 3).max(0).min(self.layer * 2), - (self.i - (layer_size / 4) * 3).clamp(0, self.layer * 2),
); );
self.i += 1; self.i += 1;

View File

@ -58,8 +58,7 @@ impl CharacterBehavior for Data {
} }
// forward, max at 8u/s // forward, max at 8u/s
(data.dt.0 * 3.0) (data.dt.0 * 3.0)
.min(8.0 - current_planar_velocity) .clamp(0.0, 8.0 - current_planar_velocity)
.max(0.0)
} else { } else {
if let CharacterState::Skate(data) = &mut update.character { if let CharacterState::Skate(data) = &mut update.character {
data.accelerate = -1.0; data.accelerate = -1.0;

View File

@ -622,7 +622,7 @@ pub fn fly_move(data: &JoinData<'_>, update: &mut StateUpdate, efficiency: f32)
let change = if data.inputs.move_z.abs() > f32::EPSILON { let change = if data.inputs.move_z.abs() > f32::EPSILON {
-data.inputs.move_z -data.inputs.move_z
} else { } else {
(def - data.density.0).max(-1.0).min(1.0) (def - data.density.0).clamp(-1.0, 1.0)
}; };
Density((update.density.0 + data.dt.0 * rate * change).clamp(min, max)) Density((update.density.0 + data.dt.0 * rate * change).clamp(min, max))
}; };

View File

@ -27,8 +27,7 @@ impl CharacterBehavior for Data {
update.vel.0.z += data.dt.0 update.vel.0.z += data.dt.0
* lift * lift
* (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075) * (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075)
.min(1.0) .clamp(0.2, 1.0);
.max(0.2);
} }
// fall off wall, hit ground, or enter water // fall off wall, hit ground, or enter water

View File

@ -678,7 +678,7 @@ impl<'a> MapConfig<'a> {
let deltax = height / angle; let deltax = height / angle;
let lighty = (light_direction.y / light_direction.x * deltax).abs(); let lighty = (light_direction.y / light_direction.x * deltax).abs();
let deltay = lighty - height; let deltay = lighty - height;
let s = (deltay / deltax / w).min(1.0).max(0.0); let s = (deltay / deltax / w).clamp(0.0, 1.0);
// Smoothstep // Smoothstep
s * s * (3.0 - 2.0 * s) s * s * (3.0 - 2.0 * s)
} else { } else {

View File

@ -135,7 +135,7 @@ pub fn xyy_to_rgb(xyy: Vec3<f32>) -> Rgb<f32> {
pub fn saturate_srgb(col: Rgb<f32>, value: f32) -> Rgb<f32> { pub fn saturate_srgb(col: Rgb<f32>, value: f32) -> Rgb<f32> {
let mut hsv = rgb_to_hsv(srgb_to_linear(col)); let mut hsv = rgb_to_hsv(srgb_to_linear(col));
hsv.y *= 1.0 + value; hsv.y *= 1.0 + value;
linear_to_srgb(hsv_to_rgb(hsv).map(|e| e.min(1.0).max(0.0))) linear_to_srgb(hsv_to_rgb(hsv).map(|e| e.clamp(0.0, 1.0)))
} }
/// Preserves the luma of one color while changing its chromaticity to match the /// Preserves the luma of one color while changing its chromaticity to match the
@ -146,5 +146,5 @@ pub fn chromify_srgb(luma: Rgb<f32>, chroma: Rgb<f32>) -> Rgb<f32> {
let mut xyy = rgb_to_xyy(srgb_to_linear(chroma)); let mut xyy = rgb_to_xyy(srgb_to_linear(chroma));
xyy.z = l; xyy.z = l;
linear_to_srgb(xyy_to_rgb(xyy).map(|e| e.min(1.0).max(0.0))) linear_to_srgb(xyy_to_rgb(xyy).map(|e| e.clamp(0.0, 1.0)))
} }

View File

@ -15,6 +15,7 @@ impl ViewDistances {
/// entity view distance to the resulting terrain view distance. /// entity view distance to the resulting terrain view distance.
/// ///
/// Also ensures both are at a minimum of 1 (unless the provided max is 0). /// Also ensures both are at a minimum of 1 (unless the provided max is 0).
#[allow(clippy::manual_clamp)]
pub fn clamp(self, max: Option<u32>) -> Self { pub fn clamp(self, max: Option<u32>) -> Self {
let terrain = self.terrain.max(1).min(max.unwrap_or(u32::MAX)); let terrain = self.terrain.max(1).min(max.unwrap_or(u32::MAX));
Self { Self {

View File

@ -395,6 +395,7 @@ fn execute_effect(
stat.max_energy_modifiers.mult_mod *= *value; stat.max_energy_modifiers.mult_mod *= *value;
}, },
}, },
#[allow(clippy::manual_clamp)]
BuffEffect::DamageReduction(dr) => { BuffEffect::DamageReduction(dr) => {
stat.damage_reduction = stat.damage_reduction.max(*dr).min(1.0); stat.damage_reduction = stat.damage_reduction.max(*dr).min(1.0);
}, },
@ -466,6 +467,7 @@ fn execute_effect(
BuffEffect::GroundFriction(gf) => { BuffEffect::GroundFriction(gf) => {
stat.friction_modifier *= *gf; stat.friction_modifier *= *gf;
}, },
#[allow(clippy::manual_clamp)]
BuffEffect::PoiseReduction(pr) => { BuffEffect::PoiseReduction(pr) => {
stat.poise_reduction = stat.poise_reduction.max(*pr).min(1.0); stat.poise_reduction = stat.poise_reduction.max(*pr).min(1.0);
}, },

View File

@ -1738,7 +1738,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
// E=½mv², we scale both energies by ½m // E=½mv², we scale both energies by ½m
let kinetic = squared_velocity; let kinetic = squared_velocity;
// positive accelerate, negative decelerate, ΔE=mgΔh // positive accelerate, negative decelerate, ΔE=mgΔh
let delta_potential = vertical_difference.max(-1.0).min(2.0) * POTENTIAL_TO_KINETIC; let delta_potential = vertical_difference.clamp(-1.0, 2.0) * POTENTIAL_TO_KINETIC;
let new_energy = kinetic + delta_potential; let new_energy = kinetic + delta_potential;
physics_state.skating_last_height = pos.0.z; physics_state.skating_last_height = pos.0.z;
new_energy / kinetic new_energy / kinetic

View File

@ -2103,9 +2103,9 @@ fn handle_light(
return Err("cr, cg and cb values mustn't be negative.".into()); return Err("cr, cg and cb values mustn't be negative.".into());
} }
let r = r.max(0.0).min(1.0); let r = r.clamp(0.0, 1.0);
let g = g.max(0.0).min(1.0); let g = g.clamp(0.0, 1.0);
let b = b.max(0.0).min(1.0); let b = b.clamp(0.0, 1.0);
light_emitter.col = Rgb::new(r, g, b) light_emitter.col = Rgb::new(r, g, b)
}; };
if let (Some(x), Some(y), Some(z)) = (opt_x, opt_y, opt_z) { if let (Some(x), Some(y), Some(z)) = (opt_x, opt_y, opt_z) {
@ -2152,14 +2152,9 @@ fn handle_lantern(
.write_storage::<LightEmitter>() .write_storage::<LightEmitter>()
.get_mut(target) .get_mut(target)
{ {
light.strength = s.max(0.1).min(10.0); light.strength = s.clamp(0.1, 10.0);
if let (Some(r), Some(g), Some(b)) = (r, g, b) { if let (Some(r), Some(g), Some(b)) = (r, g, b) {
light.col = ( light.col = (r.clamp(0.0, 1.0), g.clamp(0.0, 1.0), b.clamp(0.0, 1.0)).into();
r.max(0.0).min(1.0),
g.max(0.0).min(1.0),
b.max(0.0).min(1.0),
)
.into();
server.notify_client( server.notify_client(
client, client,
ServerGeneral::server_msg( ServerGeneral::server_msg(

View File

@ -566,8 +566,7 @@ pub fn convert_to_loaded_vd(vd: u32, max_view_distance: u32) -> i32 {
const UNLOAD_THRESHOLD: u32 = 2; const UNLOAD_THRESHOLD: u32 = 2;
// NOTE: This cast is safe for the reasons mentioned above. // NOTE: This cast is safe for the reasons mentioned above.
(vd.max(crate::MIN_VD) (vd.clamp(crate::MIN_VD, max_view_distance)
.min(max_view_distance)
.saturating_add(UNLOAD_THRESHOLD)) .saturating_add(UNLOAD_THRESHOLD))
.min(MAX_VD) as i32 .min(MAX_VD) as i32
} }

View File

@ -123,15 +123,13 @@ impl WeatherSim {
let avg_scale = 20_000.0; let avg_scale = 20_000.0;
let avg_delay = 250_000.0; let avg_delay = 250_000.0;
let pressure = ((base_nz.get( let pressure = ((base_nz
(pos / avg_scale) .get((pos / avg_scale).with_z(time / avg_delay).into_array())
.with_z(time / avg_delay) + base_nz.get(
.into_array(), (pos / (avg_scale * 0.25))
) + base_nz.get( .with_z(time / (avg_delay * 0.25))
(pos / (avg_scale * 0.25)) .into_array(),
.with_z(time / (avg_delay * 0.25)) ) * 0.5)
.into_array(),
) * 0.5)
* 0.5 * 0.5
+ 1.0) + 1.0)
.clamped(0.0, 1.0) as f32 .clamped(0.0, 1.0) as f32

View File

@ -127,8 +127,7 @@ impl Animation for RunAnimation {
let side = ((velocity.x * -0.098 * orientation.y + velocity.y * 0.098 * orientation.x) let side = ((velocity.x * -0.098 * orientation.y + velocity.y * 0.098 * orientation.x)
* -1.0) * -1.0)
.min(1.0) .clamp(-1.0, 1.0);
.max(-1.0);
let sideabs = side.abs(); let sideabs = side.abs();
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude()); let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());

View File

@ -32,16 +32,8 @@ impl Animation for GlidingAnimation {
let slow = (acc_vel * 0.5).sin(); let slow = (acc_vel * 0.5).sin();
let head_look = Vec2::new( let head_look = Vec2::new(
((global_time + anim_time) / 4.0) ((global_time + anim_time) / 4.0).floor().mul(7331.0).sin() * 0.5,
.floor() ((global_time + anim_time) / 4.0).floor().mul(1337.0).sin() * 0.25,
.mul(7331.0)
.sin()
* 0.5,
((global_time + anim_time) / 4.0)
.floor()
.mul(1337.0)
.sin()
* 0.25,
); );
let speedlog = speednorm.powi(2); let speedlog = speednorm.powi(2);

View File

@ -1153,7 +1153,7 @@ impl<'a> Widget for Map<'a> {
) )
.font_size( .font_size(
self.fonts.cyri.scale( self.fonts.cyri.scale(
(2.0 + font_scale_factor * zoom).min(18.0).max(10.0) as u32, (2.0 + font_scale_factor * zoom).clamp(10.0, 18.0) as u32,
), ),
) )
.font_id(self.fonts.cyri.conrod_id) .font_id(self.fonts.cyri.conrod_id)

View File

@ -1478,7 +1478,7 @@ impl Hud {
if let Some(health) = healths.get(me) { if let Some(health) = healths.get(me) {
// Hurt Frame // Hurt Frame
let hp_percentage = health.current() / health.maximum() * 100.0; let hp_percentage = health.current() / health.maximum() * 100.0;
self.hp_pulse += dt.as_secs_f32() * 10.0 / hp_percentage.max(3.0).min(7.0); self.hp_pulse += dt.as_secs_f32() * 10.0 / hp_percentage.clamp(3.0, 7.0);
if hp_percentage < 10.0 && !health.is_dead { if hp_percentage < 10.0 && !health.is_dead {
let hurt_fade = (self.hp_pulse).sin() * 0.5 + 0.6; //Animation timer let hurt_fade = (self.hp_pulse).sin() * 0.5 + 0.6; //Animation timer
Image::new(self.imgs.hurt_bg) Image::new(self.imgs.hurt_bg)

View File

@ -348,7 +348,7 @@ pub fn generate_mesh<'a>(
.map_or((0, 0), |limits| { .map_or((0, 0), |limits| {
let (start, end) = limits.into_tuple(); let (start, end) = limits.into_tuple();
let start = start.max(0); let start = start.max(0);
let end = end.min(range.size().d - 1).max(start); let end = end.clamp(start, range.size().d - 1);
(start, end) (start, end)
}); });

View File

@ -335,7 +335,7 @@ impl BloomFactor {
Self::Low => 0.1, Self::Low => 0.1,
Self::Medium => 0.2, Self::Medium => 0.2,
Self::High => 0.3, Self::High => 0.3,
Self::Custom(val) => val.max(0.0).min(1.0), Self::Custom(val) => val.clamp(0.0, 1.0),
} }
} }
} }

View File

@ -26,7 +26,7 @@ impl Vertex {
pos_norm: 0 pos_norm: 0
| ((pos.x as u32) & 0x003F) << 0 | ((pos.x as u32) & 0x003F) << 0
| ((pos.y as u32) & 0x003F) << 6 | ((pos.y as u32) & 0x003F) << 6
| (((pos.z + EXTRA_NEG_Z).max(0.0).min((1 << 17) as f32) as u32) & 0x1FFFF) << 12 | (((pos.z + EXTRA_NEG_Z).clamp(0.0, (1 << 17) as f32) as u32) & 0x1FFFF) << 12
| (norm_bits & 0x7) << 29, | (norm_bits & 0x7) << 29,
vel: river_velocity vel: river_velocity
.map2(Vec2::new(0, 16), |e, off| { .map2(Vec2::new(0, 16), |e, off| {

View File

@ -61,7 +61,7 @@ impl Vertex {
// | (norm_bits & 0x7) << 29, // | (norm_bits & 0x7) << 29,
pos_norm: ((pos.x as u32) & 0x00FF) // NOTE: temp hack, this doesn't need 8 bits pos_norm: ((pos.x as u32) & 0x00FF) // NOTE: temp hack, this doesn't need 8 bits
| ((pos.y as u32) & 0x00FF) << 8 | ((pos.y as u32) & 0x00FF) << 8
| (((pos.z as i32 + VERT_EXTRA_NEG_Z).max(0).min(1 << 12) as u32) & 0x0FFF) << 16 | (((pos.z as i32 + VERT_EXTRA_NEG_Z).clamp(0, 1 << 12) as u32) & 0x0FFF) << 16
| (norm_bits & 0x7) << 29, | (norm_bits & 0x7) << 29,
atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) | ((atlas_pos.y as u32) & 0xFFFF) << 16, atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) | ((atlas_pos.y as u32) & 0xFFFF) << 16,
} }
@ -129,7 +129,7 @@ impl Instance {
inst_mat3: mat_arr[3], inst_mat3: mat_arr[3],
pos_ori_door: ((pos.x as u32) & 0x003F) pos_ori_door: ((pos.x as u32) & 0x003F)
| ((pos.y as u32) & 0x003F) << 6 | ((pos.y as u32) & 0x003F) << 6
| (((pos.z + EXTRA_NEG_Z).max(0).min(1 << 16) as u32) & 0xFFFF) << 12 | (((pos.z + EXTRA_NEG_Z).clamp(0, 1 << 16) as u32) & 0xFFFF) << 12
| (u32::from(ori_bits) & 0x7) << 29 | (u32::from(ori_bits) & 0x7) << 29
| (u32::from(is_door) & 1) << 28, | (u32::from(is_door) & 1) << 28,
inst_vert_page: vert_page, inst_vert_page: vert_page,

View File

@ -28,7 +28,7 @@ impl Vertex {
Self { Self {
pos_norm: ((pos.x as u32) & 0x003F) << 0 pos_norm: ((pos.x as u32) & 0x003F) << 0
| ((pos.y as u32) & 0x003F) << 6 | ((pos.y as u32) & 0x003F) << 6
| (((pos + EXTRA_NEG_Z).z.max(0.0).min((1 << 16) as f32) as u32) & 0xFFFF) << 12 | (((pos + EXTRA_NEG_Z).z.clamp(0.0, (1 << 16) as f32) as u32) & 0xFFFF) << 12
| u32::from(meta) << 28 | u32::from(meta) << 28
| (norm_bits & 0x7) << 29, | (norm_bits & 0x7) << 29,
atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) << 0 | ((atlas_pos.y as u32) & 0xFFFF) << 16, atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) << 0 | ((atlas_pos.y as u32) & 0xFFFF) << 16,

View File

@ -65,7 +65,7 @@ fn clamp_and_modulate(ori: Vec3<f32>) -> Vec3<f32> {
// Wrap camera yaw // Wrap camera yaw
x: ori.x.rem_euclid(2.0 * PI), x: ori.x.rem_euclid(2.0 * PI),
// Clamp camera pitch to the vertical limits // Clamp camera pitch to the vertical limits
y: ori.y.min(PI / 2.0 - 0.0001).max(-PI / 2.0 + 0.0001), y: ori.y.clamp(-PI / 2.0 + 0.0001, PI / 2.0 - 0.0001),
// Wrap camera roll // Wrap camera roll
z: ori.z.rem_euclid(2.0 * PI), z: ori.z.rem_euclid(2.0 * PI),
} }
@ -522,9 +522,7 @@ impl Camera {
// Wrap camera yaw // Wrap camera yaw
self.tgt_ori.x = (self.tgt_ori.x + delta.x).rem_euclid(2.0 * PI); self.tgt_ori.x = (self.tgt_ori.x + delta.x).rem_euclid(2.0 * PI);
// Clamp camera pitch to the vertical limits // Clamp camera pitch to the vertical limits
self.tgt_ori.y = (self.tgt_ori.y + delta.y) self.tgt_ori.y = (self.tgt_ori.y + delta.y).clamp(-PI / 2.0 + 0.001, PI / 2.0 - 0.001);
.min(PI / 2.0 - 0.001)
.max(-PI / 2.0 + 0.001);
// Wrap camera roll // Wrap camera roll
self.tgt_ori.z = (self.tgt_ori.z + delta.z).rem_euclid(2.0 * PI); self.tgt_ori.z = (self.tgt_ori.z + delta.z).rem_euclid(2.0 * PI);
} }

View File

@ -79,7 +79,7 @@ fn recolor_grey(rgb: Rgb<u8>, color: Rgb<u8>) -> Rgb<u8> {
let c1 = srgb_to_linear(rgb.map(|e| e as f32 / BASE_GREY)); let c1 = srgb_to_linear(rgb.map(|e| e as f32 / BASE_GREY));
let c2 = srgb_to_linear(color.map(|e| e as f32 / 255.0)); let c2 = srgb_to_linear(color.map(|e| e as f32 / 255.0));
linear_to_srgb(c1 * c2).map(|e| (e.min(1.0).max(0.0) * 255.0) as u8) linear_to_srgb(c1 * c2).map(|e| (e.clamp(0.0, 1.0) * 255.0) as u8)
} else { } else {
rgb rgb
} }

View File

@ -54,7 +54,7 @@ impl Lod {
client.world_data().lod_alt.raw(), client.world_data().lod_alt.raw(),
client.world_data().lod_horizon.raw(), client.world_data().lod_horizon.raw(),
(client.world_data().chunk_size().as_() / weather::CHUNKS_PER_CELL).map(|e| e.max(1)), (client.world_data().chunk_size().as_() / weather::CHUNKS_PER_CELL).map(|e| e.max(1)),
settings.graphics.lod_detail.max(100).min(2500), settings.graphics.lod_detail.clamp(100, 2500),
/* TODO: figure out how we want to do this without color borders? /* TODO: figure out how we want to do this without color borders?
* water_color().into_array().into(), */ * water_color().into_array().into(), */
); );
@ -80,7 +80,7 @@ impl Lod {
pub fn set_detail(&mut self, detail: u32) { pub fn set_detail(&mut self, detail: u32) {
// Make sure the recorded detail is even. // Make sure the recorded detail is even.
self.data.tgt_detail = (detail - detail % 2).max(100).min(2500); self.data.tgt_detail = (detail - detail % 2).clamp(100, 2500);
} }
pub fn maintain( pub fn maintain(

View File

@ -1018,7 +1018,8 @@ impl<V: RectRasterableVol> Terrain<V> {
span!(guard, "Queue meshing from todo list"); span!(guard, "Queue meshing from todo list");
let mesh_focus_pos = focus_pos.map(|e| e.trunc()).xy().as_::<i64>(); let mesh_focus_pos = focus_pos.map(|e| e.trunc()).xy().as_::<i64>();
//TODO: this is actually no loop, it just runs for a single entry because of the `min_by_key`. Evaluate actually looping here //TODO: this is actually no loop, it just runs for a single entry because of
// the `min_by_key`. Evaluate actually looping here
while let Some((todo, chunk)) = self while let Some((todo, chunk)) = self
.mesh_todo .mesh_todo
.values_mut() .values_mut()

View File

@ -454,7 +454,7 @@ impl PlayState for SessionState {
let mut cam_dir = camera.get_orientation(); let mut cam_dir = camera.get_orientation();
let cam_dir_clamp = let cam_dir_clamp =
(global_state.settings.gameplay.camera_clamp_angle as f32).to_radians(); (global_state.settings.gameplay.camera_clamp_angle as f32).to_radians();
cam_dir.y = (-cam_dir_clamp).max(cam_dir.y).min(cam_dir_clamp); cam_dir.y = (-cam_dir_clamp).clamp(cam_dir.y, cam_dir_clamp);
camera.set_orientation(cam_dir); camera.set_orientation(cam_dir);
} }

View File

@ -31,7 +31,7 @@ impl Cache {
let max_texture_size = renderer.max_texture_size(); let max_texture_size = renderer.max_texture_size();
let glyph_cache_dims = let glyph_cache_dims =
Vec2::new(w, h).map(|e| (e * GLYPH_CACHE_SIZE).min(max_texture_size).max(512)); Vec2::new(w, h).map(|e| (e * GLYPH_CACHE_SIZE).clamp(512, max_texture_size));
let glyph_cache_tex = { let glyph_cache_tex = {
let tex = renderer.create_dynamic_texture(glyph_cache_dims); let tex = renderer.create_dynamic_texture(glyph_cache_dims);
@ -89,7 +89,7 @@ impl Cache {
let max_texture_size = renderer.max_texture_size(); let max_texture_size = renderer.max_texture_size();
let cache_dims = renderer let cache_dims = renderer
.resolution() .resolution()
.map(|e| (e * GLYPH_CACHE_SIZE).min(max_texture_size).max(512)); .map(|e| (e * GLYPH_CACHE_SIZE).clamp(512, max_texture_size));
self.glyph_cache = GlyphCache::builder() self.glyph_cache = GlyphCache::builder()
.dimensions(cache_dims.x, cache_dims.y) .dimensions(cache_dims.x, cache_dims.y)
.scale_tolerance(SCALE_TOLERANCE) .scale_tolerance(SCALE_TOLERANCE)

View File

@ -447,11 +447,9 @@ fn draw_graphic(
fn atlas_size(renderer: &Renderer) -> Vec2<u32> { fn atlas_size(renderer: &Renderer) -> Vec2<u32> {
let max_texture_size = renderer.max_texture_size(); let max_texture_size = renderer.max_texture_size();
renderer.resolution().map(|e| { renderer
(e * GRAPHIC_CACHE_RELATIVE_SIZE) .resolution()
.max(512) .map(|e| (e * GRAPHIC_CACHE_RELATIVE_SIZE).clamp(512, max_texture_size))
.min(max_texture_size)
})
} }
fn create_atlas_texture( fn create_atlas_texture(

View File

@ -40,7 +40,7 @@ impl Cache {
let max_texture_size = renderer.max_texture_size(); let max_texture_size = renderer.max_texture_size();
let glyph_cache_dims = let glyph_cache_dims =
Vec2::new(w, h).map(|e| (e * GLYPH_CACHE_SIZE).min(max_texture_size).max(512)); Vec2::new(w, h).map(|e| (e * GLYPH_CACHE_SIZE).clamp(512, max_texture_size));
let glyph_brush = GlyphBrushBuilder::using_font(default_font) let glyph_brush = GlyphBrushBuilder::using_font(default_font)
.initial_cache_size((glyph_cache_dims.x, glyph_cache_dims.y)) .initial_cache_size((glyph_cache_dims.x, glyph_cache_dims.y))
@ -116,7 +116,7 @@ impl Cache {
let max_texture_size = renderer.max_texture_size(); let max_texture_size = renderer.max_texture_size();
let cache_dims = renderer let cache_dims = renderer
.resolution() .resolution()
.map(|e| (e * GLYPH_CACHE_SIZE).min(max_texture_size).max(512)); .map(|e| (e * GLYPH_CACHE_SIZE).clamp(512, max_texture_size));
let glyph_brush = self.glyph_brush.get_mut(); let glyph_brush = self.glyph_brush.get_mut();
*glyph_brush = glyph_brush *glyph_brush = glyph_brush
.to_builder() .to_builder()

View File

@ -499,10 +499,7 @@ impl IcedRenderer {
b / image_h as f32, /* * ratio_y */ b / image_h as f32, /* * ratio_y */
t / image_h as f32, /* * ratio_y */ t / image_h as f32, /* * ratio_y */
), ),
Extent2::new( Extent2::new(gl_size.w * ratio_x, gl_size.h * ratio_y),
gl_size.w * ratio_x,
gl_size.h * ratio_y,
),
)) ))
/* ((l / image_w as f32), /* ((l / image_w as f32),
(r / image_w as f32), (r / image_w as f32),

View File

@ -567,8 +567,7 @@ impl Window {
// TODO: update users of this event with the fact that it is now the physical // TODO: update users of this event with the fact that it is now the physical
// size // size
let winit::dpi::PhysicalSize { width, height } = physical; let winit::dpi::PhysicalSize { width, height } = physical;
self.events self.events.push(Event::Resize(Vec2::new(width, height)));
.push(Event::Resize(Vec2::new(width, height)));
// Emit event for the UI // Emit event for the UI
let logical_size = Vec2::from(Into::<(f64, f64)>::into( let logical_size = Vec2::from(Into::<(f64, f64)>::into(

View File

@ -32,7 +32,7 @@ fn main() {
let val = nz.get(pos.into_array()); let val = nz.get(pos.into_array());
buf[j * W + i] = u32::from_le_bytes([(val.max(0.0).min(1.0) * 255.0) as u8; 4]); buf[j * W + i] = u32::from_le_bytes([(val.clamp(0.0, 1.0) * 255.0) as u8; 4]);
} }
} }

View File

@ -38,7 +38,7 @@ fn main() {
.get((pos, index, None)) .get((pos, index, None))
.map(|sample| { .map(|sample| {
( (
sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8, sample.alt.sub(64.0).add(gain).mul(0.7).clamp(0.0, 255.0) as u8,
sample.chunk.place, sample.chunk.place,
) )
}) })

View File

@ -347,8 +347,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
}; };
let river_width_noise = let river_width_noise =
(sim.gen_ctx.small_nz.get((river_pos.div(16.0)).into_array())) (sim.gen_ctx.small_nz.get((river_pos.div(16.0)).into_array()))
.max(-1.0) .clamp(-1.0, 1.0)
.min(1.0)
.mul(0.5) .mul(0.5)
.sub(0.5); .sub(0.5);
let river_width = Lerp::lerp( let river_width = Lerp::lerp(
@ -825,16 +824,14 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
let riverless_alt_delta = (sim.gen_ctx.small_nz.get( let riverless_alt_delta = (sim.gen_ctx.small_nz.get(
(wposf_turb.div(200.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64))).into_array(), (wposf_turb.div(200.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64))).into_array(),
) as f32) ) as f32)
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.abs() .abs()
.mul(3.0) .mul(3.0)
+ (sim.gen_ctx.small_nz.get( + (sim.gen_ctx.small_nz.get(
(wposf_turb.div(400.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64))) (wposf_turb.div(400.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64)))
.into_array(), .into_array(),
) as f32) ) as f32)
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.abs() .abs()
.mul(3.0); .mul(3.0);

View File

@ -271,11 +271,7 @@ fn tunnel_below_from_cell(cell: Vec2<i32>, level: u32, land: &Land) -> Option<Tu
let wpos = to_wpos(cell, level); let wpos = to_wpos(cell, level);
Some(Tunnel { Some(Tunnel {
a: node_at(to_cell(wpos, level), level, land)?, a: node_at(to_cell(wpos, level), level, land)?,
b: node_at( b: node_at(to_cell(wpos + CELL_SIZE / 2, level + 1), level + 1, land)?,
to_cell(wpos + CELL_SIZE / 2, level + 1),
level + 1,
land,
)?,
curve: 0.0, curve: 0.0,
}) })
} }

View File

@ -1053,10 +1053,9 @@ impl Branch {
{ {
let rpos = pos.xy() - p; let rpos = pos.xy() - p;
let stretch = 32.0; let stretch = 32.0;
let stair_section = let stair_section = (rpos.x.atan2(rpos.y) / (f32::consts::PI * 2.0) * stretch
(rpos.x.atan2(rpos.y) / (f32::consts::PI * 2.0) * stretch + pos.z)
+ pos.z) .rem_euclid(stretch);
.rem_euclid(stretch);
( (
stair_section < stair_thickness, stair_section < stair_thickness,
stair_section >= stair_thickness stair_section >= stair_thickness

View File

@ -568,7 +568,7 @@ fn get_max_slope(
// Normalized to be between 6 and and 54 degrees. // Normalized to be between 6 and and 54 degrees.
let div_factor = (2.0 * TerrainChunkSize::RECT_SIZE.x as f64) / 8.0; let div_factor = (2.0 * TerrainChunkSize::RECT_SIZE.x as f64) / 8.0;
let rock_strength = rock_strength_nz.get([wposf.x, wposf.y, wposz * div_factor]); let rock_strength = rock_strength_nz.get([wposf.x, wposf.y, wposz * div_factor]);
let rock_strength = rock_strength.max(-1.0).min(1.0) * 0.5 + 0.5; let rock_strength = rock_strength.clamp(-1.0, 1.0) * 0.5 + 0.5;
// Logistic regression. Make sure x ∈ (0, 1). // Logistic regression. Make sure x ∈ (0, 1).
let logit = |x: f64| x.ln() - (-x).ln_1p(); let logit = |x: f64| x.ln() - (-x).ln_1p();
// 0.5 + 0.5 * tanh(ln(1 / (1 - 0.1) - 1) / (2 * (sqrt(3)/pi))) // 0.5 + 0.5 * tanh(ln(1 / (1 - 0.1) - 1) / (2 * (sqrt(3)/pi)))
@ -589,13 +589,12 @@ fn get_max_slope(
let dmax = center + 0.05; let dmax = center + 0.05;
let log_odds = |x: f64| logit(x) - logit(center); let log_odds = |x: f64| logit(x) - logit(center);
let rock_strength = logistic_cdf( let rock_strength = logistic_cdf(
1.0 * logit(rock_strength.min(1.0f64 - 1e-7).max(1e-7)) 1.0 * logit(rock_strength.clamp(1e-7, 1.0f64 - 1e-7))
+ 1.0 + 1.0
* log_odds( * log_odds(
(wposz / CONFIG.mountain_scale as f64) (wposz / CONFIG.mountain_scale as f64)
.abs() .abs()
.min(dmax) .clamp(dmin, dmax),
.max(dmin),
), ),
); );
// NOTE: If you want to disable varying rock strength entirely, uncomment this // NOTE: If you want to disable varying rock strength entirely, uncomment this
@ -900,11 +899,7 @@ fn erode(
- uniform_idx_as_vec2(map_size_lg, posj)) - uniform_idx_as_vec2(map_size_lg, posj))
.map(|e| e as f64); .map(|e| e as f64);
let neighbor_distance = (neighbor_coef * dxy).magnitude(); let neighbor_distance = (neighbor_coef * dxy).magnitude();
let knew = (k let knew = (k * (p * chunk_area * (area[posi] * mwrec_i[kk])).powf(m)
* (p
* chunk_area
* (area[posi] * mwrec_i[kk]))
.powf(m)
/ neighbor_distance.powf(n)) / neighbor_distance.powf(n))
as SimdType; as SimdType;
k_tot[kk] = knew; k_tot[kk] = knew;
@ -1994,14 +1989,8 @@ pub fn get_lakes<F: Float>(
"For edge {:?} between lakes {:?}, couldn't find partner for pass \ "For edge {:?} between lakes {:?}, couldn't find partner for pass \
{:?}. Should never happen; maybe forgot to set both edges?", {:?}. Should never happen; maybe forgot to set both edges?",
( (
( (chunk_idx, uniform_idx_as_vec2(map_size_lg, chunk_idx)),
chunk_idx, (neighbor_idx, uniform_idx_as_vec2(map_size_lg, neighbor_idx))
uniform_idx_as_vec2(map_size_lg, chunk_idx)
),
(
neighbor_idx,
uniform_idx_as_vec2(map_size_lg, neighbor_idx)
)
), ),
( (
( (
@ -2011,10 +2000,7 @@ pub fn get_lakes<F: Float>(
), ),
( (
neighbor_lake_chunk_idx, neighbor_lake_chunk_idx,
uniform_idx_as_vec2( uniform_idx_as_vec2(map_size_lg, neighbor_lake_chunk_idx),
map_size_lg,
neighbor_lake_chunk_idx
),
neighbor_lake_idx_ neighbor_lake_idx_
) )
), ),

View File

@ -131,8 +131,8 @@ pub fn sample_pos(
false, false,
)); ));
let humidity = humidity.min(1.0).max(0.0); let humidity = humidity.clamp(0.0, 1.0);
let temperature = temperature.min(1.0).max(-1.0) * 0.5 + 0.5; let temperature = temperature.clamp(-1.0, 1.0) * 0.5 + 0.5;
let wpos = pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32); let wpos = pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32);
let column_data = samples let column_data = samples
.and_then(|samples| { .and_then(|samples| {
@ -174,8 +174,8 @@ pub fn sample_pos(
let true_water_alt = (alt.max(water_alt) as f64 - focus.z) / gain as f64; let true_water_alt = (alt.max(water_alt) as f64 - focus.z) / gain as f64;
let true_alt = (alt as f64 - focus.z) / gain as f64; let true_alt = (alt as f64 - focus.z) / gain as f64;
let water_depth = (true_water_alt - true_alt).min(1.0).max(0.0); let water_depth = (true_water_alt - true_alt).clamp(0.0, 1.0);
let alt = true_alt.min(1.0).max(0.0); let alt = true_alt.clamp(0.0, 1.0);
let water_color_factor = 2.0; let water_color_factor = 2.0;
let g_water = 32.0 * water_color_factor; let g_water = 32.0 * water_color_factor;

View File

@ -812,8 +812,7 @@ impl WorldSim {
let map_size_chunks_len_f64 = map_size_lg.chunks().map(f64::from).product(); let map_size_chunks_len_f64 = map_size_lg.chunks().map(f64::from).product();
let min_epsilon = 1.0 / map_size_chunks_len_f64.max(f64::EPSILON * 0.5); let min_epsilon = 1.0 / map_size_chunks_len_f64.max(f64::EPSILON * 0.5);
let max_epsilon = let max_epsilon = (1.0 - 1.0 / map_size_chunks_len_f64).min(1.0 - f64::EPSILON * 0.5);
(1.0 - 1.0 / map_size_chunks_len_f64).min(1.0 - f64::EPSILON * 0.5);
// No NaNs in these uniform vectors, since the original noise value always // No NaNs in these uniform vectors, since the original noise value always
// returns Some. // returns Some.
@ -828,8 +827,7 @@ impl WorldSim {
(gen_ctx (gen_ctx
.alt_nz .alt_nz
.get((wposf.div(10_000.0)).into_array()) .get((wposf.div(10_000.0)).into_array())
.min(1.0) .clamp(-1.0, 1.0))
.max(-1.0))
.sub(0.05) .sub(0.05)
.mul(0.35), .mul(0.35),
) )
@ -851,8 +849,7 @@ impl WorldSim {
.div(1_500.0)) .div(1_500.0))
.into_array(), .into_array(),
) )
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(1.0) .mul(1.0)
+ gen_ctx + gen_ctx
.hill_nz .hill_nz
@ -863,8 +860,7 @@ impl WorldSim {
.div(400.0)) .div(400.0))
.into_array(), .into_array(),
) )
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(0.3)) .mul(0.3))
.add(0.3) .add(0.3)
.max(0.0); .max(0.0);
@ -876,8 +872,7 @@ impl WorldSim {
((gen_ctx ((gen_ctx
.chaos_nz .chaos_nz
.get((wposf.div(3_000.0)).into_array()) .get((wposf.div(3_000.0)).into_array())
.min(1.0) .clamp(-1.0, 1.0))
.max(-1.0))
.add(1.0) .add(1.0)
.mul(0.5) .mul(0.5)
// [0, 1] * [0.4, 1] = [0, 1] (but probably towards the lower end) // [0, 1] * [0.4, 1] = [0, 1] (but probably towards the lower end)
@ -885,11 +880,9 @@ impl WorldSim {
(gen_ctx (gen_ctx
.chaos_nz .chaos_nz
.get((wposf.div(6_000.0)).into_array()) .get((wposf.div(6_000.0)).into_array())
.min(1.0) .clamp(-1.0, 1.0))
.max(-1.0))
.abs() .abs()
.max(0.4) .clamp(0.4, 1.0),
.min(1.0),
) )
// Chaos is always increased by a little when we're on a hill (but remember // Chaos is always increased by a little when we're on a hill (but remember
// that hill is 0.3 or less about 50% of the time). // that hill is 0.3 or less about 50% of the time).
@ -934,8 +927,7 @@ impl WorldSim {
let alt_main = (gen_ctx let alt_main = (gen_ctx
.alt_nz .alt_nz
.get((wposf.div(2_000.0)).into_array()) .get((wposf.div(2_000.0)).into_array())
.min(1.0) .clamp(-1.0, 1.0))
.max(-1.0))
.abs() .abs()
.powf(1.35); .powf(1.35);
@ -951,8 +943,7 @@ impl WorldSim {
.div(300.0)) .div(300.0))
.into_array(), .into_array(),
) )
.min(1.0) .clamp(-1.0, 1.0))
.max(-1.0))
.mul(alt_main.powf(0.8).max(/* 0.25 */ 0.15)) .mul(alt_main.powf(0.8).max(/* 0.25 */ 0.15))
.mul(0.3) .mul(0.3)
.add(1.0) .add(1.0)
@ -1120,8 +1111,7 @@ impl WorldSim {
let uheight = gen_ctx let uheight = gen_ctx
.uplift_nz .uplift_nz
.get(turb_wposf.into_array()) .get(turb_wposf.into_array())
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(0.5) .mul(0.5)
.add(0.5); .add(0.5);
let wposf3 = Vec3::new( let wposf3 = Vec3::new(
@ -1132,8 +1122,7 @@ impl WorldSim {
let rock_strength = gen_ctx let rock_strength = gen_ctx
.rock_strength_nz .rock_strength_nz
.get(wposf3.into_array()) .get(wposf3.into_array())
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(0.5) .mul(0.5)
.add(0.5); .add(0.5);
let center = 0.4; let center = 0.4;
@ -1141,8 +1130,8 @@ impl WorldSim {
let dmax = center + 0.05; let dmax = center + 0.05;
let log_odds = |x: f64| logit(x) - logit(center); let log_odds = |x: f64| logit(x) - logit(center);
let ustrength = logistic_cdf( let ustrength = logistic_cdf(
1.0 * logit(rock_strength.min(1.0f64 - 1e-7).max(1e-7)) 1.0 * logit(rock_strength.clamp(1e-7, 1.0f64 - 1e-7))
+ 1.0 * log_odds(uheight.min(dmax).max(dmin)), + 1.0 * log_odds(uheight.clamp(dmin, dmax)),
); );
// marine: ε₀ = 2.078e-3 // marine: ε₀ = 2.078e-3
// San Gabriel Mountains: ε₀ = 3.18e-4 // San Gabriel Mountains: ε₀ = 3.18e-4
@ -1175,8 +1164,7 @@ impl WorldSim {
let uheight = gen_ctx let uheight = gen_ctx
.uplift_nz .uplift_nz
.get(turb_wposf.into_array()) .get(turb_wposf.into_array())
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(0.5) .mul(0.5)
.add(0.5); .add(0.5);
let wposf3 = Vec3::new( let wposf3 = Vec3::new(
@ -1187,8 +1175,7 @@ impl WorldSim {
let rock_strength = gen_ctx let rock_strength = gen_ctx
.rock_strength_nz .rock_strength_nz
.get(wposf3.into_array()) .get(wposf3.into_array())
.min(1.0) .clamp(-1.0, 1.0)
.max(-1.0)
.mul(0.5) .mul(0.5)
.add(0.5); .add(0.5);
let center = 0.4; let center = 0.4;
@ -1196,8 +1183,8 @@ impl WorldSim {
let dmax = center + 0.05; let dmax = center + 0.05;
let log_odds = |x: f64| logit(x) - logit(center); let log_odds = |x: f64| logit(x) - logit(center);
let ustrength = logistic_cdf( let ustrength = logistic_cdf(
1.0 * logit(rock_strength.min(1.0f64 - 1e-7).max(1e-7)) 1.0 * logit(rock_strength.clamp(1e-7, 1.0f64 - 1e-7))
+ 1.0 * log_odds(uheight.min(dmax).max(dmin)), + 1.0 * log_odds(uheight.clamp(dmin, dmax)),
); );
// Frog Hollow (peak production = 0.25): α = 4.2e-2 // Frog Hollow (peak production = 0.25): α = 4.2e-2
// San Gabriel Mountains: α = 3.8e-2 // San Gabriel Mountains: α = 3.8e-2
@ -1685,7 +1672,7 @@ impl WorldSim {
// NOTE: Safe by invariants on map_size_lg. // NOTE: Safe by invariants on map_size_lg.
let posi = (pos.y << self.map_size_lg().vec().x) | pos.x; let posi = (pos.y << self.map_size_lg().vec().x) | pos.x;
v[posi] = u32::from_le_bytes([r, g, b, a]); v[posi] = u32::from_le_bytes([r, g, b, a]);
alts[posi] = (((alt.min(1.0).max(0.0) * 8191.0) as u32) & 0x1FFF) << 3; alts[posi] = (((alt.clamp(0.0, 1.0) * 8191.0) as u32) & 0x1FFF) << 3;
}, },
); );
WorldMapMsg { WorldMapMsg {
@ -2472,8 +2459,7 @@ impl SimChunk {
// Forces lakes to be downhill from the land around them, and adds some noise to // Forces lakes to be downhill from the land around them, and adds some noise to
// the lake bed to make sure it's not too flat. // the lake bed to make sure it's not too flat.
let lake_bottom_nz = (gen_ctx.small_nz.get((wposf.div(20.0)).into_array()) as f32) let lake_bottom_nz = (gen_ctx.small_nz.get((wposf.div(20.0)).into_array()) as f32)
.max(-1.0) .clamp(-1.0, 1.0)
.min(1.0)
.mul(3.0); .mul(3.0);
alt = alt.min(water_alt - 5.0) + lake_bottom_nz; alt = alt.min(water_alt - 5.0) + lake_bottom_nz;
}, },
@ -2486,12 +2472,9 @@ impl SimChunk {
0.0 0.0
} else { } else {
let tree_density = (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array())) let tree_density = (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()))
.mul(1.5) .mul(0.75)
.add(1.0) .add(0.55)
.mul(0.5) .clamp(0.0, 1.0);
.add(0.05)
.max(0.0)
.min(1.0);
// Tree density should go (by a lot) with humidity. // Tree density should go (by a lot) with humidity.
if humidity <= 0.0 || tree_density <= 0.0 { if humidity <= 0.0 || tree_density <= 0.0 {
0.0 0.0

View File

@ -22,8 +22,7 @@ pub fn map_edge_factor(map_size_lg: MapSizeLg, posi: usize) -> f32 {
(sz / 2 - (e - sz / 2).abs()) as f32 / (16.0 / 1024.0 * sz as f32) (sz / 2 - (e - sz / 2).abs()) as f32 / (16.0 / 1024.0 * sz as f32)
}) })
.reduce_partial_min() .reduce_partial_min()
.max(0.0) .clamp(0.0, 1.0)
.min(1.0)
} }
/// Computes the cumulative distribution function of the weighted sum of k /// Computes the cumulative distribution function of the weighted sum of k
@ -614,7 +613,7 @@ impl MultiFractal for HybridMulti {
return self; return self;
} }
octaves = octaves.max(1).min(Self::MAX_OCTAVES); octaves = octaves.clamp(1, Self::MAX_OCTAVES);
Self { Self {
octaves, octaves,
sources: build_sources(self.seed, octaves), sources: build_sources(self.seed, octaves),

View File

@ -368,8 +368,7 @@ impl Fill {
.dot(segment_2d.end.as_() - segment_2d.start.as_()) .dot(segment_2d.end.as_() - segment_2d.start.as_())
/ len_sq) / len_sq)
.clamp(0.0, 1.0); .clamp(0.0, 1.0);
(segment.end.z - segment.start.z) * frac (segment.end.z - segment.start.z) * frac + segment.start.z
+ segment.start.z
} }
}; };
let z_check = (projected_z..=(projected_z + height)).contains(&(pos.z as f32)); let z_check = (projected_z..=(projected_z + height)).contains(&(pos.z as f32));

View File

@ -306,11 +306,7 @@ impl Structure for Castle {
painter.fill( painter.fill(
painter.prim(Primitive::Aabb(Aabb { painter.prim(Primitive::Aabb(Aabb {
min: Vec3::new(gate_aabb.min.x + 2 + i, gate_aabb.min.y, height + i), min: Vec3::new(gate_aabb.min.x + 2 + i, gate_aabb.min.y, height + i),
max: Vec3::new( max: Vec3::new(gate_aabb.max.x - 2 - i, gate_aabb.max.y, height + i + 1),
gate_aabb.max.x - 2 - i,
gate_aabb.max.y,
height + i + 1,
),
})), })),
Fill::Block(Block::empty()), Fill::Block(Block::empty()),
); );

View File

@ -1944,8 +1944,7 @@ impl Structure for DesertCityMultiPlot {
let stair_radius = tower_length + 1; let stair_radius = tower_length + 1;
let stairs_clear = painter.aabb(Aabb { let stairs_clear = painter.aabb(Aabb {
min: (bldg_a_center - stair_radius).with_z(base), min: (bldg_a_center - stair_radius).with_z(base),
max: (bldg_a_center + stair_radius) max: (bldg_a_center + stair_radius).with_z(base + tower_height + 2),
.with_z(base + tower_height + 2),
}); });
stairs_clear stairs_clear
.sample(spiral_staircase( .sample(spiral_staircase(