Skip to content

Commit

Permalink
some clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mockersf committed Aug 3, 2024
1 parent 4547d0b commit 7514de4
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 72 deletions.
2 changes: 1 addition & 1 deletion examples/auto_navmesh_aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn setup(mut commands: Commands) {
commands.spawn(NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(0.0, 0.0),
vec2(MESH_WIDTH as f32, 0.0),
vec2(MESH_WIDTH as f32, MESH_HEIGHT as f32),
Expand Down
2 changes: 1 addition & 1 deletion examples/auto_navmesh_avian2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ fn setup(
commands.spawn(NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(-500.0, -500.0),
vec2(500.0, -500.0),
vec2(500.0, 500.0),
Expand Down
2 changes: 1 addition & 1 deletion examples/auto_navmesh_avian3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn setup(
commands.spawn((NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(-25.0, -25.0),
vec2(25.0, -25.0),
vec2(25.0, 25.0),
Expand Down
2 changes: 1 addition & 1 deletion examples/auto_navmesh_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ fn setup(mut commands: Commands) {
commands.spawn(NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(0.0, 0.0),
vec2(MESH_WIDTH as f32, 0.0),
vec2(MESH_WIDTH as f32, MESH_HEIGHT as f32),
Expand Down
14 changes: 6 additions & 8 deletions examples/demo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ fn random_obstacle(mut commands: Commands, mut meshes: ResMut<Assets<Mesh>>) {
))
.with_rotation(Quat::from_rotation_y(rng.gen_range(0.0..PI)))
.with_scale(Vec3::splat(0.0));
new_obstacle(&mut commands, &mut rng, transform, &mut *meshes, &mat);
new_obstacle(&mut commands, &mut rng, transform, &mut meshes, &mat);
}

fn setup(mut commands: Commands, mut materials: ResMut<Assets<StandardMaterial>>) {
Expand Down Expand Up @@ -218,7 +218,7 @@ fn setup(mut commands: Commands, mut materials: ResMut<Assets<StandardMaterial>>
commands.spawn(NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(0.0, 0.0),
vec2(MESH_WIDTH as f32, 0.0),
vec2(MESH_WIDTH as f32, MESH_HEIGHT as f32),
Expand Down Expand Up @@ -444,12 +444,10 @@ fn display_mesh(
*current_mesh_entity = Some(
commands
.spawn(PbrBundle {
mesh: meshes
.add(Plane3d::new(
Vec3::Y,
Vec2::new(MESH_WIDTH as f32 / 2.0, MESH_HEIGHT as f32 / 2.0),
))
.into(),
mesh: meshes.add(Plane3d::new(
Vec3::Y,
Vec2::new(MESH_WIDTH as f32 / 2.0, MESH_HEIGHT as f32 / 2.0),
)),
transform: Transform::from_translation(Vec3::new(
(MESH_WIDTH as f32) / 2.0,
0.0,
Expand Down
14 changes: 4 additions & 10 deletions examples/gltf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,7 @@ fn give_target_auto(
let target_id = commands
.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(Sphere {
radius: 0.5,
..default()
})),
mesh: meshes.add(Mesh::from(Sphere { radius: 0.5 })),
material: materials.add(StandardMaterial {
base_color: palettes::css::RED.into(),
emissive: (palettes::css::RED * 5.0).into(),
Expand All @@ -342,7 +339,7 @@ fn give_target_auto(
})
.id();
commands.entity(entity).insert(Path {
current: first.clone(),
current: *first,
next: remaining,
});
object.0 = Some(target_id);
Expand Down Expand Up @@ -386,10 +383,7 @@ fn give_target_on_click(
let target_id = commands
.spawn((
PbrBundle {
mesh: meshes.add(Mesh::from(Sphere {
radius: 0.5,
..default()
})),
mesh: meshes.add(Mesh::from(Sphere { radius: 0.5 })),
material: materials.add(StandardMaterial {
base_color: palettes::css::RED.into(),
emissive: (palettes::css::RED * 5.0).into(),
Expand All @@ -415,7 +409,7 @@ fn give_target_on_click(
})
.id();
commands.entity(entity).insert(Path {
current: first.clone(),
current: *first,
next: remaining,
});
object.0 = Some(target_id);
Expand Down
32 changes: 1 addition & 31 deletions examples/gltf_avian3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,10 @@ use bevy::{
pbr::NotShadowCaster,
prelude::*,
time::common_conditions::on_timer,
window::PrimaryWindow,
};
use polyanya::Triangulation;
use rand::Rng;
use std::{
f32::consts::{FRAC_PI_2, FRAC_PI_4, PI},
time::Duration,
};
use std::{f32::consts::FRAC_PI_2, time::Duration};
use vleue_navigator::{
prelude::{NavMeshBundle, NavMeshSettings, NavMeshUpdateMode, NavmeshUpdaterPlugin},
NavMesh, NavMeshDebug, VleueNavigatorPlugin,
Expand Down Expand Up @@ -49,7 +45,6 @@ fn main() {
Update,
(
give_target_auto,
give_target_on_click,
move_object,
move_hover,
target_activity,
Expand Down Expand Up @@ -355,31 +350,6 @@ fn refresh_path(
}
}

fn give_target_on_click(
mut commands: Commands,
mut object_query: Query<(Entity, &Transform, &mut Object)>,
targets: Query<Entity, With<Target>>,
navmeshes: Res<Assets<NavMesh>>,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
mouse_buttons: Res<ButtonInput<MouseButton>>,
primary_window: Query<&Window, With<PrimaryWindow>>,
camera: Query<(&Camera, &GlobalTransform)>,
) {
if mouse_buttons.just_pressed(MouseButton::Left) {
let navmesh = navmeshes.get(&Handle::default()).unwrap();

let position = primary_window.single().cursor_position().unwrap();
let (camera, transform) = camera.get_single().ok().unwrap();
let ray = camera.viewport_to_world(transform, position).unwrap();
let denom = Vec3::Y.dot(ray.direction.into());
let t = (Vec3::ZERO - ray.origin).dot(Vec3::Y) / denom;
let target = ray.origin + ray.direction * t;
let position = navmesh.transformed_is_in_mesh(target).then_some(target);
eprintln!("{:?} -> {:?}", target, position);
}
}

fn move_object(
mut commands: Commands,
mut object_query: Query<(&mut Transform, &mut Path, Entity, &mut Object)>,
Expand Down
8 changes: 4 additions & 4 deletions examples/helpers/agent2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn give_target_to_navigator<const SIZE: u32, const X: u32, const Y: u32>(
};
if let Some((first, remaining)) = path.path.split_first() {
let mut remaining = remaining
.into_iter()
.iter()
.map(|p| (p.xy() - Vec2::new(X as f32, Y as f32) / 2.0) * factor)
.collect::<Vec<_>>();
remaining.reverse();
Expand Down Expand Up @@ -134,7 +134,7 @@ pub fn refresh_path<const SIZE: u32, const X: u32, const Y: u32>(
};
if let Some((first, remaining)) = new_path.path.split_first() {
let mut remaining = remaining
.into_iter()
.iter()
.map(|p| (p.xy() - Vec2::new(X as f32, Y as f32) / 2.0) * factor)
.collect::<Vec<_>>();
remaining.reverse();
Expand Down Expand Up @@ -171,10 +171,10 @@ pub fn display_navigator_path(navigator: Query<(&Transform, &Path)>, mut gizmos:
return;
};
let mut to_display = path.next.clone();
to_display.push(path.current.clone());
to_display.push(path.current);
to_display.push(transform.translation.xy());
to_display.reverse();
if to_display.len() >= 1 {
if !to_display.is_empty() {
gizmos.linestrip_2d(to_display, palettes::css::YELLOW);
}
}
10 changes: 5 additions & 5 deletions examples/helpers/agent3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn give_target_to_navigator<const SIZE: u32, const X: u32, const Y: u32>(
continue;
};
if let Some((first, remaining)) = path.path.split_first() {
let mut remaining = remaining.into_iter().cloned().collect::<Vec<_>>();
let mut remaining = remaining.iter().cloned().collect::<Vec<_>>();
remaining.reverse();
let id = commands
.spawn(PbrBundle {
Expand Down Expand Up @@ -151,7 +151,7 @@ pub fn refresh_path<const SIZE: u32, const X: u32, const Y: u32>(
navmesh.set_delta(0.0);
if !navmesh.transformed_is_in_mesh(transform.translation) {
let delta_for_entity = deltas.entry(entity).or_insert(0.0);
*delta_for_entity = *delta_for_entity + 0.1;
*delta_for_entity += 0.1;
navmesh.set_delta(*delta_for_entity);
continue;
}
Expand All @@ -167,7 +167,7 @@ pub fn refresh_path<const SIZE: u32, const X: u32, const Y: u32>(
continue;
};
if let Some((first, remaining)) = new_path.path.split_first() {
let mut remaining = remaining.into_iter().cloned().collect::<Vec<_>>();
let mut remaining = remaining.iter().cloned().collect::<Vec<_>>();
remaining.reverse();
path.current = *first;
path.next = remaining;
Expand Down Expand Up @@ -203,10 +203,10 @@ pub fn display_navigator_path(
) {
for (transform, path, navigator) in &navigator {
let mut to_display = path.next.clone();
to_display.push(path.current.clone());
to_display.push(path.current);
to_display.push(transform.translation);
to_display.reverse();
if to_display.len() >= 1 {
if !to_display.is_empty() {
gizmos.linestrip(
to_display.iter().map(|xz| Vec3::new(xz.x, 0.1, xz.z)),
navigator.color,
Expand Down
2 changes: 1 addition & 1 deletion examples/helpers/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ pub fn update_settings<const STEP: u32>(
settings.simplify = (settings.simplify + STEP as f32 / 1000.0).min(10.0);
}
UiSettingsButtons::MergeStepsDec => {
settings.merge_steps = settings.merge_steps.checked_sub(1).unwrap_or(0);
settings.merge_steps = settings.merge_steps.saturating_sub(1);
}
UiSettingsButtons::MergeStepsInc => {
settings.merge_steps = (settings.merge_steps + 1).min(5);
Expand Down
16 changes: 7 additions & 9 deletions examples/primitive_3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn setup(
NavMeshBundle {
settings: NavMeshSettings {
// Define the outer borders of the navmesh.
fixed: Triangulation::from_outer_edges(&vec![
fixed: Triangulation::from_outer_edges(&[
vec2(0.0, 0.0),
vec2(MESH_WIDTH as f32, 0.0),
vec2(MESH_WIDTH as f32, MESH_HEIGHT as f32),
Expand All @@ -129,12 +129,10 @@ fn setup(
));

commands.spawn(PbrBundle {
mesh: meshes
.add(Plane3d::new(
Vec3::Y,
Vec2::new(MESH_WIDTH as f32 / 2.0, MESH_HEIGHT as f32 / 2.0),
))
.into(),
mesh: meshes.add(Plane3d::new(
Vec3::Y,
Vec2::new(MESH_WIDTH as f32 / 2.0, MESH_HEIGHT as f32 / 2.0),
)),
transform: Transform::from_translation(Vec3::new(
MESH_WIDTH as f32 / 2.0,
0.0,
Expand Down Expand Up @@ -163,7 +161,7 @@ fn setup(
rng.gen_range(0.0..(MESH_HEIGHT as f32)),
))
.with_rotation(Quat::from_rotation_y(rng.gen_range(0.0..PI)));
new_obstacle(&mut commands, &mut rng, transform, &mut *meshes, &mat);
new_obstacle(&mut commands, &mut rng, transform, &mut meshes, &mat);
}
}

Expand Down Expand Up @@ -371,7 +369,7 @@ fn spawn_obstacle_on_click(
)));
let transform = Transform::from_translation(position)
.with_rotation(Quat::from_rotation_y(rng.gen_range(0.0..PI)));
new_obstacle(&mut commands, &mut rng, transform, &mut *meshes, &mat);
new_obstacle(&mut commands, &mut rng, transform, &mut meshes, &mat);
info!("spawning an obstacle at {}", position);
}
}
Expand Down

0 comments on commit 7514de4

Please sign in to comment.