Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Replace default method calls from Glam types with explicit const #1645

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions crates/bevy_gltf/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async fn load_gltf<'a, 'b>(
let mut world = World::default();
world
.spawn()
.insert_bundle((Transform::default(), GlobalTransform::default()))
.insert_bundle((Transform::identity(), GlobalTransform::identity()))
.with_children(|parent| {
for node in scene.nodes() {
let result = load_node(&node, parent, load_context, &buffer_data);
Expand Down Expand Up @@ -297,7 +297,7 @@ fn load_node(
let mut gltf_error = None;
let node = world_builder.spawn((
Transform::from_matrix(Mat4::from_cols_array_2d(&transform.matrix())),
GlobalTransform::default(),
GlobalTransform::identity(),
));

if let Some(name) = gltf_node.name() {
Expand Down Expand Up @@ -564,7 +564,7 @@ mod test {
GltfNode {
children: vec![],
mesh: None,
transform: bevy_transform::prelude::Transform::default(),
transform: bevy_transform::prelude::Transform::identity(),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/bevy_render/src/mesh/shape/capsule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ impl From<Capsule> for Mesh {
// Initialize arrays.
let vert_len = vert_offset_south_cap + longitudes;

let mut vs: Vec<Vec3> = vec![Vec3::default(); vert_len];
let mut vts: Vec<Vec2> = vec![Vec2::default(); vert_len];
let mut vns: Vec<Vec3> = vec![Vec3::default(); vert_len];
let mut vs: Vec<Vec3> = vec![Vec3::ZERO; vert_len];
let mut vts: Vec<Vec2> = vec![Vec2::ZERO; vert_len];
let mut vns: Vec<Vec3> = vec![Vec3::ZERO; vert_len];

let to_theta = 2.0 * std::f32::consts::PI / longitudes as f32;
let to_phi = std::f32::consts::PI / latitudes as f32;
Expand All @@ -106,8 +106,8 @@ impl From<Capsule> for Mesh {
let vt_aspect_north = 1.0 - vt_aspect_ratio;
let vt_aspect_south = vt_aspect_ratio;

let mut theta_cartesian: Vec<Vec2> = vec![Vec2::default(); longitudes];
let mut rho_theta_cartesian: Vec<Vec2> = vec![Vec2::default(); longitudes];
let mut theta_cartesian: Vec<Vec2> = vec![Vec2::ZERO; longitudes];
let mut rho_theta_cartesian: Vec<Vec2> = vec![Vec2::ZERO; longitudes];
let mut s_texture_cache: Vec<f32> = vec![0.0; lonsp1];

for j in 0..longitudes {
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_transform/src/components/global_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl GlobalTransform {
}

#[inline]
pub fn identity() -> Self {
pub const fn identity() -> Self {
GlobalTransform {
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl Transform {
}

#[inline]
pub fn identity() -> Self {
pub const fn identity() -> Self {
Transform {
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_ui/src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ mod tests {
use super::{ui_z_system, UI_Z_STEP};

fn node_with_transform(name: &str) -> (String, Node, Transform) {
(name.to_owned(), Node::default(), Transform::default())
(name.to_owned(), Node::default(), Transform::identity())
}

fn node_without_transform(name: &str) -> (String, Node) {
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/3d_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/msaa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-3.0, 3.0, 5.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(-3.0, 3.0, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/parenting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/spawner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 15.0, 150.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(0.0, 15.0, 150.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});

Expand Down
2 changes: 1 addition & 1 deletion examples/3d/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(3.0, 5.0, 8.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/update_gltf_scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn setup(
commands
.spawn((
Transform::from_xyz(0.0, 0.0, -1.0),
GlobalTransform::default(),
GlobalTransform::identity(),
))
.with_children(|parent| {
parent.spawn_scene(asset_server.load("models/FlightHelmet/FlightHelmet.gltf#Scene0"));
Expand Down
2 changes: 1 addition & 1 deletion examples/3d/wireframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/3d/z_sort_debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(5.0, 10.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/android/android.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/asset/asset_loading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 3.0, 10.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(0.0, 3.0, 10.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/asset/hot_asset_reloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(2.0, 2.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/ecs/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct MyComponent(f64);

fn setup(mut commands: Commands) {
commands.spawn((MyComponent(0.),));
commands.spawn((Transform::default(),));
commands.spawn((Transform::identity(),));
}

fn change_component(time: Res<Time>, mut query: Query<(Entity, &mut MyComponent)>) {
Expand Down
4 changes: 2 additions & 2 deletions examples/ecs/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ fn movement(
mut query: Query<&mut Transform, With<Sprite>>,
) {
for mut transform in query.iter_mut() {
let mut direction = Vec3::default();
let mut direction = Vec3::ZERO;
if input.pressed(KeyCode::Left) {
direction.x += 1.0;
}
Expand All @@ -134,7 +134,7 @@ fn movement(
direction.y -= 1.0;
}

if direction != Vec3::default() {
if direction != Vec3::ZERO {
transform.translation += direction.normalize() * SPEED * time.delta_seconds();
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/game/alien_cake_addict.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
commands
.spawn((
Transform::from_xyz(i as f32, height - 0.2, j as f32),
GlobalTransform::default(),
GlobalTransform::identity(),
))
.with_children(|cell| {
cell.spawn_scene(cell_scene.clone());
Expand All @@ -160,7 +160,7 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, mut game: ResMu
rotation: Quat::from_rotation_y(-std::f32::consts::FRAC_PI_2),
..Default::default()
},
GlobalTransform::default(),
GlobalTransform::identity(),
))
.with_children(|cell| {
cell.spawn_scene(asset_server.load("models/AlienCake/alien.glb#Scene0"));
Expand Down Expand Up @@ -336,7 +336,7 @@ fn spawn_bonus(
),
..Default::default()
},
GlobalTransform::default(),
GlobalTransform::identity(),
))
.with_children(|cell| {
cell.spawn_scene(game.bonus.handle.clone());
Expand Down
2 changes: 1 addition & 1 deletion examples/ios/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn setup(
})
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(-2.0, 2.5, 5.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/scene/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn save_scene_system(world: &mut World) {
scene_world.spawn().insert_bundle((
component_b,
ComponentA { x: 1.0, y: 2.0 },
Transform::default(),
Transform::identity(),
));
scene_world
.spawn()
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/array_texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn setup(
.unwrap();

commands.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(2.0, 2.0, 2.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/hot_shader_reloading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/shader/mesh_custom_attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/shader/shader_custom_material.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn setup(
.with(material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
2 changes: 1 addition & 1 deletion examples/shader/shader_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn setup(
.with(blue_material)
// camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(3.0, 5.0, -8.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}
4 changes: 2 additions & 2 deletions examples/window/multiple_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ fn setup_pipeline(
})
// main camera
.spawn(PerspectiveCameraBundle {
transform: Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(0.0, 0.0, 6.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
})
// second window camera
Expand All @@ -200,7 +200,7 @@ fn setup_pipeline(
window: window_id,
..Default::default()
},
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::default(), Vec3::Y),
transform: Transform::from_xyz(6.0, 0.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..Default::default()
});
}