mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
fix clamp clippy errors
This commit is contained in:
parent
0ab7a2543e
commit
dad73ba2a3
@ -992,6 +992,7 @@ impl Client {
|
||||
&mut self,
|
||||
view_distances: common::ViewDistances,
|
||||
) -> common::ViewDistances {
|
||||
#[allow(clippy::manual_clamp)]
|
||||
let view_distances = common::ViewDistances {
|
||||
terrain: view_distances
|
||||
.terrain
|
||||
@ -1004,6 +1005,7 @@ impl Client {
|
||||
}
|
||||
|
||||
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;
|
||||
self.lod_distance = lod_distance;
|
||||
}
|
||||
|
@ -591,10 +591,10 @@ impl ComponentRecipe {
|
||||
let mut slot_claims = HashMap::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>,
|
||||
unsatisfied_requirements: &mut Vec<(&'a RecipeInput, u32)>,
|
||||
inv: &'b Inventory,
|
||||
inv: &Inventory,
|
||||
input: &'a RecipeInput,
|
||||
amount: u32,
|
||||
input_slots: I,
|
||||
|
@ -110,6 +110,7 @@ impl SkillSetBuilder {
|
||||
/// 2) If added skill already applied
|
||||
/// 3) If added skill wasn't applied at the end
|
||||
pub fn with_skill(mut self, skill: Skill, level: u16) -> Self {
|
||||
|
||||
let group = if let Some(skill_group) = skill.skill_group_kind() {
|
||||
skill_group
|
||||
} else {
|
||||
|
@ -43,10 +43,10 @@ impl Iterator for Spiral2d {
|
||||
let layer_size = (self.layer * 8 + 4 * self.layer.min(1) - 4).max(1);
|
||||
|
||||
let pos = Vec2::new(
|
||||
-self.layer + (self.i - (layer_size / 4) * 0).max(0).min(self.layer * 2)
|
||||
- (self.i - (layer_size / 4) * 2).max(0).min(self.layer * 2),
|
||||
-self.layer + (self.i - (layer_size / 4) * 1).max(0).min(self.layer * 2)
|
||||
- (self.i - (layer_size / 4) * 3).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).clamp(0, self.layer * 2),
|
||||
-self.layer + (self.i - (layer_size / 4) * 1).clamp(0, self.layer * 2)
|
||||
- (self.i - (layer_size / 4) * 3).clamp(0, self.layer * 2),
|
||||
);
|
||||
|
||||
self.i += 1;
|
||||
|
@ -58,8 +58,7 @@ impl CharacterBehavior for Data {
|
||||
}
|
||||
// forward, max at 8u/s
|
||||
(data.dt.0 * 3.0)
|
||||
.min(8.0 - current_planar_velocity)
|
||||
.max(0.0)
|
||||
.clamp(0.0, 8.0 - current_planar_velocity)
|
||||
} else {
|
||||
if let CharacterState::Skate(data) = &mut update.character {
|
||||
data.accelerate = -1.0;
|
||||
|
@ -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 {
|
||||
-data.inputs.move_z
|
||||
} 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))
|
||||
};
|
||||
|
@ -27,8 +27,7 @@ impl CharacterBehavior for Data {
|
||||
update.vel.0.z += data.dt.0
|
||||
* lift
|
||||
* (Vec2::<f32>::from(update.vel.0).magnitude() * 0.075)
|
||||
.min(1.0)
|
||||
.max(0.2);
|
||||
.clamp(0.2, 1.0);
|
||||
}
|
||||
|
||||
// fall off wall, hit ground, or enter water
|
||||
|
@ -678,7 +678,7 @@ impl<'a> MapConfig<'a> {
|
||||
let deltax = height / angle;
|
||||
let lighty = (light_direction.y / light_direction.x * deltax).abs();
|
||||
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
|
||||
s * s * (3.0 - 2.0 * s)
|
||||
} else {
|
||||
|
@ -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> {
|
||||
let mut hsv = rgb_to_hsv(srgb_to_linear(col));
|
||||
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
|
||||
@ -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));
|
||||
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)))
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ impl ViewDistances {
|
||||
/// entity view distance to the resulting terrain view distance.
|
||||
///
|
||||
/// 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 {
|
||||
let terrain = self.terrain.max(1).min(max.unwrap_or(u32::MAX));
|
||||
Self {
|
||||
|
@ -395,6 +395,7 @@ fn execute_effect(
|
||||
stat.max_energy_modifiers.mult_mod *= *value;
|
||||
},
|
||||
},
|
||||
#[allow(clippy::manual_clamp)]
|
||||
BuffEffect::DamageReduction(dr) => {
|
||||
stat.damage_reduction = stat.damage_reduction.max(*dr).min(1.0);
|
||||
},
|
||||
@ -466,6 +467,7 @@ fn execute_effect(
|
||||
BuffEffect::GroundFriction(gf) => {
|
||||
stat.friction_modifier *= *gf;
|
||||
},
|
||||
#[allow(clippy::manual_clamp)]
|
||||
BuffEffect::PoiseReduction(pr) => {
|
||||
stat.poise_reduction = stat.poise_reduction.max(*pr).min(1.0);
|
||||
},
|
||||
|
@ -1738,7 +1738,7 @@ fn box_voxel_collision<'a, T: BaseVol<Vox = Block> + ReadVol>(
|
||||
// E=½mv², we scale both energies by ½m
|
||||
let kinetic = squared_velocity;
|
||||
// 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;
|
||||
physics_state.skating_last_height = pos.0.z;
|
||||
new_energy / kinetic
|
||||
|
@ -2103,9 +2103,9 @@ fn handle_light(
|
||||
return Err("cr, cg and cb values mustn't be negative.".into());
|
||||
}
|
||||
|
||||
let r = r.max(0.0).min(1.0);
|
||||
let g = g.max(0.0).min(1.0);
|
||||
let b = b.max(0.0).min(1.0);
|
||||
let r = r.clamp(0.0, 1.0);
|
||||
let g = g.clamp(0.0, 1.0);
|
||||
let b = b.clamp(0.0, 1.0);
|
||||
light_emitter.col = Rgb::new(r, g, b)
|
||||
};
|
||||
if let (Some(x), Some(y), Some(z)) = (opt_x, opt_y, opt_z) {
|
||||
@ -2152,14 +2152,9 @@ fn handle_lantern(
|
||||
.write_storage::<LightEmitter>()
|
||||
.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) {
|
||||
light.col = (
|
||||
r.max(0.0).min(1.0),
|
||||
g.max(0.0).min(1.0),
|
||||
b.max(0.0).min(1.0),
|
||||
)
|
||||
.into();
|
||||
light.col = (r.clamp(0.0, 1.0), g.clamp(0.0, 1.0), b.clamp(0.0, 1.0)).into();
|
||||
server.notify_client(
|
||||
client,
|
||||
ServerGeneral::server_msg(
|
||||
|
@ -566,8 +566,7 @@ pub fn convert_to_loaded_vd(vd: u32, max_view_distance: u32) -> i32 {
|
||||
const UNLOAD_THRESHOLD: u32 = 2;
|
||||
|
||||
// NOTE: This cast is safe for the reasons mentioned above.
|
||||
(vd.max(crate::MIN_VD)
|
||||
.min(max_view_distance)
|
||||
(vd.clamp(crate::MIN_VD, max_view_distance)
|
||||
.saturating_add(UNLOAD_THRESHOLD))
|
||||
.min(MAX_VD) as i32
|
||||
}
|
||||
|
@ -123,15 +123,13 @@ impl WeatherSim {
|
||||
|
||||
let avg_scale = 20_000.0;
|
||||
let avg_delay = 250_000.0;
|
||||
let pressure = ((base_nz.get(
|
||||
(pos / avg_scale)
|
||||
.with_z(time / avg_delay)
|
||||
.into_array(),
|
||||
) + base_nz.get(
|
||||
(pos / (avg_scale * 0.25))
|
||||
.with_z(time / (avg_delay * 0.25))
|
||||
.into_array(),
|
||||
) * 0.5)
|
||||
let pressure = ((base_nz
|
||||
.get((pos / avg_scale).with_z(time / avg_delay).into_array())
|
||||
+ base_nz.get(
|
||||
(pos / (avg_scale * 0.25))
|
||||
.with_z(time / (avg_delay * 0.25))
|
||||
.into_array(),
|
||||
) * 0.5)
|
||||
* 0.5
|
||||
+ 1.0)
|
||||
.clamped(0.0, 1.0) as f32
|
||||
|
@ -127,8 +127,7 @@ impl Animation for RunAnimation {
|
||||
|
||||
let side = ((velocity.x * -0.098 * orientation.y + velocity.y * 0.098 * orientation.x)
|
||||
* -1.0)
|
||||
.min(1.0)
|
||||
.max(-1.0);
|
||||
.clamp(-1.0, 1.0);
|
||||
let sideabs = side.abs();
|
||||
let x_tilt = avg_vel.z.atan2(avg_vel.xy().magnitude());
|
||||
|
||||
|
@ -32,16 +32,8 @@ impl Animation for GlidingAnimation {
|
||||
let slow = (acc_vel * 0.5).sin();
|
||||
|
||||
let head_look = Vec2::new(
|
||||
((global_time + anim_time) / 4.0)
|
||||
.floor()
|
||||
.mul(7331.0)
|
||||
.sin()
|
||||
* 0.5,
|
||||
((global_time + anim_time) / 4.0)
|
||||
.floor()
|
||||
.mul(1337.0)
|
||||
.sin()
|
||||
* 0.25,
|
||||
((global_time + anim_time) / 4.0).floor().mul(7331.0).sin() * 0.5,
|
||||
((global_time + anim_time) / 4.0).floor().mul(1337.0).sin() * 0.25,
|
||||
);
|
||||
|
||||
let speedlog = speednorm.powi(2);
|
||||
|
@ -1153,7 +1153,7 @@ impl<'a> Widget for Map<'a> {
|
||||
)
|
||||
.font_size(
|
||||
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)
|
||||
|
@ -1478,7 +1478,7 @@ impl Hud {
|
||||
if let Some(health) = healths.get(me) {
|
||||
// Hurt Frame
|
||||
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 {
|
||||
let hurt_fade = (self.hp_pulse).sin() * 0.5 + 0.6; //Animation timer
|
||||
Image::new(self.imgs.hurt_bg)
|
||||
|
@ -348,7 +348,7 @@ pub fn generate_mesh<'a>(
|
||||
.map_or((0, 0), |limits| {
|
||||
let (start, end) = limits.into_tuple();
|
||||
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)
|
||||
});
|
||||
|
||||
|
@ -335,7 +335,7 @@ impl BloomFactor {
|
||||
Self::Low => 0.1,
|
||||
Self::Medium => 0.2,
|
||||
Self::High => 0.3,
|
||||
Self::Custom(val) => val.max(0.0).min(1.0),
|
||||
Self::Custom(val) => val.clamp(0.0, 1.0),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ impl Vertex {
|
||||
pos_norm: 0
|
||||
| ((pos.x as u32) & 0x003F) << 0
|
||||
| ((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,
|
||||
vel: river_velocity
|
||||
.map2(Vec2::new(0, 16), |e, off| {
|
||||
|
@ -61,7 +61,7 @@ impl Vertex {
|
||||
// | (norm_bits & 0x7) << 29,
|
||||
pos_norm: ((pos.x as u32) & 0x00FF) // NOTE: temp hack, this doesn't need 8 bits
|
||||
| ((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,
|
||||
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],
|
||||
pos_ori_door: ((pos.x as u32) & 0x003F)
|
||||
| ((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(is_door) & 1) << 28,
|
||||
inst_vert_page: vert_page,
|
||||
|
@ -28,7 +28,7 @@ impl Vertex {
|
||||
Self {
|
||||
pos_norm: ((pos.x as u32) & 0x003F) << 0
|
||||
| ((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
|
||||
| (norm_bits & 0x7) << 29,
|
||||
atlas_pos: ((atlas_pos.x as u32) & 0xFFFF) << 0 | ((atlas_pos.y as u32) & 0xFFFF) << 16,
|
||||
|
@ -65,7 +65,7 @@ fn clamp_and_modulate(ori: Vec3<f32>) -> Vec3<f32> {
|
||||
// Wrap camera yaw
|
||||
x: ori.x.rem_euclid(2.0 * PI),
|
||||
// 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
|
||||
z: ori.z.rem_euclid(2.0 * PI),
|
||||
}
|
||||
@ -522,9 +522,7 @@ impl Camera {
|
||||
// Wrap camera yaw
|
||||
self.tgt_ori.x = (self.tgt_ori.x + delta.x).rem_euclid(2.0 * PI);
|
||||
// Clamp camera pitch to the vertical limits
|
||||
self.tgt_ori.y = (self.tgt_ori.y + delta.y)
|
||||
.min(PI / 2.0 - 0.001)
|
||||
.max(-PI / 2.0 + 0.001);
|
||||
self.tgt_ori.y = (self.tgt_ori.y + delta.y).clamp(-PI / 2.0 + 0.001, PI / 2.0 - 0.001);
|
||||
// Wrap camera roll
|
||||
self.tgt_ori.z = (self.tgt_ori.z + delta.z).rem_euclid(2.0 * PI);
|
||||
}
|
||||
|
@ -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 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 {
|
||||
rgb
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ impl Lod {
|
||||
client.world_data().lod_alt.raw(),
|
||||
client.world_data().lod_horizon.raw(),
|
||||
(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?
|
||||
* water_color().into_array().into(), */
|
||||
);
|
||||
@ -80,7 +80,7 @@ impl Lod {
|
||||
|
||||
pub fn set_detail(&mut self, detail: u32) {
|
||||
// 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(
|
||||
|
@ -1018,7 +1018,8 @@ impl<V: RectRasterableVol> Terrain<V> {
|
||||
|
||||
span!(guard, "Queue meshing from todo list");
|
||||
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
|
||||
.mesh_todo
|
||||
.values_mut()
|
||||
|
@ -454,7 +454,7 @@ impl PlayState for SessionState {
|
||||
let mut cam_dir = camera.get_orientation();
|
||||
let cam_dir_clamp =
|
||||
(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);
|
||||
}
|
||||
|
||||
|
@ -31,7 +31,7 @@ impl Cache {
|
||||
let max_texture_size = renderer.max_texture_size();
|
||||
|
||||
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 tex = renderer.create_dynamic_texture(glyph_cache_dims);
|
||||
@ -89,7 +89,7 @@ impl Cache {
|
||||
let max_texture_size = renderer.max_texture_size();
|
||||
let cache_dims = renderer
|
||||
.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()
|
||||
.dimensions(cache_dims.x, cache_dims.y)
|
||||
.scale_tolerance(SCALE_TOLERANCE)
|
||||
|
@ -447,11 +447,9 @@ fn draw_graphic(
|
||||
fn atlas_size(renderer: &Renderer) -> Vec2<u32> {
|
||||
let max_texture_size = renderer.max_texture_size();
|
||||
|
||||
renderer.resolution().map(|e| {
|
||||
(e * GRAPHIC_CACHE_RELATIVE_SIZE)
|
||||
.max(512)
|
||||
.min(max_texture_size)
|
||||
})
|
||||
renderer
|
||||
.resolution()
|
||||
.map(|e| (e * GRAPHIC_CACHE_RELATIVE_SIZE).clamp(512, max_texture_size))
|
||||
}
|
||||
|
||||
fn create_atlas_texture(
|
||||
|
@ -40,7 +40,7 @@ impl Cache {
|
||||
let max_texture_size = renderer.max_texture_size();
|
||||
|
||||
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)
|
||||
.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 cache_dims = renderer
|
||||
.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();
|
||||
*glyph_brush = glyph_brush
|
||||
.to_builder()
|
||||
|
@ -499,10 +499,7 @@ impl IcedRenderer {
|
||||
b / image_h as f32, /* * ratio_y */
|
||||
t / image_h as f32, /* * ratio_y */
|
||||
),
|
||||
Extent2::new(
|
||||
gl_size.w * ratio_x,
|
||||
gl_size.h * ratio_y,
|
||||
),
|
||||
Extent2::new(gl_size.w * ratio_x, gl_size.h * ratio_y),
|
||||
))
|
||||
/* ((l / image_w as f32),
|
||||
(r / image_w as f32),
|
||||
|
@ -567,8 +567,7 @@ impl Window {
|
||||
// TODO: update users of this event with the fact that it is now the physical
|
||||
// size
|
||||
let winit::dpi::PhysicalSize { width, height } = physical;
|
||||
self.events
|
||||
.push(Event::Resize(Vec2::new(width, height)));
|
||||
self.events.push(Event::Resize(Vec2::new(width, height)));
|
||||
|
||||
// Emit event for the UI
|
||||
let logical_size = Vec2::from(Into::<(f64, f64)>::into(
|
||||
|
@ -32,7 +32,7 @@ fn main() {
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ fn main() {
|
||||
.get((pos, index, None))
|
||||
.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,
|
||||
)
|
||||
})
|
||||
|
@ -347,8 +347,7 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
||||
};
|
||||
let river_width_noise =
|
||||
(sim.gen_ctx.small_nz.get((river_pos.div(16.0)).into_array()))
|
||||
.max(-1.0)
|
||||
.min(1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.5)
|
||||
.sub(0.5);
|
||||
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(
|
||||
(wposf_turb.div(200.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64))).into_array(),
|
||||
) as f32)
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.abs()
|
||||
.mul(3.0)
|
||||
+ (sim.gen_ctx.small_nz.get(
|
||||
(wposf_turb.div(400.0 * (32.0 / TerrainChunkSize::RECT_SIZE.x as f64)))
|
||||
.into_array(),
|
||||
) as f32)
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.abs()
|
||||
.mul(3.0);
|
||||
|
||||
|
@ -271,11 +271,7 @@ fn tunnel_below_from_cell(cell: Vec2<i32>, level: u32, land: &Land) -> Option<Tu
|
||||
let wpos = to_wpos(cell, level);
|
||||
Some(Tunnel {
|
||||
a: node_at(to_cell(wpos, level), level, land)?,
|
||||
b: node_at(
|
||||
to_cell(wpos + CELL_SIZE / 2, level + 1),
|
||||
level + 1,
|
||||
land,
|
||||
)?,
|
||||
b: node_at(to_cell(wpos + CELL_SIZE / 2, level + 1), level + 1, land)?,
|
||||
curve: 0.0,
|
||||
})
|
||||
}
|
||||
|
@ -1053,10 +1053,9 @@ impl Branch {
|
||||
{
|
||||
let rpos = pos.xy() - p;
|
||||
let stretch = 32.0;
|
||||
let stair_section =
|
||||
(rpos.x.atan2(rpos.y) / (f32::consts::PI * 2.0) * stretch
|
||||
+ pos.z)
|
||||
.rem_euclid(stretch);
|
||||
let stair_section = (rpos.x.atan2(rpos.y) / (f32::consts::PI * 2.0) * stretch
|
||||
+ pos.z)
|
||||
.rem_euclid(stretch);
|
||||
(
|
||||
stair_section < stair_thickness,
|
||||
stair_section >= stair_thickness
|
||||
|
@ -568,7 +568,7 @@ fn get_max_slope(
|
||||
// Normalized to be between 6 and and 54 degrees.
|
||||
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.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).
|
||||
let logit = |x: f64| x.ln() - (-x).ln_1p();
|
||||
// 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 log_odds = |x: f64| logit(x) - logit(center);
|
||||
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
|
||||
* log_odds(
|
||||
(wposz / CONFIG.mountain_scale as f64)
|
||||
.abs()
|
||||
.min(dmax)
|
||||
.max(dmin),
|
||||
.clamp(dmin, dmax),
|
||||
),
|
||||
);
|
||||
// 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))
|
||||
.map(|e| e as f64);
|
||||
let neighbor_distance = (neighbor_coef * dxy).magnitude();
|
||||
let knew = (k
|
||||
* (p
|
||||
* chunk_area
|
||||
* (area[posi] * mwrec_i[kk]))
|
||||
.powf(m)
|
||||
let knew = (k * (p * chunk_area * (area[posi] * mwrec_i[kk])).powf(m)
|
||||
/ neighbor_distance.powf(n))
|
||||
as SimdType;
|
||||
k_tot[kk] = knew;
|
||||
@ -1994,14 +1989,8 @@ pub fn get_lakes<F: Float>(
|
||||
"For edge {:?} between lakes {:?}, couldn't find partner for pass \
|
||||
{:?}. Should never happen; maybe forgot to set both edges?",
|
||||
(
|
||||
(
|
||||
chunk_idx,
|
||||
uniform_idx_as_vec2(map_size_lg, chunk_idx)
|
||||
),
|
||||
(
|
||||
neighbor_idx,
|
||||
uniform_idx_as_vec2(map_size_lg, neighbor_idx)
|
||||
)
|
||||
(chunk_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,
|
||||
uniform_idx_as_vec2(
|
||||
map_size_lg,
|
||||
neighbor_lake_chunk_idx
|
||||
),
|
||||
uniform_idx_as_vec2(map_size_lg, neighbor_lake_chunk_idx),
|
||||
neighbor_lake_idx_
|
||||
)
|
||||
),
|
||||
|
@ -131,8 +131,8 @@ pub fn sample_pos(
|
||||
false,
|
||||
));
|
||||
|
||||
let humidity = humidity.min(1.0).max(0.0);
|
||||
let temperature = temperature.min(1.0).max(-1.0) * 0.5 + 0.5;
|
||||
let humidity = humidity.clamp(0.0, 1.0);
|
||||
let temperature = temperature.clamp(-1.0, 1.0) * 0.5 + 0.5;
|
||||
let wpos = pos * TerrainChunkSize::RECT_SIZE.map(|e| e as i32);
|
||||
let column_data = 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_alt = (alt as f64 - focus.z) / gain as f64;
|
||||
let water_depth = (true_water_alt - true_alt).min(1.0).max(0.0);
|
||||
let 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.clamp(0.0, 1.0);
|
||||
|
||||
let water_color_factor = 2.0;
|
||||
let g_water = 32.0 * water_color_factor;
|
||||
|
@ -812,8 +812,7 @@ impl WorldSim {
|
||||
|
||||
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 max_epsilon =
|
||||
(1.0 - 1.0 / map_size_chunks_len_f64).min(1.0 - f64::EPSILON * 0.5);
|
||||
let max_epsilon = (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
|
||||
// returns Some.
|
||||
@ -828,8 +827,7 @@ impl WorldSim {
|
||||
(gen_ctx
|
||||
.alt_nz
|
||||
.get((wposf.div(10_000.0)).into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0))
|
||||
.clamp(-1.0, 1.0))
|
||||
.sub(0.05)
|
||||
.mul(0.35),
|
||||
)
|
||||
@ -851,8 +849,7 @@ impl WorldSim {
|
||||
.div(1_500.0))
|
||||
.into_array(),
|
||||
)
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(1.0)
|
||||
+ gen_ctx
|
||||
.hill_nz
|
||||
@ -863,8 +860,7 @@ impl WorldSim {
|
||||
.div(400.0))
|
||||
.into_array(),
|
||||
)
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.3))
|
||||
.add(0.3)
|
||||
.max(0.0);
|
||||
@ -876,8 +872,7 @@ impl WorldSim {
|
||||
((gen_ctx
|
||||
.chaos_nz
|
||||
.get((wposf.div(3_000.0)).into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0))
|
||||
.clamp(-1.0, 1.0))
|
||||
.add(1.0)
|
||||
.mul(0.5)
|
||||
// [0, 1] * [0.4, 1] = [0, 1] (but probably towards the lower end)
|
||||
@ -885,11 +880,9 @@ impl WorldSim {
|
||||
(gen_ctx
|
||||
.chaos_nz
|
||||
.get((wposf.div(6_000.0)).into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0))
|
||||
.clamp(-1.0, 1.0))
|
||||
.abs()
|
||||
.max(0.4)
|
||||
.min(1.0),
|
||||
.clamp(0.4, 1.0),
|
||||
)
|
||||
// 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).
|
||||
@ -934,8 +927,7 @@ impl WorldSim {
|
||||
let alt_main = (gen_ctx
|
||||
.alt_nz
|
||||
.get((wposf.div(2_000.0)).into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0))
|
||||
.clamp(-1.0, 1.0))
|
||||
.abs()
|
||||
.powf(1.35);
|
||||
|
||||
@ -951,8 +943,7 @@ impl WorldSim {
|
||||
.div(300.0))
|
||||
.into_array(),
|
||||
)
|
||||
.min(1.0)
|
||||
.max(-1.0))
|
||||
.clamp(-1.0, 1.0))
|
||||
.mul(alt_main.powf(0.8).max(/* 0.25 */ 0.15))
|
||||
.mul(0.3)
|
||||
.add(1.0)
|
||||
@ -1120,8 +1111,7 @@ impl WorldSim {
|
||||
let uheight = gen_ctx
|
||||
.uplift_nz
|
||||
.get(turb_wposf.into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.5)
|
||||
.add(0.5);
|
||||
let wposf3 = Vec3::new(
|
||||
@ -1132,8 +1122,7 @@ impl WorldSim {
|
||||
let rock_strength = gen_ctx
|
||||
.rock_strength_nz
|
||||
.get(wposf3.into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.5)
|
||||
.add(0.5);
|
||||
let center = 0.4;
|
||||
@ -1141,8 +1130,8 @@ impl WorldSim {
|
||||
let dmax = center + 0.05;
|
||||
let log_odds = |x: f64| logit(x) - logit(center);
|
||||
let ustrength = logistic_cdf(
|
||||
1.0 * logit(rock_strength.min(1.0f64 - 1e-7).max(1e-7))
|
||||
+ 1.0 * log_odds(uheight.min(dmax).max(dmin)),
|
||||
1.0 * logit(rock_strength.clamp(1e-7, 1.0f64 - 1e-7))
|
||||
+ 1.0 * log_odds(uheight.clamp(dmin, dmax)),
|
||||
);
|
||||
// marine: ε₀ = 2.078e-3
|
||||
// San Gabriel Mountains: ε₀ = 3.18e-4
|
||||
@ -1175,8 +1164,7 @@ impl WorldSim {
|
||||
let uheight = gen_ctx
|
||||
.uplift_nz
|
||||
.get(turb_wposf.into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.5)
|
||||
.add(0.5);
|
||||
let wposf3 = Vec3::new(
|
||||
@ -1187,8 +1175,7 @@ impl WorldSim {
|
||||
let rock_strength = gen_ctx
|
||||
.rock_strength_nz
|
||||
.get(wposf3.into_array())
|
||||
.min(1.0)
|
||||
.max(-1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(0.5)
|
||||
.add(0.5);
|
||||
let center = 0.4;
|
||||
@ -1196,8 +1183,8 @@ impl WorldSim {
|
||||
let dmax = center + 0.05;
|
||||
let log_odds = |x: f64| logit(x) - logit(center);
|
||||
let ustrength = logistic_cdf(
|
||||
1.0 * logit(rock_strength.min(1.0f64 - 1e-7).max(1e-7))
|
||||
+ 1.0 * log_odds(uheight.min(dmax).max(dmin)),
|
||||
1.0 * logit(rock_strength.clamp(1e-7, 1.0f64 - 1e-7))
|
||||
+ 1.0 * log_odds(uheight.clamp(dmin, dmax)),
|
||||
);
|
||||
// Frog Hollow (peak production = 0.25): α = 4.2e-2
|
||||
// San Gabriel Mountains: α = 3.8e-2
|
||||
@ -1225,7 +1212,7 @@ impl WorldSim {
|
||||
// u = 5e-4: normal (mid example in Yuan, average mountain uplift)
|
||||
// u = 2e-4: low (low example in Yuan; known that lagoons etc. may have u ~
|
||||
// 0.05). u = 0: low (plateau [fan, altitude = 0.0])
|
||||
|
||||
|
||||
height.mul(max_erosion_per_delta_t)
|
||||
};
|
||||
let alt_func = |posi| {
|
||||
@ -1685,7 +1672,7 @@ impl WorldSim {
|
||||
// NOTE: Safe by invariants on map_size_lg.
|
||||
let posi = (pos.y << self.map_size_lg().vec().x) | pos.x;
|
||||
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 {
|
||||
@ -2472,8 +2459,7 @@ impl SimChunk {
|
||||
// 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.
|
||||
let lake_bottom_nz = (gen_ctx.small_nz.get((wposf.div(20.0)).into_array()) as f32)
|
||||
.max(-1.0)
|
||||
.min(1.0)
|
||||
.clamp(-1.0, 1.0)
|
||||
.mul(3.0);
|
||||
alt = alt.min(water_alt - 5.0) + lake_bottom_nz;
|
||||
},
|
||||
@ -2486,12 +2472,9 @@ impl SimChunk {
|
||||
0.0
|
||||
} else {
|
||||
let tree_density = (gen_ctx.tree_nz.get((wposf.div(1024.0)).into_array()))
|
||||
.mul(1.5)
|
||||
.add(1.0)
|
||||
.mul(0.5)
|
||||
.add(0.05)
|
||||
.max(0.0)
|
||||
.min(1.0);
|
||||
.mul(0.75)
|
||||
.add(0.55)
|
||||
.clamp(0.0, 1.0);
|
||||
// Tree density should go (by a lot) with humidity.
|
||||
if humidity <= 0.0 || tree_density <= 0.0 {
|
||||
0.0
|
||||
|
@ -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)
|
||||
})
|
||||
.reduce_partial_min()
|
||||
.max(0.0)
|
||||
.min(1.0)
|
||||
.clamp(0.0, 1.0)
|
||||
}
|
||||
|
||||
/// Computes the cumulative distribution function of the weighted sum of k
|
||||
@ -614,7 +613,7 @@ impl MultiFractal for HybridMulti {
|
||||
return self;
|
||||
}
|
||||
|
||||
octaves = octaves.max(1).min(Self::MAX_OCTAVES);
|
||||
octaves = octaves.clamp(1, Self::MAX_OCTAVES);
|
||||
Self {
|
||||
octaves,
|
||||
sources: build_sources(self.seed, octaves),
|
||||
|
@ -368,8 +368,7 @@ impl Fill {
|
||||
.dot(segment_2d.end.as_() - segment_2d.start.as_())
|
||||
/ len_sq)
|
||||
.clamp(0.0, 1.0);
|
||||
(segment.end.z - segment.start.z) * frac
|
||||
+ segment.start.z
|
||||
(segment.end.z - segment.start.z) * frac + segment.start.z
|
||||
}
|
||||
};
|
||||
let z_check = (projected_z..=(projected_z + height)).contains(&(pos.z as f32));
|
||||
|
@ -306,11 +306,7 @@ impl Structure for Castle {
|
||||
painter.fill(
|
||||
painter.prim(Primitive::Aabb(Aabb {
|
||||
min: Vec3::new(gate_aabb.min.x + 2 + i, gate_aabb.min.y, height + i),
|
||||
max: Vec3::new(
|
||||
gate_aabb.max.x - 2 - i,
|
||||
gate_aabb.max.y,
|
||||
height + i + 1,
|
||||
),
|
||||
max: Vec3::new(gate_aabb.max.x - 2 - i, gate_aabb.max.y, height + i + 1),
|
||||
})),
|
||||
Fill::Block(Block::empty()),
|
||||
);
|
||||
|
@ -1944,8 +1944,7 @@ impl Structure for DesertCityMultiPlot {
|
||||
let stair_radius = tower_length + 1;
|
||||
let stairs_clear = painter.aabb(Aabb {
|
||||
min: (bldg_a_center - stair_radius).with_z(base),
|
||||
max: (bldg_a_center + stair_radius)
|
||||
.with_z(base + tower_height + 2),
|
||||
max: (bldg_a_center + stair_radius).with_z(base + tower_height + 2),
|
||||
});
|
||||
stairs_clear
|
||||
.sample(spiral_staircase(
|
||||
|
Loading…
Reference in New Issue
Block a user