diff --git a/.gitignore b/.gitignore index c0bf137..3204f7e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Generated by Cargo # will have compiled files and executables -/target/ +/target /examples/target/ /serialize_test/ .vscode diff --git a/Cargo.toml b/Cargo.toml index 74e4e7e..70db94d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,8 +19,8 @@ exclude = [ [dependencies] bitflags = "2.2.1" serde = {version = "1.0.163", features = ["derive"], optional = true} -strum = {version = "0.24.1", optional = true} -strum_macros = {version ="0.24.3", optional = true} +strum = {version = "0.27.2", optional = true} +strum_macros = {version ="0.27.2", optional = true} [features] serde_support = ["serde", "strum", "strum_macros"] diff --git a/examples/testbed/main_loop.rs b/examples/testbed/main_loop.rs index fba529f..1a19c91 100644 --- a/examples/testbed/main_loop.rs +++ b/examples/testbed/main_loop.rs @@ -31,7 +31,7 @@ pub struct System { pub imgui: Context, pub platform: WinitPlatform, pub renderer: Renderer, - pub font_size: f32, + // pub font_size: f32, pub(crate) s_settings: Settings, } @@ -102,7 +102,7 @@ pub fn init(title: &str) -> System { imgui, platform, renderer, - font_size, + // font_size, s_settings, } } @@ -174,8 +174,8 @@ impl System { target.clear_color(0.2, 0.2, 0.2, 1.0); platform.prepare_render(&ui, gl_window.window()); - if g_debug_draw.borrow().m_show_ui - { + if g_debug_draw.borrow().m_show_ui + { s_test.borrow().get_base().borrow_mut().draw_title( &ui, &format!( @@ -183,7 +183,7 @@ impl System { g_test_entries[s_settings.m_test_index as usize].category, g_test_entries[s_settings.m_test_index as usize].name ), - ); + ); } s_test.borrow_mut().step( @@ -245,7 +245,7 @@ impl System { device_id: _, is_synthetic: _, } => { - if input.state == ElementState::Pressed + if input.state == ElementState::Pressed { match input.virtual_keycode { Some(VirtualKeyCode::Escape) => { @@ -329,8 +329,8 @@ impl System { Some(VirtualKeyCode::P) => { s_settings.m_pause = !s_settings.m_pause; }, - Some(VirtualKeyCode::LBracket) => { - // Switch to previous test + Some(VirtualKeyCode::LBracket) => { + // Switch to previous test if s_settings.m_test_index==0 { s_settings.m_test_index = g_test_entries.len()-1; }else{ @@ -359,9 +359,9 @@ impl System { d.m_show_ui = !d.m_show_ui; }, _ => {}, - } - } - s_test.borrow_mut().keyboard(input); + } + } + s_test.borrow_mut().keyboard(input); } WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit, _ => (), @@ -394,7 +394,7 @@ impl System { s_test: TestPtr, cursor_position: PhysicalPosition, g_camera: &mut Camera, - button: &MouseButton, + button: &MouseButton, action: &ElementState, mods: &ModifiersState, s_right_mouse_down: &mut bool, @@ -419,7 +419,7 @@ impl System { s_test.borrow_mut().mouse_down(pw); } } - + if *action == ElementState::Released { s_test.borrow_mut().mouse_up(pw); @@ -428,7 +428,7 @@ impl System { else if *button == MouseButton::Right { if *action == ElementState::Pressed - { + { *s_click_point_ws = g_camera.convert_screen_to_world(ps); *s_right_mouse_down = true; } @@ -440,7 +440,7 @@ impl System { } } - fn mouse_motion_callback<'a, D: UserDataType, F: Facade>(s_test: TestPtr, + fn mouse_motion_callback<'a, D: UserDataType, F: Facade>(s_test: TestPtr, g_camera: &mut Camera, position: &PhysicalPosition, s_right_mouse_down: &mut bool, s_click_point_ws: &mut B2vec2) @@ -449,7 +449,7 @@ impl System { let pw: B2vec2 = g_camera.convert_screen_to_world(ps); s_test.borrow_mut().mouse_move(pw); - + if *s_right_mouse_down { let diff: B2vec2 = pw - *s_click_point_ws; @@ -501,7 +501,7 @@ impl System { ui.slider_config("Vel Iters", 0, 50) .display_format("%d") .build(&mut s_settings.m_velocity_iterations); - + ui.slider_config("Pos Iter", 0, 50) .display_format("%d") .build(&mut s_settings.m_position_iterations); @@ -516,7 +516,7 @@ impl System { ui.checkbox("Warm Starting", &mut s_settings.m_enable_warm_starting); ui.checkbox("Time of Impact", &mut s_settings.m_enable_continuous); ui.checkbox("Sub-Stepping", &mut s_settings.m_enable_sub_stepping); - + ui.separator(); ui.checkbox("Shapes", &mut s_settings.m_draw_shapes); diff --git a/examples/testbed/test.rs b/examples/testbed/test.rs index 93289e4..2c6d8fc 100644 --- a/examples/testbed/test.rs +++ b/examples/testbed/test.rs @@ -38,7 +38,7 @@ pub(crate) fn random_float_range(lo: f32, hi: f32) -> f32 { // This is called when a joint in the world is implicitly destroyed // because an attached body is destroyed. This gives us a chance to // nullify the mouse joint. -pub(crate)struct B2testDestructionListenerDefault +pub(crate)struct B2testDestructionListenerDefault { pub(crate) base: TestBasePtrWeak, } @@ -80,10 +80,10 @@ pub(crate) struct ContactPoint { pub(crate) state: B2pointState, pub(crate) normal_impulse: f32, pub(crate) tangent_impulse: f32, - pub(crate) separation: f32, + // pub(crate) separation: f32, } -pub(crate)struct B2testContactListenerDefault +pub(crate)struct B2testContactListenerDefault { pub(crate) base: TestBasePtrWeak, } @@ -108,7 +108,7 @@ pub(crate) type TestPtr = Rc>>; pub(crate) trait TestDyn { fn get_base(&self) -> TestBasePtr; - + fn step(&mut self, ui: &imgui::Ui, display: &F, target: &mut glium::Frame, settings: &mut Settings, camera: &mut Camera); fn update_ui(&mut self, _ui: &imgui::Ui) {} fn keyboard(&mut self, key: &KeyboardInput) { @@ -129,17 +129,22 @@ pub(crate) trait TestDyn fn launch_bomb_rand(&mut self) { private::launch_bomb_rand(&mut self.get_base().borrow_mut()); } + + #[allow(dead_code)] fn launch_bomb(&mut self, position: B2vec2, velocity: B2vec2) { private::launch_bomb(&mut self.get_base().borrow_mut(), position, velocity); } + #[allow(dead_code)] fn spawn_bomb(&mut self, world_pt: B2vec2) { private::spawn_bomb(&mut self.get_base().borrow_mut(), world_pt); } + #[allow(dead_code)] fn complete_bomb_spawn(&mut self, p: B2vec2) { private::complete_bomb_spawn(&mut self.get_base().borrow_mut(), p); } // Let derived tests know that a joint was destroyed. + #[allow(dead_code)] fn joint_destroyed(&mut self, joint: B2jointPtr) { b2_not_used(joint); } diff --git a/examples/testbed/test_private.rs b/examples/testbed/test_private.rs index 6c85f8a..e8a1e7e 100644 --- a/examples/testbed/test_private.rs +++ b/examples/testbed/test_private.rs @@ -63,7 +63,7 @@ pub(crate) fn pre_solve( state: state2[i], normal_impulse: manifold.points[i].normal_impulse, tangent_impulse: manifold.points[i].tangent_impulse, - separation: world_manifold.separations[i], + // separation: world_manifold.separations[i], }); } } @@ -117,7 +117,7 @@ pub(crate) fn mouse_down(self_: &mut Test, p: B2vec2) { { let frequency_hz: f32 = 5.0; let damping_ratio: f32 = 0.7; - + jd = B2mouseJointDef { base: B2jointDef { jtype: B2jointType::EMouseJoint, diff --git a/examples/testbed/tests/rope.rs b/examples/testbed/tests/rope.rs index 8af382e..9cedd18 100644 --- a/examples/testbed/tests/rope.rs +++ b/examples/testbed/tests/rope.rs @@ -139,7 +139,7 @@ impl TestDyn for Rope { .build(|| { ui.separator(); //TODO_humman sys::igGetWindowWidth() - let width_token = ui.push_item_width(200.0 * 0.5); + let _width_token = ui.push_item_width(200.0 * 0.5); let bend_models = ["Spring", "PBD Ang", "XPBD Ang", "PBD Dist", "PBD Height", "PBD Triangle"]; let stretch_models = ["PBD", "XPBD"]; @@ -171,7 +171,7 @@ impl TestDyn for Rope { } _ => {} } - } + } } ui.slider_config("Damping##B1", 0.0, 4.0) @@ -255,7 +255,7 @@ impl TestDyn for Rope { *bend_model2 = B2bendingModel::B2PbdHeightBendingModel; } _ => {} - } + } } } ui.slider_config("Damping##B2", 0.0, 4.0) @@ -268,7 +268,7 @@ impl TestDyn for Rope { ui.slider_config("Stiffness##B2", 0.0, 1.0) .display_format("%.1f") - .build(&mut self.m_tuning2.bend_stiffness); + .build(&mut self.m_tuning2.bend_stiffness); ui.checkbox( "Isometric##2", @@ -287,7 +287,7 @@ impl TestDyn for Rope { let stretch_model2 = &mut self.m_tuning2.stretching_model; let mut stretch_model2_selected: usize = *stretch_model2 as usize; if ui.combo_simple_string("Stretch Model##2", &mut stretch_model2_selected, &stretch_models) { - + match stretch_model2_selected { 0 => { *stretch_model2 = B2stretchingModel::B2PbdStretchingModel; @@ -297,7 +297,7 @@ impl TestDyn for Rope { } _ => {} } - + } } @@ -330,11 +330,11 @@ impl TestDyn for Rope { self.m_rope1.reset(self.m_position1); self.m_rope2.reset(self.m_position2); } - + //TODO_humman fix //width_token.pop(ui); - }); - + }); + } fn keyboard(&mut self, key: &KeyboardInput) { match key.virtual_keycode { diff --git a/src/b2_body.rs b/src/b2_body.rs index c6212b6..99c1c7a 100644 --- a/src/b2_body.rs +++ b/src/b2_body.rs @@ -32,14 +32,14 @@ pub enum B2bodyType { impl Default for B2bodyType { fn default() -> Self { - return B2bodyType::B2StaticBody; + B2bodyType::B2StaticBody } } impl Default for B2bodyDef { /// This constructor sets the body definition default values. fn default() -> Self { - return Self { + Self { position: B2vec2::zero(), angle: 0.0, linear_velocity: B2vec2::zero(), @@ -54,21 +54,21 @@ impl Default for B2bodyDef { enabled: true, gravity_scale: 1.0, user_data: None, - }; + } } } impl LinkedListNode> for B2body { fn get_next(&self) -> Option> { - return self.m_next.clone(); + self.m_next.clone() } fn set_next(&mut self, value: Option>) { self.m_next = value; } fn take_next(&mut self) -> Option> { - return self.m_next.take(); + self.m_next.take() } } @@ -76,7 +76,7 @@ impl DoubleLinkedListNode> for B2body { fn get_prev(&self) -> Option> { - return self.m_prev.clone(); + self.m_prev.clone() } fn set_prev(&mut self, value: Option>) { @@ -231,7 +231,7 @@ impl B2body { /// Warning: This function is locked during callbacks. ///

pub fn create_fixture(self_: BodyPtr, def: &B2fixtureDef) -> FixturePtr { - return private::create_fixture(self_, def); + private::create_fixture(self_, def) } /// Creates a fixture from a shape and attach it to this body. @@ -244,7 +244,7 @@ impl B2body { /// Warning: This function is locked during callbacks. ///

pub fn create_fixture_by_shape(self_: BodyPtr, shape: ShapeDefPtr, density: f32) -> FixturePtr { - return private::create_fixture_by_shape(self_, shape, density); + private::create_fixture_by_shape(self_, shape, density) } /// destroy a fixture. This removes the fixture from the broad-phase and @@ -273,31 +273,31 @@ impl B2body { /// /// @return the world transform of the body's origin. pub fn get_transform(&self) -> B2Transform { - return inline::get_transform(self); + inline::get_transform(self) } /// Get the world body origin position. /// /// @return the world position of the body's origin. pub fn get_position(&self) -> B2vec2 { - return inline::get_position(self); + inline::get_position(self) } /// Get the angle in radians. /// /// @return the current world rotation angle in radians. pub fn get_angle(&self) -> f32 { - return inline::get_angle(self); + inline::get_angle(self) } /// Get the world position of the center of mass. pub fn get_world_center(&self) -> B2vec2 { - return inline::get_world_center(self); + inline::get_world_center(self) } /// Get the local position of the center of mass. pub fn get_local_center(&self) -> B2vec2 { - return inline::get_local_center(self); + inline::get_local_center(self) } /// Set the linear velocity of the center of mass. @@ -310,7 +310,7 @@ impl B2body { /// /// @return the linear velocity of the center of mass. pub fn get_linear_velocity(&self) -> B2vec2 { - return inline::get_linear_velocity(self); + inline::get_linear_velocity(self) } /// Set the angular velocity. @@ -323,7 +323,7 @@ impl B2body { /// /// @return the angular velocity in radians/second. pub fn get_angular_velocity(&self) -> f32 { - return inline::get_angular_velocity(self); + inline::get_angular_velocity(self) } /// Apply a force at a world point. If the force is not @@ -379,14 +379,14 @@ impl B2body { /// /// @return the mass, usually in kilograms (kg). pub fn get_mass(&self) -> f32 { - return inline::get_mass(self); + inline::get_mass(self) } /// Get the rotational inertia of the body about the local origin. /// /// @return the rotational inertia, usually in kg-m^2. pub fn get_inertia(&self) -> f32 { - return inline::get_inertia(self); + inline::get_inertia(self) } /// Get the mass data of the body. @@ -417,7 +417,7 @@ impl B2body { /// /// @return the same point expressed in world coordinates. pub fn get_world_point(&self, local_point: B2vec2) -> B2vec2 { - return inline::get_world_point(self, local_point); + inline::get_world_point(self, local_point) } /// Get the world coordinates of a vector given the local coordinates. @@ -425,7 +425,7 @@ impl B2body { /// /// @return the same vector expressed in world coordinates. pub fn get_world_vector(&self, local_vector: B2vec2) -> B2vec2 { - return inline::get_world_vector(self, local_vector); + inline::get_world_vector(self, local_vector) } /// Gets a local point relative to the body's origin given a world point. @@ -433,7 +433,7 @@ impl B2body { /// /// @return the corresponding local point relative to the body's origin. pub fn get_local_point(&self, world_point: B2vec2) -> B2vec2 { - return inline::get_local_point(self, world_point); + inline::get_local_point(self, world_point) } /// Gets a local vector given a world vector. @@ -441,7 +441,7 @@ impl B2body { /// /// @return the corresponding local vector. pub fn get_local_vector(&self, world_vector: B2vec2) -> B2vec2 { - return inline::get_local_vector(self, world_vector); + inline::get_local_vector(self, world_vector) } /// Get the world linear velocity of a world point attached to this body. @@ -449,7 +449,7 @@ impl B2body { /// /// @return the world velocity of a point. pub fn get_linear_velocity_from_world_point(&self, world_point: B2vec2) -> B2vec2 { - return inline::get_linear_velocity_from_world_point(self, world_point); + inline::get_linear_velocity_from_world_point(self, world_point) } /// Get the world velocity of a local point. @@ -457,12 +457,12 @@ impl B2body { /// /// @return the world velocity of a point. pub fn get_linear_velocity_from_local_point(&self, local_point: B2vec2) -> B2vec2 { - return inline::get_linear_velocity_from_local_point(self, local_point); + inline::get_linear_velocity_from_local_point(self, local_point) } /// Get the linear damping of the body. pub fn get_linear_damping(&self) -> f32 { - return inline::get_linear_damping(self); + inline::get_linear_damping(self) } /// Set the linear damping of the body. @@ -472,7 +472,7 @@ impl B2body { /// Get the angular damping of the body. pub fn get_angular_damping(&self) -> f32 { - return inline::get_angular_damping(self); + inline::get_angular_damping(self) } /// Set the angular damping of the body. @@ -482,7 +482,7 @@ impl B2body { /// Get the gravity scale of the body. pub fn get_gravity_scale(&self) -> f32 { - return inline::get_gravity_scale(self); + inline::get_gravity_scale(self) } /// Set the gravity scale of the body. @@ -497,7 +497,7 @@ impl B2body { /// Get the type of this body. pub fn get_type(&self) -> B2bodyType { - return inline::get_type(self); + inline::get_type(self) } /// Should this body be treated like a bullet for continuous collision detection? @@ -507,7 +507,7 @@ impl B2body { /// Is this body treated like a bullet for continuous collision detection? pub fn is_bullet(&self) -> bool { - return inline::is_bullet(self); + inline::is_bullet(self) } /// You can disable sleeping on this body. If you disable sleeping, the @@ -518,7 +518,7 @@ impl B2body { /// Is this body allowed to sleep pub fn is_sleeping_allowed(&self) -> bool { - return inline::is_sleeping_allowed(self); + inline::is_sleeping_allowed(self) } /// Set the sleep state of the body. A sleeping body has very @@ -532,7 +532,7 @@ impl B2body { /// /// @return true if the body is awake. pub fn is_awake(&self) -> bool { - return inline::is_awake(self); + inline::is_awake(self) } /// Allow a body to be disabled. A disabled body is not simulated and cannot @@ -553,7 +553,7 @@ impl B2body { /// Get the active state of the body. pub fn is_enabled(&self) -> bool { - return inline::is_enabled(self); + inline::is_enabled(self) } /// Set this body to have fixed rotation. This causes the mass @@ -564,12 +564,12 @@ impl B2body { /// Does this body have fixed rotation? pub fn is_fixed_rotation(&self) -> bool { - return inline::is_fixed_rotation(self); + inline::is_fixed_rotation(self) } /// Get the list of all fixtures attached to this body. pub fn get_fixture_list(&self) -> &LinkedList> { - return inline::get_fixture_list(self); + inline::get_fixture_list(self) } // pub fn get_fixture_list_mut(&mut self) -> &mut Option> { // return inline::get_fixture_list_mut(self); @@ -577,10 +577,10 @@ impl B2body { /// Get the list of all joints attached to this body. pub fn get_joint_list(&self) -> &DoubleLinkedList> { - return inline::get_joint_list(self); + inline::get_joint_list(self) } pub fn get_joint_list_mut(&mut self) -> &mut DoubleLinkedList> { - return inline::get_joint_list_mut(self); + inline::get_joint_list_mut(self) } /// Get the list of all contacts attached to this body. @@ -589,7 +589,7 @@ impl B2body { /// miss some collisions if you don't use B2contactListener. ///

pub fn get_contact_list(&self) -> &DoubleLinkedList> { - return inline::get_contact_list(self); + inline::get_contact_list(self) } // pub fn get_contact_list_mut(&mut self) -> &mut Option> { // return inline::get_contact_list_mut(self); @@ -597,12 +597,12 @@ impl B2body { /// Get the next body in the world's body list. pub fn get_next(&self) -> Option> { - return inline::get_next(self); + inline::get_next(self) } /// Get the user data pointer that was provided in the body definition. pub fn get_user_data(&self) -> Option { - return inline::get_user_data(self); + inline::get_user_data(self) } /// Set the user data. Use this to store your application specific data. @@ -612,13 +612,13 @@ impl B2body { /// Get the parent world of this body. pub fn get_world(&self) -> B2worldPtr { - return inline::get_world(self); + inline::get_world(self) } // private: pub(crate) fn new(bd: &B2bodyDef, world: B2worldPtr) -> Self { - return private::b2_body(bd, world); + private::b2_body(bd, world) } pub(crate) fn synchronize_fixtures(&mut self) { @@ -634,7 +634,7 @@ impl B2body { // This is used to prevent connected bodies from colliding. // It may lie, depending on the collide_connected flag. pub(crate) fn should_collide(&self, other: BodyPtr) -> bool { - return private::should_collide(self, other); + private::should_collide(self, other) } pub(crate) fn advance(&mut self, t: f32) { @@ -646,27 +646,27 @@ mod inline { use super::*; pub fn get_type(self_: &B2body) -> B2bodyType { - return self_.m_type; + self_.m_type } pub fn get_transform(self_: &B2body) -> B2Transform { - return self_.m_xf; + self_.m_xf } pub fn get_position(self_: &B2body) -> B2vec2 { - return self_.m_xf.p; + self_.m_xf.p } pub fn get_angle(self_: &B2body) -> f32 { - return self_.m_sweep.a; + self_.m_sweep.a } pub fn get_world_center(self_: &B2body) -> B2vec2 { - return self_.m_sweep.c; + self_.m_sweep.c } pub fn get_local_center(self_: &B2body) -> B2vec2 { - return self_.m_sweep.local_center; + self_.m_sweep.local_center } pub fn set_linear_velocity(self_: &mut B2body, v: B2vec2) { @@ -682,7 +682,7 @@ mod inline { } pub fn get_linear_velocity(self_: &B2body) -> B2vec2 { - return self_.m_linear_velocity; + self_.m_linear_velocity } pub fn set_angular_velocity(self_: &mut B2body, w: f32) { @@ -698,16 +698,16 @@ mod inline { } pub fn get_angular_velocity(self_: &B2body) -> f32 { - return self_.m_angular_velocity; + self_.m_angular_velocity } pub fn get_mass(self_: &B2body) -> f32 { - return self_.m_mass; + self_.m_mass } pub fn get_inertia(self_: &B2body) -> f32 { - return self_.m_i - + self_.m_mass * b2_dot(self_.m_sweep.local_center, self_.m_sweep.local_center); + self_.m_i + + self_.m_mass * b2_dot(self_.m_sweep.local_center, self_.m_sweep.local_center) } pub fn get_mass_data(self_: &B2body, data: &mut B2massData) { @@ -718,38 +718,38 @@ mod inline { } pub fn get_world_point(self_: &B2body, local_point: B2vec2) -> B2vec2 { - return b2_mul_transform_by_vec2(self_.m_xf, local_point); + b2_mul_transform_by_vec2(self_.m_xf, local_point) } pub fn get_world_vector(self_: &B2body, local_vector: B2vec2) -> B2vec2 { - return b2_mul_rot_by_vec2(self_.m_xf.q, local_vector); + b2_mul_rot_by_vec2(self_.m_xf.q, local_vector) } pub fn get_local_point(self_: &B2body, world_point: B2vec2) -> B2vec2 { - return b2_mul_t_transform_by_vec2(self_.m_xf, world_point); + b2_mul_t_transform_by_vec2(self_.m_xf, world_point) } pub fn get_local_vector(self_: &B2body, world_vector: B2vec2) -> B2vec2 { - return b2_mul_t_rot_by_vec2(self_.m_xf.q, world_vector); + b2_mul_t_rot_by_vec2(self_.m_xf.q, world_vector) } pub fn get_linear_velocity_from_world_point( self_: &B2body, world_point: B2vec2, ) -> B2vec2 { - return self_.m_linear_velocity - + b2_cross_scalar_by_vec(self_.m_angular_velocity, world_point - self_.m_sweep.c); + self_.m_linear_velocity + + b2_cross_scalar_by_vec(self_.m_angular_velocity, world_point - self_.m_sweep.c) } pub fn get_linear_velocity_from_local_point( self_: &B2body, local_point: B2vec2, ) -> B2vec2 { - return self_.get_linear_velocity_from_world_point(self_.get_world_point(local_point)); + self_.get_linear_velocity_from_world_point(self_.get_world_point(local_point)) } pub fn get_linear_damping(self_: &B2body) -> f32 { - return self_.m_linear_damping; + self_.m_linear_damping } pub fn set_linear_damping(self_: &mut B2body, linear_damping: f32) { @@ -757,7 +757,7 @@ mod inline { } pub fn get_angular_damping(self_: &B2body) -> f32 { - return self_.m_angular_damping; + self_.m_angular_damping } pub fn set_angular_damping(self_: &mut B2body, angular_damping: f32) { @@ -765,7 +765,7 @@ mod inline { } pub fn get_gravity_scale(self_: &B2body) -> f32 { - return self_.m_gravity_scale; + self_.m_gravity_scale } pub fn set_gravity_scale(self_: &mut B2body, scale: f32) { @@ -777,7 +777,7 @@ mod inline { } pub fn is_bullet(self_: &B2body) -> bool { - return self_.m_flags.contains(BodyFlags::E_BULLET_FLAG); + self_.m_flags.contains(BodyFlags::E_BULLET_FLAG) } pub fn set_awake(self_: &mut B2body, flag: bool) { @@ -801,15 +801,15 @@ mod inline { } pub fn is_awake(self_: &B2body) -> bool { - return self_.m_flags.contains(BodyFlags::E_AWAKE_FLAG); + self_.m_flags.contains(BodyFlags::E_AWAKE_FLAG) } pub fn is_enabled(self_: &B2body) -> bool { - return self_.m_flags.contains(BodyFlags::E_ENABLED_FLAG); + self_.m_flags.contains(BodyFlags::E_ENABLED_FLAG) } pub fn is_fixed_rotation(self_: &B2body) -> bool { - return self_.m_flags.contains(BodyFlags::E_FIXED_ROTATION_FLAG); + self_.m_flags.contains(BodyFlags::E_FIXED_ROTATION_FLAG) } pub fn set_sleeping_allowed(self_: &mut B2body, flag: bool) { @@ -821,7 +821,7 @@ mod inline { } pub fn is_sleeping_allowed(self_: &B2body) -> bool { - return self_.m_flags.contains(BodyFlags::E_AUTO_SLEEP_FLAG); + self_.m_flags.contains(BodyFlags::E_AUTO_SLEEP_FLAG) } // pub fn get_fixture_list_mut( @@ -831,17 +831,17 @@ mod inline { // } pub fn get_fixture_list(self_: &B2body) -> &LinkedList> { - return &self_.m_fixture_list; + &self_.m_fixture_list } pub fn get_joint_list_mut( self_: &mut B2body, ) -> &mut DoubleLinkedList> { - return &mut self_.m_joint_list; + &mut self_.m_joint_list } pub fn get_joint_list(self_: &B2body) -> &DoubleLinkedList> { - return &self_.m_joint_list; + &self_.m_joint_list } // pub fn get_contact_list_mut( @@ -851,11 +851,11 @@ mod inline { // } pub fn get_contact_list(self_: &B2body) -> &DoubleLinkedList> { - return &self_.m_contact_list; + &self_.m_contact_list } pub fn get_next(self_: &B2body) -> Option> { - return self_.m_next.clone(); + self_.m_next.clone() } pub fn set_user_data(self_: &mut B2body, data: &D::Body) { @@ -863,7 +863,7 @@ mod inline { } pub fn get_user_data(self_: &B2body) -> Option { - return self_.m_user_data.clone(); + self_.m_user_data.clone() } pub fn apply_force( @@ -986,6 +986,6 @@ mod inline { } pub fn get_world(self_: &B2body) -> B2worldPtr { - return self_.m_world.upgrade().unwrap(); + self_.m_world.upgrade().unwrap() } } diff --git a/src/b2_broad_phase.rs b/src/b2_broad_phase.rs index 96d8afe..d789e41 100644 --- a/src/b2_broad_phase.rs +++ b/src/b2_broad_phase.rs @@ -40,9 +40,15 @@ pub struct B2broadPhasePairs { pub const E_NULL_PROXY: i32 = -1; +impl Default for B2broadPhase { + fn default() -> Self { + Self::new() + } +} + impl B2broadPhase { pub fn new() -> Self { - return private::b2_broad_phase_b2_broad_phase(); + private::b2_broad_phase_b2_broad_phase() } //~B2broadPhase(); @@ -50,7 +56,7 @@ impl B2broadPhase { /// create a proxy with an initial AABB. Pairs are not reported until /// UpdatePairs is called. pub fn create_proxy(&mut self, aabb: B2AABB, user_data: &UserDataType) -> i32 { - return private::b2_broad_phase_create_proxy(self, aabb, user_data); + private::b2_broad_phase_create_proxy(self, aabb, user_data) } /// destroy a proxy. It is up to the client to remove any pairs. @@ -71,22 +77,22 @@ impl B2broadPhase { /// Get the fat AABB for a proxy. pub fn get_fat_aabb(&self, proxy_id: i32) -> B2AABB { - return inline::get_fat_aabb(self, proxy_id); + inline::get_fat_aabb(self, proxy_id) } /// Get user data from a proxy. Returns None if the id is invalid. pub fn get_user_data(&self, proxy_id: i32) -> Option { - return inline::get_user_data(self, proxy_id); + inline::get_user_data(self, proxy_id) } /// Test overlap of fat AABBs. pub fn test_overlap(&self, proxy_id_a: i32, proxy_id_b: i32) -> bool { - return inline::test_overlap(self, proxy_id_a, proxy_id_b); + inline::test_overlap(self, proxy_id_a, proxy_id_b) } /// Get the number of proxies. pub fn get_proxy_count(&self) -> i32 { - return inline::get_proxy_count(self); + inline::get_proxy_count(self) } /// update the pairs. This results in pair callbacks. This can only add pairs. @@ -116,17 +122,17 @@ impl B2broadPhase { /// Get the height of the embedded tree. pub fn get_tree_height(&self) -> i32 { - return inline::get_tree_height(self); + inline::get_tree_height(self) } /// Get the balance of the embedded tree. pub fn get_tree_balance(&self) -> i32 { - return inline::get_tree_balance(self); + inline::get_tree_balance(self) } /// Get the quality metric of the embedded tree. pub fn get_tree_quality(&self) -> f32 { - return inline::get_tree_quality(self); + inline::get_tree_quality(self) } /// Shift the world origin. Useful for large worlds. @@ -137,7 +143,7 @@ impl B2broadPhase { } pub fn get_tree_mut(&mut self)->&mut B2dynamicTree{ - return &mut self.m_tree; + &mut self.m_tree } pub(crate) fn buffer_move(&mut self, proxy_id: i32) { @@ -164,7 +170,7 @@ mod inline { self_: &B2broadPhase, proxy_id: i32, ) -> Option { - return self_.m_tree.get_user_data(proxy_id); + self_.m_tree.get_user_data(proxy_id) } pub fn test_overlap( @@ -174,27 +180,27 @@ mod inline { ) -> bool { let aabb_a: B2AABB = self_.m_tree.get_fat_aabb(proxy_id_a); let aabb_b: B2AABB = self_.m_tree.get_fat_aabb(proxy_id_b); - return b2_test_overlap(aabb_a, aabb_b); + b2_test_overlap(aabb_a, aabb_b) } pub fn get_fat_aabb(self_: &B2broadPhase, proxy_id: i32) -> B2AABB { - return self_.m_tree.get_fat_aabb(proxy_id); + self_.m_tree.get_fat_aabb(proxy_id) } pub fn get_proxy_count(self_: &B2broadPhase) -> i32 { - return self_.m_proxy_count; + self_.m_proxy_count } pub fn get_tree_height(self_: &B2broadPhase) -> i32 { - return self_.m_tree.get_height(); + self_.m_tree.get_height() } pub fn get_tree_balance(self_: &B2broadPhase) -> i32 { - return self_.m_tree.get_max_balance(); + self_.m_tree.get_max_balance() } pub fn get_tree_quality(self_: &B2broadPhase) -> f32 { - return self_.m_tree.get_area_ration(); + self_.m_tree.get_area_ration() } pub fn update_pairs>( @@ -220,7 +226,7 @@ mod inline { // query tree, create pairs and add them pair buffer. tree.query(|proxy_id:i32|->bool{ let moved = tree.was_moved(proxy_id); - return private::b2_broad_phase_query_callback(pairs, m_query_proxy_id, proxy_id, moved); + private::b2_broad_phase_query_callback(pairs, m_query_proxy_id, proxy_id, moved) }, fat_aabb); } } diff --git a/src/b2_collision.rs b/src/b2_collision.rs index 2edf854..a3efe26 100644 --- a/src/b2_collision.rs +++ b/src/b2_collision.rs @@ -1,3 +1,6 @@ +//! Structures and functions used for computing contact points, distance +//! queries, and TOI queries. + use crate::b2_math::*; use crate::b2_common::B2_MAX_MANIFOLD_POINTS; use crate::b2_shape::*; @@ -6,11 +9,8 @@ use crate::shapes::b2_circle_shape::*; use crate::shapes::b2_edge_shape::*; use crate::shapes::b2_polygon_shape::*; -/// @file -/// Structures and functions used for computing contact points, distance -/// queries, and TOI queries. -pub const B2_NULL_FEATURE: u8 = std::u8::MAX; +pub const B2_NULL_FEATURE: u8 = u8::MAX; pub enum B2contactFeatureType { EVertex = 0, @@ -68,19 +68,19 @@ pub enum B2manifoldType { impl Default for B2manifoldType { fn default() -> Self { - return B2manifoldType::ECircles; + B2manifoldType::ECircles } } impl Default for B2manifold { fn default() -> Self { - return B2manifold { + B2manifold { points: [B2manifoldPoint::default();B2_MAX_MANIFOLD_POINTS], local_normal: B2vec2::default(), local_point: B2vec2::default(), manifold_type: B2manifoldType::ECircles, point_count: 0, - }; + } } } @@ -88,14 +88,17 @@ impl Default for B2manifold { /// Box2D supports multiple types of contact: /// - clip point versus plane with radius /// - point versus point with radius (circles) +/// /// The local point usage depends on the manifold type: /// -e_circles: the local center of circle_a /// -e_faceA: the center of faceA /// -e_faceB: the center of faceB +/// /// Similarly the local normal usage: /// -e_circles: not used /// -e_faceA: the normal on polygon_a /// -e_faceB: the normal on polygon_b +/// /// We store contacts in this way so that position correction can /// account for movement, which is critical for continuous physics. /// All contact scenarios must be expressed in one of these types. @@ -208,24 +211,24 @@ pub struct B2AABB { impl B2AABB { /// Verify that the bounds are sorted. pub fn is_valid(self) -> bool { - return b2_aabb_is_valid(self); + b2_aabb_is_valid(self) } /// Get the center of the AABB. pub fn get_center(self) -> B2vec2 { - return 0.5 * (self.lower_bound + self.upper_bound); + 0.5 * (self.lower_bound + self.upper_bound) } /// Get the extents of the AABB (half-widths). pub fn get_extents(self) -> B2vec2 { - return 0.5 * (self.upper_bound - self.lower_bound); + 0.5 * (self.upper_bound - self.lower_bound) } /// Get the perimeter length pub fn get_perimeter(self) -> f32 { let wx = self.upper_bound.x - self.lower_bound.x; let wy = self.upper_bound.y - self.lower_bound.y; - return 2.0 * (wx + wy); + 2.0 * (wx + wy) } /// Combine an AABB into this one. @@ -247,11 +250,11 @@ impl B2AABB { result = result && self.lower_bound.y <= aabb.lower_bound.y; result = result && aabb.upper_bound.x <= self.upper_bound.x; result = result && aabb.upper_bound.y <= self.upper_bound.y; - return result; + result } pub fn ray_cast(self, output: &mut B2rayCastOutput, input: &B2rayCastInput) -> bool { - return private::b2_collision::b2_aabb_ray_cast(self, output, input); + private::b2_collision::b2_aabb_ray_cast(self, output, input) } } @@ -322,13 +325,13 @@ pub fn b2_clip_segment_to_line( offset: f32, vertex_index_a: usize, ) -> usize { - return private::b2_collision::b2_clip_segment_to_line( + private::b2_collision::b2_clip_segment_to_line( v_out, v_in, normal, offset, vertex_index_a, - ); + ) } /// Determine if two generic shapes overlap. @@ -340,7 +343,7 @@ pub fn b2_test_overlap_shapes( xf_a: B2Transform, xf_b: B2Transform, ) -> bool { - return private::b2_collision::b2_test_overlap(shape_a, index_a, shape_b, index_b, xf_a, xf_b); + private::b2_collision::b2_test_overlap(shape_a, index_a, shape_b, index_b, xf_a, xf_b) } // ---------------- Inline Functions ------------------------------------------ @@ -349,7 +352,7 @@ pub fn b2_aabb_is_valid(self_: B2AABB) -> bool { let d: B2vec2 = self_.upper_bound - self_.lower_bound; let mut valid: bool = d.x >= 0.0 && d.y >= 0.0; valid = valid && self_.lower_bound.is_valid() && self_.upper_bound.is_valid(); - return valid; + valid } pub fn b2_test_overlap(a: B2AABB, b: B2AABB) -> bool { @@ -364,5 +367,5 @@ pub fn b2_test_overlap(a: B2AABB, b: B2AABB) -> bool { return false; } - return true; + true } diff --git a/src/b2_common.rs b/src/b2_common.rs index dfb67ba..2b4e496 100644 --- a/src/b2_common.rs +++ b/src/b2_common.rs @@ -14,8 +14,8 @@ pub fn b2_assert(a: bool) { assert!(a); } -pub const B2_MAX_FLOAT: f32 = std::f32::MAX; -pub const B2_EPSILON: f32 = std::f32::EPSILON; +pub const B2_MAX_FLOAT: f32 = f32::MAX; +pub const B2_EPSILON: f32 = f32::EPSILON; pub const B2_PI: f32 = std::f32::consts::PI; // Collision diff --git a/src/b2_contact.rs b/src/b2_contact.rs index bbca868..798f127 100644 --- a/src/b2_contact.rs +++ b/src/b2_contact.rs @@ -27,22 +27,22 @@ pub static G_BLOCK_SOLVE: AtomicBool = AtomicBool::new(true); /// Friction mixing law. The idea is to allow either fixture to drive the friction to zero. /// For example, anything slides on ice. pub fn b2_mix_friction(friction1: f32, friction2: f32) -> f32 { - return b2_sqrt(friction1 * friction2); + b2_sqrt(friction1 * friction2) } /// Restitution mixing law. The idea is allow for anything to bounce off an inelastic surface. /// For example, a superball bounces on anything. pub fn b2_mix_restitution(restitution1: f32, restitution2: f32) -> f32 { - return if restitution1 > restitution2 { + if restitution1 > restitution2 { restitution1 } else { restitution2 - }; + } } /// Restitution mixing law. This picks the lowest value. pub fn b2_mix_restitution_threshold(threshold1: f32, threshold2: f32) -> f32 { - return if threshold1 < threshold2 {threshold1} else {threshold2}; + if threshold1 < threshold2 {threshold1} else {threshold2} } pub type ContactEdgePtr = Rc>>; @@ -51,14 +51,14 @@ pub type ContactEdgeWeakPtr = Weak>>; impl LinkedListNode> for B2contactEdge { fn get_next(&self) -> Option> { - return self.next.clone(); + self.next.clone() } fn set_next(&mut self, value: Option>) { self.next = value; } fn take_next(&mut self) -> Option> { - return self.next.take(); + self.next.take() } } @@ -66,7 +66,7 @@ impl DoubleLinkedListNode> for B2contactEdge { fn get_prev(&self) -> Option> { - return self.prev.clone(); + self.prev.clone() } fn set_prev(&mut self, value: Option>) { @@ -95,8 +95,8 @@ pub type ContactPtr = Rc>>; pub type ContactWeakPtr = Weak>>; pub trait B2contactDynTrait { - fn get_base<'a>(&'a self) -> &'a B2contact; - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact; + fn get_base(&self) -> &B2contact; + fn get_base_mut(&mut self) -> &mut B2contact; /// evaluate this contact with your own manifold and transforms. fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform); } @@ -105,14 +105,14 @@ impl LinkedListNode> for dyn B2contactD { fn get_next(&self) -> Option>>> { - return self.get_base().m_next.clone(); + self.get_base().m_next.clone() } fn set_next(&mut self, value: Option>>>) { self.get_base_mut().m_next = value; } fn take_next(&mut self) -> Option>>> { - return self.get_base_mut().m_next.take(); + self.get_base_mut().m_next.take() } } @@ -120,7 +120,7 @@ impl DoubleLinkedListNode> for dyn B2co { fn get_prev(&self) -> Option>>> { - return self.get_base().m_prev.clone(); + self.get_base().m_prev.clone() } fn set_prev(&mut self, value: Option>>>) { @@ -135,11 +135,11 @@ impl B2contact { /// Get the contact manifold. Do not modify the manifold unless you understand the /// internals of Box2D. pub fn get_manifold(&self) -> &B2manifold { - return inline::get_manifold(self); + inline::get_manifold(self) } pub fn get_manifold_mut(&mut self) -> &mut B2manifold { - return inline::get_manifold_mut(self); + inline::get_manifold_mut(self) } /// Get the world manifold. @@ -149,7 +149,7 @@ impl B2contact { /// Is this contact touching? pub fn is_touching(&self) -> bool { - return inline::is_touching(self); + inline::is_touching(self) } /// Enable/disable this contact. This can be used inside the pre-solve @@ -161,32 +161,32 @@ impl B2contact { /// Has this contact been disabled? pub fn is_enabled(&self) -> bool { - return inline::is_enabled(self); + inline::is_enabled(self) } /// Get the next contact in the world's contact list. pub fn get_next(&self) -> Option> { - return inline::get_next(self); + inline::get_next(self) } /// Get fixture A in this contact. pub fn get_fixture_a(&self) -> FixturePtr { - return inline::get_fixture_a(self); + inline::get_fixture_a(self) } /// Get the child primitive index for fixture A. pub fn get_child_index_a(&self) -> i32 { - return inline::get_child_index_a(self); + inline::get_child_index_a(self) } /// Get fixture b in this contact. pub fn get_fixture_b(&self) -> FixturePtr { - return inline::get_fixture_b(self); + inline::get_fixture_b(self) } /// Get the child primitive index for fixture b. pub fn get_child_index_b(&self) -> i32 { - return inline::get_child_index_b(self); + inline::get_child_index_b(self) } /// Override the default friction mixture. You can call this in B2contactListener::pre_solve. @@ -197,7 +197,7 @@ impl B2contact { /// Get the friction. pub fn get_friction(&self) -> f32 { - return inline::get_friction(self); + inline::get_friction(self) } /// reset the friction mixture to the default value. @@ -213,7 +213,7 @@ impl B2contact { /// Get the restitution. pub fn get_restitution(&self) -> f32 { - return inline::get_restitution(self); + inline::get_restitution(self) } /// reset the restitution to the default value. pub fn reset_restitution(&mut self) { @@ -228,7 +228,7 @@ impl B2contact { /// Get the restitution threshold. pub fn get_restitution_threshold(&self)->f32{ - return inline::get_restitution_threshold(self); + inline::get_restitution_threshold(self) } /// Reset the restitution threshold to the default value. @@ -243,7 +243,7 @@ impl B2contact { /// Get the desired tangent speed. In meters per second. pub fn get_tangent_speed(&self) -> f32 { - return inline::get_tangent_speed(self); + inline::get_tangent_speed(self) } //protected: @@ -260,14 +260,14 @@ impl B2contact { fixture_b: FixturePtr, index_b: i32, ) -> ContactPtr { - return private::b2_contact_create(contact_manager, fixture_a, index_a, fixture_b, index_b); + private::b2_contact_create(contact_manager, fixture_a, index_a, fixture_b, index_b) } pub(crate) fn destroy(self_: &dyn B2contactDynTrait) { private::b2_contact_destroy(self_); } pub(crate) fn new(f_a: FixturePtr, index_a: i32, f_b: FixturePtr, index_b: i32) -> Self { - return private::b2_contact_new(f_a, index_a, f_b, index_b); + private::b2_contact_new(f_a, index_a, f_b, index_b) } pub(crate) fn update( @@ -342,11 +342,11 @@ mod inline { use super::*; pub fn get_manifold(self_: &B2contact) -> &B2manifold { - return &self_.m_manifold; + &self_.m_manifold } pub fn get_manifold_mut(self_: &mut B2contact) -> &mut B2manifold { - return &mut self_.m_manifold; + &mut self_.m_manifold } pub fn get_world_manifold( @@ -372,31 +372,31 @@ mod inline { } pub fn is_enabled(self_: &B2contact) -> bool { - return self_.m_flags.contains(ContactFlags::E_ENABLED_FLAG); + self_.m_flags.contains(ContactFlags::E_ENABLED_FLAG) } pub fn is_touching(self_: &B2contact) -> bool { - return self_.m_flags.contains(ContactFlags::E_TOUCHING_FLAG); + self_.m_flags.contains(ContactFlags::E_TOUCHING_FLAG) } pub fn get_next(self_: &B2contact) -> Option> { - return self_.m_next.clone(); + self_.m_next.clone() } pub fn get_fixture_a(self_: &B2contact) -> FixturePtr { - return self_.m_fixture_a.clone(); + self_.m_fixture_a.clone() } pub fn get_child_index_a(self_: &B2contact) -> i32 { - return self_.m_index_a; + self_.m_index_a } pub fn get_fixture_b(self_: &B2contact) -> FixturePtr { - return self_.m_fixture_b.clone(); + self_.m_fixture_b.clone() } pub fn get_child_index_b(self_: &B2contact) -> i32 { - return self_.m_index_b; + self_.m_index_b } pub fn flag_for_filtering(self_: &mut B2contact) { @@ -408,7 +408,7 @@ mod inline { } pub fn get_friction(self_: &B2contact) -> f32 { - return self_.m_friction; + self_.m_friction } pub fn reset_friction(self_: &mut B2contact) { @@ -423,7 +423,7 @@ mod inline { } pub fn get_restitution(self_: &B2contact) -> f32 { - return self_.m_restitution; + self_.m_restitution } pub fn reset_restitution(self_: &mut B2contact) { @@ -438,7 +438,7 @@ mod inline { } pub fn get_restitution_threshold(self_: &B2contact) -> f32 { - return self_.m_restitution_threshold; + self_.m_restitution_threshold } pub fn reset_restitution_threshold(self_: &mut B2contact) { @@ -453,6 +453,6 @@ mod inline { } pub fn get_tangent_speed(self_: &B2contact) -> f32 { - return self_.m_tangent_speed; + self_.m_tangent_speed } } diff --git a/src/b2_contact_manager.rs b/src/b2_contact_manager.rs index f1eba77..14abba7 100644 --- a/src/b2_contact_manager.rs +++ b/src/b2_contact_manager.rs @@ -18,18 +18,24 @@ use std::rc::Rc; // } // } +impl Default for B2contactManager { + fn default() -> Self { + Self::new() + } +} + impl B2contactManager { //TODO_humman переместить в приват и использовать B2contactFilterDefault pub fn new() ->Self{ - return Self{ + Self{ m_registers: Default::default(), m_broad_phase: Rc::new(RefCell::new(B2broadPhase::new())), m_contact_list: Default::default(), m_contact_count: 0, m_contact_filter: Some(Rc::new(RefCell::new(B2contactFilterDefault{}))), m_contact_listener: Default::default(), - }; + } } pub fn find_new_contacts(&mut self) { @@ -45,7 +51,7 @@ impl B2contactManager { } pub fn get_broad_phase(&self)->B2broadPhasePtr>{ - return self.m_broad_phase.clone(); + self.m_broad_phase.clone() } } diff --git a/src/b2_distance.rs b/src/b2_distance.rs index e4413f8..0e5f036 100644 --- a/src/b2_distance.rs +++ b/src/b2_distance.rs @@ -35,22 +35,22 @@ impl B2distanceProxy { /// Get the supporting vertex index in the given direction. pub fn get_support(&self, d: B2vec2) -> usize { - return inline::get_support(self, d); + inline::get_support(self, d) } /// Get the supporting vertex in the given direction. pub fn get_support_vertex(&self, d: B2vec2) -> B2vec2 { - return inline::get_support_vertex(self, d); + inline::get_support_vertex(self, d) } /// Get the vertex count. pub fn get_vertex_count(&self) -> usize { - return inline::get_vertex_count(self); + inline::get_vertex_count(self) } /// Get a vertex by index. Used by b2Distance. pub fn get_vertex(&self, index: usize) -> B2vec2 { - return inline::get_vertex(self, index); + inline::get_vertex(self, index) } } @@ -125,19 +125,19 @@ pub struct B2shapeCastOutput { /// /// @returns true if hit, false if there is no hit or an initial overlap pub fn b2_shape_cast(output: &mut B2shapeCastOutput, input: B2shapeCastInput) -> bool { - return private::b2_shape_cast(output, input); + private::b2_shape_cast(output, input) } mod inline { use super::*; pub fn get_vertex_count(self_: &B2distanceProxy) -> usize { - return self_.m_vertices.len(); + self_.m_vertices.len() } pub fn get_vertex(self_: &B2distanceProxy, index: usize) -> B2vec2 { b2_assert(index < self_.m_vertices.len()); - return self_.m_vertices[index]; + self_.m_vertices[index] } pub fn get_support(self_: &B2distanceProxy, d: B2vec2) -> usize { @@ -151,7 +151,7 @@ mod inline { } } - return best_index; + best_index } pub fn get_support_vertex(self_: &B2distanceProxy, d: B2vec2) -> B2vec2 { @@ -165,6 +165,6 @@ mod inline { } } - return self_.m_vertices[best_index]; + self_.m_vertices[best_index] } } diff --git a/src/b2_draw.rs b/src/b2_draw.rs index 6854c39..1350f51 100644 --- a/src/b2_draw.rs +++ b/src/b2_draw.rs @@ -14,21 +14,21 @@ pub struct B2color { } impl B2color { pub fn new(r_in: f32, g_in: f32, b_in: f32) -> B2color { - return B2color { + B2color { r: r_in, g: g_in, b: b_in, a: 1.0, - }; + } } pub fn new_with_alpha(r_in: f32, g_in: f32, b_in: f32, a_in: f32) -> B2color { - return B2color { + B2color { r: r_in, g: g_in, b: b_in, a: a_in, - }; + } } pub fn set(&mut self, r_in: f32, g_in: f32, b_in: f32) { @@ -74,7 +74,7 @@ impl B2draw { /// Get the drawing flags. pub fn get_flags(self) -> B2drawShapeFlags { - return self.m_draw_flags; + self.m_draw_flags } /// Append flags to the current flags. diff --git a/src/b2_dynamic_tree.rs b/src/b2_dynamic_tree.rs index 63df2b6..a4bcc87 100644 --- a/src/b2_dynamic_tree.rs +++ b/src/b2_dynamic_tree.rs @@ -33,7 +33,7 @@ pub struct B2treeNode { impl B2treeNode { pub fn is_leaf(&self) -> bool { - return self.child1 == B2_NULL_NODE; + self.child1 == B2_NULL_NODE } } @@ -61,15 +61,15 @@ pub struct B2dynamicTree { impl B2dynamicTree { /// Constructing the tree initializes the node pool. pub fn new() -> Self { - return private::b2_dynamic_tree(); + private::b2_dynamic_tree() } - /// destroy the tree, freeing the node pool. + // /// destroy the tree, freeing the node pool. //~B2dynamicTree(); /// create a proxy. Provide a tight fitting AABB and a user_data pointer. pub fn create_proxy(&mut self, aabb: B2AABB, user_data: &UserDataType) -> i32 { - return private::create_proxy(self, aabb, user_data); + private::create_proxy(self, aabb, user_data) } /// destroy a proxy. This asserts if the id is invalid. @@ -80,21 +80,21 @@ impl B2dynamicTree { /// Move a proxy with a swepted AABB. If the proxy has moved outside of its fattened AABB, /// then the proxy is removed from the tree and re-inserted. Otherwise /// the function returns immediately. - /// + /// /// @return true if the proxy was re-inserted. pub fn move_proxy(&mut self, proxy_id: i32, aabb1: B2AABB, displacement: B2vec2) -> bool { - return private::move_proxy(self, proxy_id, aabb1, displacement); + private::move_proxy(self, proxy_id, aabb1, displacement) } /// Get proxy user data. - /// + /// /// @return the proxy user data or 0 if the id is invalid. pub fn get_user_data(&self, proxy_id: i32) -> Option { - return inline::get_user_data(self, proxy_id); + inline::get_user_data(self, proxy_id) } pub fn was_moved(&self, proxy_id: i32) -> bool { - return inline::was_moved(self, proxy_id); + inline::was_moved(self, proxy_id) } pub fn clear_moved(&mut self, proxy_id: i32) { inline::clear_moved(self, proxy_id); @@ -102,7 +102,7 @@ impl B2dynamicTree { /// Get the fat AABB for a proxy. pub fn get_fat_aabb(&self, proxy_id: i32) -> B2AABB { - return inline::get_fat_aabb(self, proxy_id); + inline::get_fat_aabb(self, proxy_id) } /// query an AABB for overlapping proxies. The callback class @@ -130,18 +130,18 @@ impl B2dynamicTree { /// Compute the height of the binary tree in O(n) time. Should not be /// called often. pub fn get_height(&self) -> i32 { - return private::get_height(self); + private::get_height(self) } /// Get the maximum balance of an node in the tree. The balance is the difference /// in height of the two children of a node. pub fn get_max_balance(&self) -> i32 { - return private::get_max_balance(self); + private::get_max_balance(self) } /// Get the ratio of the sum of the node areas to the root area. pub fn get_area_ration(&self) -> f32 { - return private::get_area_ratio(self); + private::get_area_ratio(self) } /// Build an optimal tree. Very expensive. For testing. @@ -157,7 +157,7 @@ impl B2dynamicTree { } pub(crate) fn allocate_node(&mut self) -> i32 { - return private::allocate_node(self); + private::allocate_node(self) } pub(crate) fn free_node(&mut self, node: i32) { private::free_node(self, node); @@ -171,14 +171,14 @@ impl B2dynamicTree { } pub(crate) fn balance(&mut self, index: i32) -> i32 { - return private::balance(self, index); + private::balance(self, index) } pub(crate) fn compute_height(&self) -> i32 { - return private::compute_height(self); + private::compute_height(self) } pub(crate) fn compute_height_by_node(&self, node_id: i32) -> i32 { - return private::compute_height_by_node(self, node_id); + private::compute_height_by_node(self, node_id) } pub(crate) fn validate_structure(&self, index: i32) { @@ -209,7 +209,7 @@ mod inline { proxy_id: i32, ) -> Option { //b2_assert(0 <= proxy_id && proxy_id < self_.m_nodeCapacity); - return self_.m_nodes[proxy_id as usize].user_data.clone(); + self_.m_nodes[proxy_id as usize].user_data.clone() } pub fn was_moved( @@ -217,7 +217,7 @@ mod inline { proxy_id: i32, ) -> bool { //b2_assert(0 <= proxy_id && proxy_id < self_.m_nodeCapacity); - return self_.m_nodes[proxy_id as usize].moved; + self_.m_nodes[proxy_id as usize].moved } pub fn clear_moved( @@ -233,7 +233,7 @@ mod inline { proxy_id: i32, ) -> B2AABB { //b2_assert(0 <= proxy_id && proxy_id < self_.m_nodeCapacity); - return self_.m_nodes[proxy_id as usize].aabb; + self_.m_nodes[proxy_id as usize].aabb } pub fn query( @@ -255,7 +255,7 @@ mod inline { if b2_test_overlap(node.aabb, aabb) { if node.is_leaf() { let proceed: bool = callback(node_id); - if proceed == false { + if !proceed { return; } } else { @@ -305,7 +305,7 @@ mod inline { let node = &self_.m_nodes[node_id as usize]; - if b2_test_overlap(node.aabb, segment_aabb) == false { + if !b2_test_overlap(node.aabb, segment_aabb) { continue; } @@ -322,7 +322,7 @@ mod inline { let sub_input = B2rayCastInput { p1: input.p1, p2: input.p2, - max_fraction: max_fraction, + max_fraction, }; let value: f32 = callback(&sub_input, node_id); diff --git a/src/b2_fixture.rs b/src/b2_fixture.rs index 8ba9788..4dcd34d 100644 --- a/src/b2_fixture.rs +++ b/src/b2_fixture.rs @@ -16,11 +16,11 @@ use serde::{Serialize, Deserialize}; impl Default for B2filter { fn default() -> Self { - return B2filter { + B2filter { category_bits: 0x0001, mask_bits: 0xFFFF, group_index: 0, - }; + } } } @@ -44,7 +44,7 @@ pub struct B2filter { impl Default for B2fixtureDef { /// The constructor sets the default fixture definition values. fn default() -> Self { - return B2fixtureDef { + B2fixtureDef { shape: None, user_data: None, friction: 0.2, @@ -53,7 +53,7 @@ impl Default for B2fixtureDef { density: 0.0, is_sensor: false, filter: B2filter::default(), - }; + } } } @@ -105,14 +105,14 @@ pub struct B2fixtureProxy { impl LinkedListNode> for B2fixture { fn get_next(&self) -> Option> { - return self.m_next.clone(); + self.m_next.clone() } fn set_next(&mut self, value: Option>) { self.m_next = value; } fn take_next(&mut self) -> Option> { - return self.m_next.take(); + self.m_next.take() } } @@ -151,14 +151,14 @@ impl B2fixture { /// /// @return the shape type. pub fn get_type(&self) -> B2ShapeType { - return inline::get_type(self); + inline::get_type(self) } /// Get the child shape. You can modify the child shape, however you should not change the /// number of vertices because this will crash some collision caching mechanisms. /// Manipulating the shape may lead to non-physical behavior. pub fn get_shape(&self) -> ShapePtr { - return inline::get_shape(self); + inline::get_shape(self) } /// Set if this fixture is a sensor. @@ -170,7 +170,7 @@ impl B2fixture { /// /// @return the true if the shape is a sensor. pub fn is_sensor(&self) -> bool { - return inline::is_sensor(self); + inline::is_sensor(self) } /// Set the contact filtering data. This will not update contacts until the next time @@ -182,7 +182,7 @@ impl B2fixture { /// Get the contact filtering data. pub fn get_filter_data(&self) -> B2filter { - return inline::get_filter_data(self); + inline::get_filter_data(self) } /// Call this if you want to establish collision that was previously disabled by B2contactFilter::should_collide. @@ -194,20 +194,20 @@ impl B2fixture { /// /// @return the parent body. pub fn get_body(&self) -> BodyPtr { - return inline::get_body(self); + inline::get_body(self) } /// Get the next fixture in the parent body's fixture list. /// /// @return the next shape. pub fn get_next(&self) -> Option> { - return inline::get_next(self); + inline::get_next(self) } /// Get the user data that was assigned in the fixture definition. Use this to /// store your application specific data. pub fn get_user_data(&self) -> Option { - return inline::get_user_data(self); + inline::get_user_data(self) } /// Set the user data. Use this to store your application specific data. @@ -218,7 +218,7 @@ impl B2fixture { /// Test a point for containment in this fixture. /// * `p` - a point in world coordinates. pub fn test_point(&self, p: B2vec2) -> bool { - return inline::test_point(self, p); + inline::test_point(self, p) } /// Cast a ray against this shape. @@ -231,7 +231,7 @@ impl B2fixture { input: &B2rayCastInput, child_index: i32, ) -> bool { - return inline::ray_cast(self, output, input, child_index); + inline::ray_cast(self, output, input, child_index) } /// Get the mass data for this fixture. The mass data is based on the density and @@ -249,23 +249,23 @@ impl B2fixture { /// Get the density of this fixture. pub fn get_density(&self) -> f32 { - return inline::get_density(self); + inline::get_density(self) } /// Get the coefficient of friction. pub fn get_friction(&self) -> f32 { - return inline::get_friction(self); + inline::get_friction(self) } /// Set the coefficient of friction. This will _not_ change the friction of /// existing contacts. pub fn set_friction(&mut self, friction: f32) { - return inline::set_friction(self, friction); + inline::set_friction(self, friction) } /// Get the coefficient of restitution. pub fn get_restitution(&self) -> f32 { - return inline::get_restitution(self); + inline::get_restitution(self) } /// Set the coefficient of restitution. This will _not_ change the restitution of @@ -276,7 +276,7 @@ impl B2fixture { /// Get the restitution velocity threshold. pub fn get_restitution_threshold(&self)-> f32{ - return inline::get_restitution_threshold(self); + inline::get_restitution_threshold(self) } /// Set the restitution threshold. This will _not_ change the restitution threshold of @@ -290,11 +290,11 @@ impl B2fixture { /// If you need a more accurate AABB, compute it using the shape and /// the body transform. pub fn get_aabb(&self, child_index: i32) -> B2AABB { - return inline::get_aabb(self, child_index); + inline::get_aabb(self, child_index) } pub(crate) fn default() -> Self { - return private::b2_fixture_default(); + private::b2_fixture_default() } // We need separation create/destroy functions from the constructor/destructor because @@ -336,23 +336,23 @@ mod inline { use super::*; pub fn get_type(self_: &B2fixture) -> B2ShapeType { - return self_.m_shape.as_ref().unwrap().get_type(); + self_.m_shape.as_ref().unwrap().get_type() } pub fn get_shape(self_: &B2fixture) -> ShapePtr { - return self_.m_shape.as_ref().unwrap().clone(); + self_.m_shape.as_ref().unwrap().clone() } pub fn is_sensor(self_: &B2fixture) -> bool { - return self_.m_is_sensor; + self_.m_is_sensor } pub fn get_filter_data(self_: &B2fixture) -> B2filter { - return self_.m_filter; + self_.m_filter } pub fn get_user_data(self_: &B2fixture) -> Option { - return self_.m_user_data.clone(); + self_.m_user_data.clone() } pub fn set_user_data(self_: &mut B2fixture, data: &D::Fixture) { @@ -360,11 +360,11 @@ mod inline { } pub fn get_body(self_: &B2fixture) -> BodyPtr { - return self_.m_body.as_ref().unwrap().upgrade().unwrap(); + self_.m_body.as_ref().unwrap().upgrade().unwrap() } pub fn get_next(self_: &B2fixture) -> Option> { - return self_.m_next.clone(); + self_.m_next.clone() } pub fn set_density(self_: &mut B2fixture, density: f32) { @@ -373,11 +373,11 @@ mod inline { } pub fn get_density(self_: &B2fixture) -> f32 { - return self_.m_density; + self_.m_density } pub fn get_friction(self_: &B2fixture) -> f32 { - return self_.m_friction; + self_.m_friction } pub fn set_friction(self_: &mut B2fixture, friction: f32) { @@ -385,7 +385,7 @@ mod inline { } pub fn get_restitution(self_: &B2fixture) -> f32 { - return self_.m_restitution; + self_.m_restitution } pub fn set_restitution(self_: &mut B2fixture, restitution: f32) { @@ -394,7 +394,7 @@ mod inline { pub fn get_restitution_threshold(self_: &B2fixture) ->f32 { - return self_.m_restitution_threshold; + self_.m_restitution_threshold } pub fn set_restitution_threshold(self_: &mut B2fixture, threshold:f32) diff --git a/src/b2_growable_stack.rs b/src/b2_growable_stack.rs index bb6c5a8..c7f689e 100644 --- a/src/b2_growable_stack.rs +++ b/src/b2_growable_stack.rs @@ -26,14 +26,20 @@ enum B2rsStackOrVec DynVec(Vec) } +impl Default for B2growableStack { + fn default() -> Self { + Self::new() + } +} + impl B2growableStack { pub fn new() -> Self { - return B2growableStack { + B2growableStack { value: B2rsStackOrVec::Stack(B2rsStaticArrayWithSize { m_array: [T::default(); N], m_count: 0, }) - }; + } } pub fn push(&mut self, element: &T) { @@ -62,11 +68,11 @@ impl B2growableStack { B2rsStackOrVec::Stack(ref mut stack)=>{ b2_assert(stack.m_count > 0); stack.m_count-=1; - return stack.m_array[stack.m_count]; + stack.m_array[stack.m_count] }, B2rsStackOrVec::DynVec(ref mut vec)=>{ - b2_assert(vec.len() > 0); - return vec.pop().unwrap(); + b2_assert(!vec.is_empty()); + vec.pop().unwrap() } } } @@ -75,10 +81,10 @@ impl B2growableStack { match self.value { B2rsStackOrVec::Stack(ref stack)=>{ - return stack.m_count; + stack.m_count }, B2rsStackOrVec::DynVec(ref vec)=>{ - return vec.len(); + vec.len() } } } diff --git a/src/b2_joint.rs b/src/b2_joint.rs index a4c8838..9c99cbb 100644 --- a/src/b2_joint.rs +++ b/src/b2_joint.rs @@ -54,12 +54,12 @@ pub enum B2jointType { EPulleyJoint, ERevoluteJoint, EWeldJoint, - EWheelJoint, + EWheelJoint, } impl Default for B2jointType { fn default() -> Self { - return B2jointType::EUnknownJoint; + B2jointType::EUnknownJoint } } @@ -76,19 +76,19 @@ pub type B2jointEdgeWeakPtr = Weak>>; impl LinkedListNode> for B2jointEdge { fn get_next(&self) -> Option> { - return self.next.clone(); + self.next.clone() } fn set_next(&mut self, value: Option>) { self.next = value; } fn take_next(&mut self) -> Option> { - return self.next.take(); + self.next.take() } } impl DoubleLinkedListNode> for B2jointEdge { fn get_prev(&self) -> Option> { - return self.prev.clone(); + self.prev.clone() } fn set_prev(&mut self, value: Option>) { self.prev = value; @@ -113,31 +113,31 @@ pub struct B2jointEdge { impl Default for B2jointDef { fn default() -> Self { - return Self { + Self { jtype: B2jointType::EUnknownJoint, user_data: None, body_a: None, body_b: None, collide_connected: false, - }; + } } } impl LinkedListNode> for dyn B2jointTraitDyn { fn get_next(&self) -> Option> { - return self.get_base().m_next.clone(); + self.get_base().m_next.clone() } fn set_next(&mut self, value: Option>) { self.get_base_mut().m_next = value; } fn take_next(&mut self) -> Option> { - return self.get_base_mut().m_next.take(); + self.get_base_mut().m_next.take() } } impl DoubleLinkedListNode> for dyn B2jointTraitDyn { fn get_prev(&self) -> Option> { - return self.get_base().m_prev.clone(); + self.get_base().m_prev.clone() } fn set_prev(&mut self, value: Option>) { self.get_base_mut().m_prev = value.clone(); @@ -189,27 +189,27 @@ pub fn b2_angular_stiffness(stiffness: &mut f32, damping: &mut impl B2joint { /// Get the type of the concrete joint. pub fn get_type(&self) -> B2jointType { - return self.m_type; + self.m_type } /// Get the first body attached to this joint. pub fn get_body_a(&self) -> BodyPtr { - return self.m_body_a.clone(); + self.m_body_a.clone() } /// Get the second body attached to this joint. pub fn get_body_b(&self) -> BodyPtr { - return self.m_body_b.clone(); + self.m_body_b.clone() } /// Get the next joint the world joint list. pub fn get_next(&self) -> B2jointPtr { - return self.m_next.as_ref().unwrap().clone(); + self.m_next.as_ref().unwrap().clone() } /// Get the user data pointer. pub fn get_user_data(&self) -> Option { - return self.m_user_data.clone(); + self.m_user_data.clone() } /// Set the user data pointer. @@ -219,24 +219,24 @@ impl B2joint { /// Short-cut function to determine if either body is enabled. pub fn is_enabled(&self) -> bool { - return private::is_enabled(self); + private::is_enabled(self) } /// Get collide connected. /// Note: modifying the collide connect flag won't work correctly because /// the flag is only checked when fixture AABBs begin to overlap. pub fn get_collide_connected(&self) -> bool { - return self.m_collide_connected; + self.m_collide_connected } // protected: // static B2joint* create(const B2jointDef* def, b2BlockAllocator* allocator); pub(crate) fn create(def: &B2JointDefEnum) -> B2jointPtr { - return private::create(def); + private::create(def) } pub(crate) fn new(def: &B2jointDef) -> B2joint { - return private::new(def); + private::new(def) } } @@ -263,7 +263,7 @@ pub trait B2jointTraitDyn: ToDerivedJoint { /// Debug draw this joint fn draw(&self, draw: &mut dyn B2drawTrait) { private::draw(self, draw); - } + } fn init_velocity_constraints( &mut self, @@ -286,8 +286,8 @@ pub trait B2jointTraitDyn: ToDerivedJoint { } pub trait ToDerivedJoint { - fn as_derived(&self) -> JointAsDerived; - fn as_derived_mut(&mut self) -> JointAsDerivedMut; + fn as_derived(&self) -> JointAsDerived<'_, D>; + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D>; } pub enum JointAsDerived<'a, D: UserDataType> { @@ -327,7 +327,7 @@ pub struct B2joint { pub(crate) m_body_a: BodyPtr, pub(crate) m_body_b: BodyPtr, - pub(crate) m_index: i32, + //pub(crate) m_index: i32, pub(crate) m_island_flag: bool, pub(crate) m_collide_connected: bool, diff --git a/src/b2_math.rs b/src/b2_math.rs index 92454c3..8e6f10e 100644 --- a/src/b2_math.rs +++ b/src/b2_math.rs @@ -1,20 +1,19 @@ use crate::b2_common::{b2_assert, B2_PI}; use crate::private::common::b2_math as private; -use std::f32::EPSILON; use std::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; #[cfg(feature="serde_support")] use serde::{Serialize, Deserialize}; pub fn b2_is_valid(x: f32) -> bool { - return x.is_finite(); + x.is_finite() } pub fn b2_sqrt(x: f32) -> f32 { - return f32::sqrt(x); + f32::sqrt(x) } pub fn b2_atan2(y: f32, x: f32) -> f32 { - return f32::atan2(y, x); + f32::atan2(y, x) } /// A 2D column vector. @@ -28,11 +27,11 @@ pub struct B2vec2 { impl B2vec2 { /// Construct using coordinates. pub fn new(x_in: f32, y_in: f32) -> B2vec2 { - return B2vec2 { x: x_in, y: y_in }; + B2vec2 { x: x_in, y: y_in } } pub fn zero() -> B2vec2{ - return B2vec2::new(0.0, 0.0); + B2vec2::new(0.0, 0.0) } /// Set this vector to all zeros. @@ -48,7 +47,7 @@ impl B2vec2 { } pub fn get(self, i: i32) -> f32 { - assert!(i >= 0 && i < 2); + assert!((0..2).contains(&i)); if i == 0 { self.x @@ -58,7 +57,7 @@ impl B2vec2 { } pub fn set_by_index(&mut self, i: i32, value: f32) { - assert!(i >= 0 && i < 2); + assert!((0..2).contains(&i)); if i == 0 { self.x = value; @@ -69,36 +68,36 @@ impl B2vec2 { /// Get the length of this vector (the norm). pub fn length(self) -> f32 { - return b2_sqrt(self.x * self.x + self.y * self.y); + b2_sqrt(self.x * self.x + self.y * self.y) } /// Get the length squared. For performance, use this instead of /// B2vec2::length (if possible). pub fn length_squared(self) -> f32 { - return self.x * self.x + self.y * self.y; + self.x * self.x + self.y * self.y } /// Convert this vector into a unit vector. Returns the length. pub fn normalize(&mut self) -> f32 { let length = self.length(); - if length < EPSILON { + if length < f32::EPSILON { return 0.0; } let inv_length: f32 = 1.0 / length; self.x *= inv_length; self.y *= inv_length; - return length; + length } /// Does this vector contain finite coordinates? pub fn is_valid(self) -> bool { - return b2_is_valid(self.x) && b2_is_valid(self.y); + b2_is_valid(self.x) && b2_is_valid(self.y) } /// Get the skew vector such that dot(skew_vec, other) == cross(vec, other) pub fn skew(self) -> B2vec2 { - return B2vec2::new(-self.y, self.x); + B2vec2::new(-self.y, self.x) } } @@ -106,10 +105,10 @@ impl Neg for B2vec2 { type Output = B2vec2; /// Negate this vector. fn neg(self) -> B2vec2 { - return B2vec2 { + B2vec2 { x: -self.x, y: -self.y, - }; + } } } @@ -149,11 +148,11 @@ pub struct B2Vec3 { impl B2Vec3 { /// Construct using coordinates. pub fn new(x_in: f32, y_in: f32, z_in: f32) -> B2Vec3 { - return B2Vec3 { + B2Vec3 { x: x_in, y: y_in, z: z_in, - }; + } } /// Set this vector to all zeros. @@ -164,7 +163,7 @@ impl B2Vec3 { } pub fn zero() -> Self{ - return Self::new(0.0, 0.0, 0.0); + Self::new(0.0, 0.0, 0.0) } /// Set this vector to some specified coordinates. @@ -179,7 +178,7 @@ impl Neg for B2Vec3 { type Output = B2Vec3; /// Negate this vector. fn neg(self) -> B2Vec3 { - return B2Vec3::new(-self.x, -self.y, -self.z); + B2Vec3::new(-self.x, -self.y, -self.z) } } @@ -221,15 +220,15 @@ pub struct B2Mat22 { impl B2Mat22 { /// Construct this matrix using columns. pub fn new(c1: B2vec2, c2: B2vec2) -> B2Mat22 { - return B2Mat22 { ex: c1, ey: c2 }; + B2Mat22 { ex: c1, ey: c2 } } /// Construct this matrix using scalars. pub fn new_scalars(a11: f32, a12: f32, a21: f32, a22: f32) -> B2Mat22 { - return B2Mat22 { + B2Mat22 { ex: B2vec2::new(a11, a21), ey: B2vec2::new(a12, a22), - }; + } } /// initialize this matrix using columns. @@ -255,7 +254,7 @@ impl B2Mat22 { } pub fn zero()->Self{ - return Self::new(B2vec2::zero(), B2vec2::zero()); + Self::new(B2vec2::zero(), B2vec2::zero()) } pub fn get_inverse(&mut self) -> B2Mat22 { @@ -267,10 +266,10 @@ impl B2Mat22 { if det != 0.0 { det = 1.0 / det; } - return B2Mat22 { + B2Mat22 { ex: B2vec2::new(det * d, -det * c), ey: B2vec2::new(-det * b, det * a), - }; + } } /// solve A * x = b, where b is a column vector. This is more efficient @@ -284,12 +283,12 @@ impl B2Mat22 { if det != 0.0 { det = 1.0 / det; } - let x: B2vec2; - x = B2vec2 { + + let x: B2vec2 = B2vec2 { x: det * (a22 * b.x - a12 * b.y), y: det * (a11 * b.y - a21 * b.x), }; - return x; + x } } @@ -305,11 +304,11 @@ pub struct B2Mat33 { impl B2Mat33 { /// Construct this matrix using columns. pub fn new(c1: B2Vec3, c2: B2Vec3, c3: B2Vec3) -> B2Mat33 { - return B2Mat33 { + B2Mat33 { ex: c1, ey: c2, ez: c3, - }; + } } /// Set this matrix to all zeros. @@ -320,32 +319,32 @@ impl B2Mat33 { } pub fn zero()->Self{ - return Self::new(B2Vec3::zero(), B2Vec3::zero(),B2Vec3::zero()); + Self::new(B2Vec3::zero(), B2Vec3::zero(),B2Vec3::zero()) } /// solve A * x = b, where b is a column vector. This is more efficient /// than computing the inverse in one-shot cases. pub fn solve33(self, b: B2Vec3) -> B2Vec3 { - return private::solve33(self, b); + private::solve33(self, b) } /// solve A * x = b, where b is a column vector. This is more efficient /// than computing the inverse in one-shot cases. solve only the upper /// 2-by-2 matrix equation. pub fn solve22(self, b: B2vec2) -> B2vec2 { - return private::solve22(self, b); + private::solve22(self, b) } /// Get the inverse of this matrix as a 2-by-2. /// Returns the zero matrix if singular. pub fn get_inverse22(self, m: &mut B2Mat33) { - return private::get_inverse22(self, m); + private::get_inverse22(self, m) } /// Get the symmetric inverse of this matrix as a 3-by-3. /// Returns the zero matrix if singular. pub fn get_sym_inverse33(self, m: &mut B2Mat33) { - return private::get_sym_inverse33(self, m); + private::get_sym_inverse33(self, m) } } @@ -362,10 +361,10 @@ impl B2Rot { /// initialize from an angle in radians pub fn new(angle: f32) -> B2Rot { // TODO_ERIN optimize - return B2Rot { + B2Rot { s: f32::sin(angle), c: f32::cos(angle), - }; + } } /// Set using an angle in radians. @@ -383,17 +382,17 @@ impl B2Rot { /// Get the angle in radians pub fn get_angle(self) -> f32 { - return f32::atan2(self.s, self.c); + f32::atan2(self.s, self.c) } /// Get the x-axis pub fn get_xaxis(self) -> B2vec2 { - return B2vec2::new(self.c, self.s); + B2vec2::new(self.c, self.s) } /// Get the u-axis pub fn get_yaxis(self) -> B2vec2 { - return B2vec2::new(-self.s, self.c); + B2vec2::new(-self.s, self.c) } } @@ -409,10 +408,10 @@ pub struct B2Transform { impl B2Transform { /// initialize using a position vector and a rotation. pub fn new(position: B2vec2, rotation: B2Rot) -> B2Transform { - return B2Transform { + B2Transform { p: position, q: rotation, - }; + } } /// Set this to the identity transform. @@ -468,83 +467,83 @@ impl B2Sweep { /// Perform the dot product on two vectors. pub fn b2_dot(a: B2vec2, b: B2vec2) -> f32 { - return a.x * b.x + a.y * b.y; + a.x * b.x + a.y * b.y } /// Perform the cross product on two vectors. In 2D this produces a scalar. pub fn b2_cross(a: B2vec2, b: B2vec2) -> f32 { - return a.x * b.y - a.y * b.x; + a.x * b.y - a.y * b.x } /// Perform the cross product on a vector and a scalar. In 2D this produces /// a vector. pub fn b2_cross_vec_by_scalar(a: B2vec2, s: f32) -> B2vec2 { - return B2vec2::new(s * a.y, -s * a.x); + B2vec2::new(s * a.y, -s * a.x) } /// Perform the cross product on a scalar and a vector. In 2D this produces /// a vector. pub fn b2_cross_scalar_by_vec(s: f32, a: B2vec2) -> B2vec2 { - return B2vec2::new(-s * a.y, s * a.x); + B2vec2::new(-s * a.y, s * a.x) } /// Multiply a matrix times a vector. If a rotation matrix is provided, /// then this transforms the vector from one frame to another. pub fn b2_mul(a: B2Mat22, v: B2vec2) -> B2vec2 { - return B2vec2::new(a.ex.x * v.x + a.ey.x * v.y, a.ex.y * v.x + a.ey.y * v.y); + B2vec2::new(a.ex.x * v.x + a.ey.x * v.y, a.ex.y * v.x + a.ey.y * v.y) } /// Multiply a matrix transpose times a vector. If a rotation matrix is provided, /// then this transforms the vector from one frame to another (inverse transform). pub fn b2_mul_t(a: B2Mat22, v: B2vec2) -> B2vec2 { - return B2vec2::new(b2_dot(v, a.ex), b2_dot(v, a.ey)); + B2vec2::new(b2_dot(v, a.ex), b2_dot(v, a.ey)) } impl Add for B2vec2 { type Output = B2vec2; /// Add two vectors component-wise. fn add(self, b: B2vec2) -> B2vec2 { - return B2vec2::new(self.x + b.x, self.y + b.y); + B2vec2::new(self.x + b.x, self.y + b.y) } } impl Sub for B2vec2 { type Output = B2vec2; /// Subtract two vectors component-wise. fn sub(self, b: B2vec2) -> B2vec2 { - return B2vec2::new(self.x - b.x, self.y - b.y); + B2vec2::new(self.x - b.x, self.y - b.y) } } impl Mul for f32 { type Output = B2vec2; fn mul(self, a: B2vec2) -> B2vec2 { - return B2vec2::new(self * a.x, self * a.y); + B2vec2::new(self * a.x, self * a.y) } } pub fn is_equal(a: B2vec2, b: B2vec2) -> bool { - return a.x == b.x && a.y == b.y; + a.x == b.x && a.y == b.y } pub fn not_equal(a: B2vec2, b: B2vec2) -> bool { - return a.x != b.x || a.y != b.y; + a.x != b.x || a.y != b.y } pub fn b2_distance_vec2(a: B2vec2, b: B2vec2) -> f32 { let c: B2vec2 = a - b; - return c.length(); + c.length() } pub fn b2_distance_vec2_squared(a: B2vec2, b: B2vec2) -> f32 { let c: B2vec2 = a - b; - return b2_dot(c, c); + b2_dot(c, c) } impl Mul for f32 { type Output = B2Vec3; fn mul(self, a: B2Vec3) -> B2Vec3 { - return B2Vec3::new(self * a.x, self * a.y, self * a.z); + B2Vec3::new(self * a.x, self * a.y, self * a.z) } } @@ -552,7 +551,7 @@ impl Add for B2Vec3 { type Output = B2Vec3; /// Add two vectors component-wise. fn add(self, b: B2Vec3) -> B2Vec3 { - return B2Vec3::new(self.x + b.x, self.y + b.y, self.z + b.z); + B2Vec3::new(self.x + b.x, self.y + b.y, self.z + b.z) } } @@ -561,50 +560,50 @@ impl Sub for B2Vec3 { type Output = B2Vec3; /// Add two vectors component-wise. fn sub(self, b: B2Vec3) -> B2Vec3 { - return B2Vec3::new(self.x - b.x, self.y - b.y, self.z - b.z); + B2Vec3::new(self.x - b.x, self.y - b.y, self.z - b.z) } } /// Perform the dot product on two vectors. pub fn b2_dot_vec3(a: B2Vec3, b: B2Vec3) -> f32 { - return a.x * b.x + a.y * b.y + a.z * b.z; + a.x * b.x + a.y * b.y + a.z * b.z } /// Perform the cross product on two vectors. pub fn b2_cross_vec3(a: B2Vec3, b: B2Vec3) -> B2Vec3 { - return B2Vec3::new( + B2Vec3::new( a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x, - ); + ) } impl Add for B2Mat22 { type Output = B2Mat22; fn add(self, b: B2Mat22) -> B2Mat22 { - return B2Mat22::new(self.ex + b.ex, self.ey + b.ey); + B2Mat22::new(self.ex + b.ex, self.ey + b.ey) } } // A * b pub fn b2_mul_mat22(a: B2Mat22, b: B2Mat22) -> B2Mat22 { - return B2Mat22::new(b2_mul(a, b.ex), b2_mul(a, b.ey)); + B2Mat22::new(b2_mul(a, b.ex), b2_mul(a, b.ey)) } // A^T * b pub fn b2_mul_t_mat22(a: B2Mat22, b: B2Mat22) -> B2Mat22 { let c1 = B2vec2::new(b2_dot(a.ex, b.ex), b2_dot(a.ey, b.ex)); let c2 = B2vec2::new(b2_dot(a.ex, b.ey), b2_dot(a.ey, b.ey)); - return B2Mat22::new(c1, c2); + B2Mat22::new(c1, c2) } /// Multiply a matrix times a vector. pub fn b2_mul_mat33(a: B2Mat33, v: B2Vec3) -> B2Vec3 { - return v.x * a.ex + v.y * a.ey + v.z * a.ez; + v.x * a.ex + v.y * a.ey + v.z * a.ez } /// Multiply a matrix times a vector. pub fn b2_mul22(a: B2Mat33, v: B2vec2) -> B2vec2 { - return B2vec2::new(a.ex.x * v.x + a.ey.x * v.y, a.ex.y * v.x + a.ey.y * v.y); + B2vec2::new(a.ex.x * v.x + a.ey.x * v.y, a.ex.y * v.x + a.ey.y * v.y) } /// Multiply two rotations: q * r @@ -613,11 +612,11 @@ pub fn b2_mul_rot(q: B2Rot, r: B2Rot) -> B2Rot { // [qs qc] [rs rc] [qs*rc+qc*rs -qs*rs+qc*rc] // s = qs * rc + qc * rs // c = qc * rc - qs * rs - let qr = B2Rot { + + B2Rot { s: q.s * r.c + q.c * r.s, c: q.c * r.c - q.s * r.s, - }; - return qr; + } } /// Transpose multiply two rotations: qT * r @@ -626,28 +625,28 @@ pub fn b2_mul_t_rot(q: B2Rot, r: B2Rot) -> B2Rot { // [-qs qc] [rs rc] [-qs*rc+qc*rs qs*rs+qc*rc] // s = qc * rs - qs * rc // c = qc * rc + qs * rs - let qr = B2Rot { + + B2Rot { s: q.c * r.s - q.s * r.c, c: q.c * r.c + q.s * r.s, - }; - return qr; + } } /// Rotate a vector pub fn b2_mul_rot_by_vec2(q: B2Rot, v: B2vec2) -> B2vec2 { - return B2vec2::new(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y); + B2vec2::new(q.c * v.x - q.s * v.y, q.s * v.x + q.c * v.y) } /// Inverse rotate a vector pub fn b2_mul_t_rot_by_vec2(q: B2Rot, v: B2vec2) -> B2vec2 { - return B2vec2::new(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y); + B2vec2::new(q.c * v.x + q.s * v.y, -q.s * v.x + q.c * v.y) } pub fn b2_mul_transform_by_vec2(t: B2Transform, v: B2vec2) -> B2vec2 { let x: f32 = (t.q.c * v.x - t.q.s * v.y) + t.p.x; let y: f32 = (t.q.s * v.x + t.q.c * v.y) + t.p.y; - return B2vec2::new(x, y); + B2vec2::new(x, y) } pub fn b2_mul_t_transform_by_vec2(t: B2Transform, v: B2vec2) -> B2vec2 { @@ -656,27 +655,25 @@ pub fn b2_mul_t_transform_by_vec2(t: B2Transform, v: B2vec2) -> B2vec2 { let x: f32 = t.q.c * px + t.q.s * py; let y: f32 = -t.q.s * px + t.q.c * py; - return B2vec2::new(x, y); + B2vec2::new(x, y) } // v2 = A.q.Rot(b.q.Rot(v1) + b.p) + A.p // = (A.q * b.q).Rot(v1) + A.q.Rot(b.p) + A.p pub fn b2_mul_transform(a: B2Transform, b: B2Transform) -> B2Transform { - let c = B2Transform { - q: b2_mul_rot(a.q.clone(), b.q.clone()), + B2Transform { + q: b2_mul_rot(a.q, b.q), p: b2_mul_rot_by_vec2(a.q, b.p) + a.p, - }; - return c; + } } // v2 = A.q' * (b.q * v1 + b.p - A.p) // = A.q' * b.q * v1 + A.q' * (b.p - A.p) pub fn b2_mul_t_transform(a: B2Transform, b: B2Transform) -> B2Transform { - let c = B2Transform { + B2Transform { q: b2_mul_t_rot(a.q, b.q), p: b2_mul_t_rot_by_vec2(a.q, b.p - a.p), - }; - return c; + } } // pub fn b2_abs(a: T) -> T @@ -686,52 +683,52 @@ pub fn b2_mul_t_transform(a: B2Transform, b: B2Transform) -> B2Transform { // } pub fn b2_abs_i32(v: i32) -> i32 { - return i32::abs(v); + i32::abs(v) } pub fn b2_abs(v: f32) -> f32 { - return f32::abs(v); + f32::abs(v) } pub fn b2_abs_vec2(a: B2vec2) -> B2vec2 { - return B2vec2::new(b2_abs(a.x), b2_abs(a.y)); + B2vec2::new(b2_abs(a.x), b2_abs(a.y)) } pub fn b2_abs_mat22(a: B2Mat22) -> B2Mat22 { - return B2Mat22::new(b2_abs_vec2(a.ex), b2_abs_vec2(a.ey)); + B2Mat22::new(b2_abs_vec2(a.ex), b2_abs_vec2(a.ey)) } pub fn b2_min(a: T, b: T) -> T where T: PartialOrd, { - return if a < b { a } else { b }; + if a < b { a } else { b } } pub fn b2_min_vec2(a: B2vec2, b: B2vec2) -> B2vec2 { - return B2vec2::new(b2_min(a.x, b.x), b2_min(a.y, b.y)); + B2vec2::new(b2_min(a.x, b.x), b2_min(a.y, b.y)) } pub fn b2_max(a: T, b: T) -> T where T: PartialOrd, { - return if a > b { a } else { b }; + if a > b { a } else { b } } pub fn b2_max_vec2(a: B2vec2, b: B2vec2) -> B2vec2 { - return B2vec2::new(b2_max(a.x, b.x), b2_max(a.y, b.y)); + B2vec2::new(b2_max(a.x, b.x), b2_max(a.y, b.y)) } pub fn b2_clamp(a: T, low: T, high: T) -> T where T: PartialOrd, { - return b2_max(low, b2_min(a, high)); + b2_max(low, b2_min(a, high)) } pub fn b2_clamp_vec2(a: B2vec2, low: B2vec2, high: B2vec2) -> B2vec2 { - return b2_max_vec2(low, b2_max_vec2(a, high)); + b2_max_vec2(low, b2_max_vec2(a, high)) } pub fn b2_swap(a: &mut T, b: &mut T) { @@ -752,12 +749,12 @@ pub fn b2_next_power_of_two(v: u32) -> u32 { x |= x >> 4; x |= x >> 8; x |= x >> 16; - return x + 1; + x + 1 } pub fn b2_is_power_of_two(x: u32) -> bool { let result: bool = x > 0 && (x & (x - 1)) == 0; - return result; + result } // https://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/ diff --git a/src/b2_rope.rs b/src/b2_rope.rs index 7c2c251..01bddad 100644 --- a/src/b2_rope.rs +++ b/src/b2_rope.rs @@ -60,7 +60,6 @@ pub struct B2ropeDefVertices { pub mass: f32, } -/// pub struct B2ropeDef { pub position: B2vec2, pub vertices: Vec, @@ -140,24 +139,19 @@ impl Default for B2rope { } } -/// impl B2rope { - /// pub fn create(&mut self, def: &B2ropeDef) { private::create(self, def); } - /// pub fn set_tuning(&mut self, tuning: &B2ropeTuning) { private::set_tuning(self, tuning); } - /// pub fn step(&mut self, time_step: f32, iterations: i32, position: B2vec2) { private::step(self, time_step, iterations, position); } - /// pub fn reset(&mut self, position: B2vec2) { private::reset(self, position); } diff --git a/src/b2_settings.rs b/src/b2_settings.rs index dad6d5f..a5c0d7c 100644 --- a/src/b2_settings.rs +++ b/src/b2_settings.rs @@ -1,4 +1,4 @@ -/// Settings that can be overriden for your application +//! Settings that can be overriden for your application // Tunable Constants diff --git a/src/b2_shape.rs b/src/b2_shape.rs index 01b0ece..c4369df 100644 --- a/src/b2_shape.rs +++ b/src/b2_shape.rs @@ -54,7 +54,7 @@ impl B2Shape { /// /// @return the shape type. pub fn get_type(self) -> B2ShapeType { - return self.m_type; + self.m_type } } diff --git a/src/b2_time_of_impact.rs b/src/b2_time_of_impact.rs index 4ced84c..c659189 100644 --- a/src/b2_time_of_impact.rs +++ b/src/b2_time_of_impact.rs @@ -38,7 +38,7 @@ impl Default for B2toioutputState { fn default()->Self { - return B2toioutputState::EUnknown; + B2toioutputState::EUnknown } } diff --git a/src/b2_timer.rs b/src/b2_timer.rs index b8c6bef..40eec6a 100644 --- a/src/b2_timer.rs +++ b/src/b2_timer.rs @@ -25,13 +25,11 @@ impl B2timer { pub fn get_milliseconds(&self) -> f32 { let elapsed = self.start.elapsed(); let nanos = elapsed.subsec_nanos() as u64; - let ms = 1000.0 * elapsed.as_secs() as f32 + nanos as f32/(1000.0 * 1000.0); - ms as f32 + 1000.0 * elapsed.as_secs() as f32 + nanos as f32/(1000.0 * 1000.0) } pub fn precise_time_ns(&self) -> u64 { let elapsed = self.start.elapsed(); let nanos = elapsed.subsec_nanos() as u64; - let ns = 1000*1000*1000 * elapsed.as_secs() + nanos; - ns + 1000*1000*1000 * elapsed.as_secs() + nanos } } diff --git a/src/b2_world.rs b/src/b2_world.rs index 9998faa..cec7fdc 100644 --- a/src/b2_world.rs +++ b/src/b2_world.rs @@ -23,7 +23,7 @@ impl B2world { /// Construct a world object. /// * `gravity` - the world gravity vector. pub fn new(gravity: B2vec2) -> B2worldPtr { - return private::b2_world_new(gravity); + private::b2_world_new(gravity) } /// Register a destruction listener. The listener is owned by you and must @@ -58,7 +58,7 @@ impl B2world { /// Warning: This function is locked during callbacks. ///

pub fn create_body(self_: B2worldPtr, def: &B2bodyDef) -> BodyPtr { - return private::create_body(self_, def); + private::create_body(self_, def) } /// destroy a rigid body given a definition. No reference to the definition @@ -79,7 +79,7 @@ impl B2world { /// Warning: This function is locked during callbacks. ///

pub fn create_joint(&mut self, def: &B2JointDefEnum) -> B2jointPtr { - return private::create_joint(self, def); + private::create_joint(self, def) } /// destroy a joint. This may cause the connected bodies to begin colliding. @@ -137,7 +137,7 @@ impl B2world { /// /// @return the head of the world body list. pub fn get_body_list(&self) -> DoubleLinkedList> { - return inline::get_body_list(self); + inline::get_body_list(self) } /// Get the world joint list. With the returned joint, use B2joint::get_next to get @@ -145,7 +145,7 @@ impl B2world { /// /// @return the head of the world joint list. pub fn get_joint_list(&self) -> DoubleLinkedList> { - return inline::get_joint_list(self); + inline::get_joint_list(self) } /// Get the world contact list. With the returned contact, use B2contact::get_next to get @@ -157,7 +157,7 @@ impl B2world { ///

/// Use B2contactListener to avoid missing contacts. pub fn get_contact_list(&self) -> DoubleLinkedList> { - return inline::get_contact_list(self); + inline::get_contact_list(self) } /// Enable/disable sleep. @@ -165,7 +165,7 @@ impl B2world { private::set_allow_sleeping(self, flag); } pub fn get_allow_sleeping(&self) -> bool { - return self.m_allow_sleep; + self.m_allow_sleep } /// Enable/disable warm starting. For testing. @@ -173,7 +173,7 @@ impl B2world { self.m_warm_starting = flag; } pub fn get_warm_starting(&self) -> bool { - return self.m_warm_starting; + self.m_warm_starting } /// Enable/disable continuous physics. For testing. @@ -181,7 +181,7 @@ impl B2world { self.m_continuous_physics = flag; } pub fn get_continuous_physics(&self) -> bool { - return self.m_continuous_physics; + self.m_continuous_physics } /// Enable/disable single stepped continuous physics. For testing. @@ -189,43 +189,43 @@ impl B2world { self.m_sub_stepping = flag; } pub fn get_sub_stepping(&self) -> bool { - return self.m_sub_stepping; + self.m_sub_stepping } /// Get the number of broad-phase proxies. pub fn get_proxy_count(&self) -> i32 { - return private::get_proxy_count(self); + private::get_proxy_count(self) } /// Get the number of bodies. pub fn get_body_count(&self) -> usize { - return inline::get_body_count(self); + inline::get_body_count(self) } /// Get the number of joints. pub fn get_joint_count(&self) -> usize { - return inline::get_joint_count(self); + inline::get_joint_count(self) } /// Get the number of contacts (each may have 0 or more contact points). pub fn get_contact_count(&self) -> usize { - return inline::get_contact_count(self); + inline::get_contact_count(self) } /// Get the height of the dynamic tree. pub fn get_tree_height(&self) -> i32 { - return private::get_tree_height(self); + private::get_tree_height(self) } /// Get the balance of the dynamic tree. pub fn get_tree_balance(&self) -> i32 { - return private::get_tree_balance(self); + private::get_tree_balance(self) } /// Get the quality metric of the dynamic tree. The smaller the better. /// The minimum is 1. pub fn get_tree_quality(&self) -> f32 { - return private::get_tree_quality(self); + private::get_tree_quality(self) } /// Change the global gravity vector. @@ -234,12 +234,12 @@ impl B2world { } /// Get the global gravity vector. pub fn get_gravity(&self) -> B2vec2 { - return inline::get_gravity(self); + inline::get_gravity(self) } /// Is the world locked (in the middle of a time step). pub fn is_locked(&self) -> bool { - return inline::is_locked(self); + inline::is_locked(self) } /// Set flag to control automatic clearing of forces after each time step. @@ -249,7 +249,7 @@ impl B2world { /// Get the flag that controls automatic clearing of forces after each time step. pub fn get_auto_clear_forces(&self) -> bool { - return inline::get_auto_clear_forces(self); + inline::get_auto_clear_forces(self) } /// Shift the world origin. Useful for large worlds. @@ -261,12 +261,12 @@ impl B2world { /// Get the contact manager for testing. pub fn get_contact_manager(&self) -> B2contactManagerPtr { - return inline::get_contact_manager(self); + inline::get_contact_manager(self) } /// Get the current profile. pub fn get_profile(&self) -> B2Profile { - return inline::get_profile(self); + inline::get_profile(self) } // private: @@ -332,11 +332,11 @@ mod inline { use super::*; pub fn get_body_list(self_: &B2world) -> DoubleLinkedList> { - return self_.m_body_list.clone(); + self_.m_body_list.clone() } pub fn get_joint_list(self_: &B2world) -> DoubleLinkedList> { - return self_.m_joint_list.clone(); + self_.m_joint_list.clone() } pub fn get_contact_list(self_: &B2world) -> DoubleLinkedList> { @@ -344,11 +344,11 @@ mod inline { } pub fn get_body_count(self_: &B2world) -> usize { - return self_.m_body_count; + self_.m_body_count } pub fn get_joint_count(self_: &B2world) -> usize { - return self_.m_joint_count; + self_.m_joint_count } pub fn get_contact_count(self_: &B2world) -> usize { @@ -360,11 +360,11 @@ mod inline { } pub fn get_gravity(self_: &B2world) -> B2vec2 { - return self_.m_gravity; + self_.m_gravity } pub fn is_locked(self_: &B2world) -> bool { - return self_.m_locked; + self_.m_locked } pub fn set_auto_clear_forces(self_: &mut B2world, flag: bool) { @@ -373,14 +373,14 @@ mod inline { /// Get the flag that controls automatic clearing of forces after each time step. pub fn get_auto_clear_forces(self_: &B2world) -> bool { - return self_.m_clear_forces; + self_.m_clear_forces } pub fn get_contact_manager(self_: &B2world) -> B2contactManagerPtr { - return self_.m_contact_manager.clone(); + self_.m_contact_manager.clone() } pub(crate) fn get_profile(self_: &B2world) -> B2Profile { - return self_.m_profile; + self_.m_profile } } diff --git a/src/b2_world_callbacks.rs b/src/b2_world_callbacks.rs index 69bd5ce..bac5782 100644 --- a/src/b2_world_callbacks.rs +++ b/src/b2_world_callbacks.rs @@ -36,7 +36,7 @@ pub trait B2contactFilter { /// Warning: for performance reasons this is only called when the AABBs begin to overlap. ///

fn should_collide(&self, fixture_a: FixturePtr, fixture_b: FixturePtr) -> bool { - return private::should_collide(fixture_a, fixture_b); + private::should_collide(fixture_a, fixture_b) } } diff --git a/src/b2rs_common.rs b/src/b2rs_common.rs index 7bbf404..52766b2 100644 --- a/src/b2rs_common.rs +++ b/src/b2rs_common.rs @@ -4,11 +4,11 @@ use serde::{de::DeserializeOwned, Serialize}; use std::rc::{Rc,Weak}; pub fn upgrade(v: &Weak) -> Rc { - return v.upgrade().unwrap(); + v.upgrade().unwrap() } pub fn upgrade_opt(v: &Option>) -> Rc { - return v.as_ref().unwrap().upgrade().unwrap(); + v.as_ref().unwrap().upgrade().unwrap() } #[cfg(not(feature="serde_support"))] diff --git a/src/b2rs_double_linked_list.rs b/src/b2rs_double_linked_list.rs index 95d3ac1..498d64d 100644 --- a/src/b2rs_double_linked_list.rs +++ b/src/b2rs_double_linked_list.rs @@ -20,14 +20,14 @@ pub struct DoubleLinkedList + ?Sized> { head: Option>>, } -impl fmt::Debug for dyn DoubleLinkedListNode +impl fmt::Debug for dyn DoubleLinkedListNode { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "Node") } } -impl fmt::Debug for DoubleLinkedList +impl fmt::Debug for DoubleLinkedList where T: DoubleLinkedListNode + fmt::Debug + ?Sized, { @@ -38,15 +38,15 @@ where impl + ?Sized> Default for DoubleLinkedList { fn default() -> Self { - return Self { head: None }; + Self { head: None } } } impl + ?Sized> Clone for DoubleLinkedList { fn clone(&self) -> Self { - return Self { + Self { head: self.head.clone(), - }; + } } } @@ -101,7 +101,7 @@ where { next.borrow_mut().set_prev(prev); } - + if self.head.is_some() { if ptr::eq( self.head.as_ref().unwrap().as_ref(), @@ -113,7 +113,7 @@ where } else { //println!("{:#?}", self); - assert!(false); + panic!(); } //assert!(original_len==self.len()+1); @@ -160,7 +160,7 @@ where // for (i, node) in list.iter().enumerate(){ // let prev = node.borrow().get_prev(); // let next = node.borrow().get_next(); - + // if i==0 { // assert!(prev.is_none()); // assert!(!next.is_none()); @@ -215,14 +215,14 @@ where self.head = Some(node_to_push.clone()); //assert!(original_len+1==self.len()); //assert!(self.contains(node_to_push.clone())); - //self.validate(); + //self.validate(); } - + pub fn clear(&mut self){ self.head = None; } pub fn iter(&self)->Iter{ - return Iter{ + Iter{ next: self.head.clone() } } @@ -235,7 +235,7 @@ where next: Option>> } -impl Iterator for Iter +impl Iterator for Iter where T: DoubleLinkedListNode + ?Sized, { diff --git a/src/b2rs_linked_list.rs b/src/b2rs_linked_list.rs index 48b0f63..7dc736b 100644 --- a/src/b2rs_linked_list.rs +++ b/src/b2rs_linked_list.rs @@ -19,15 +19,15 @@ pub struct LinkedList + ?Sized> { impl + ?Sized> Default for LinkedList { fn default() -> Self { - return Self { head: None }; + Self { head: None } } } impl + ?Sized> Clone for LinkedList { fn clone(&self) -> Self { - return Self { + Self { head: self.head.clone(), - }; + } } } @@ -63,35 +63,32 @@ where pub fn remove(&mut self, node_to_remove: Rc>) { let mut found: bool = false; - match self.head.clone() { - Some(ref head_node) => { - if ptr::eq(head_node.as_ref(), node_to_remove.as_ref()) { - self.head = head_node.borrow().get_next(); - found = true; - } else { - let mut node = head_node.clone(); - loop { - let next; - { - next = node.borrow().get_next(); - } - - if let Some(next) = next { - if ptr::eq(next.as_ref(), node_to_remove.as_ref()) { - node.borrow_mut() - .set_next(node_to_remove.borrow().get_next()); - found = true; - break; - } + if let Some(ref head_node) = self.head.clone() { + if ptr::eq(head_node.as_ref(), node_to_remove.as_ref()) { + self.head = head_node.borrow().get_next(); + found = true; + } else { + let mut node = head_node.clone(); + loop { + let next; + { + next = node.borrow().get_next(); + } - node = next; - } else { + if let Some(next) = next { + if ptr::eq(next.as_ref(), node_to_remove.as_ref()) { + node.borrow_mut() + .set_next(node_to_remove.borrow().get_next()); + found = true; break; } + + node = next; + } else { + break; } } } - None => {} } assert!(found); @@ -103,19 +100,19 @@ where } pub fn front(&self) -> Option<&Rc>> { - return self.head.as_ref(); + self.head.as_ref() } pub fn front_mut(&mut self) -> &mut Option>> { - return &mut self.head; + &mut self.head } pub fn clear(&mut self) { self.head = None; } pub fn iter(&self) -> Iter { - return Iter { + Iter { next: self.head.clone(), - }; + } } } diff --git a/src/joints/b2_distance_joint.rs b/src/joints/b2_distance_joint.rs index f2dac95..7f9a555 100644 --- a/src/joints/b2_distance_joint.rs +++ b/src/joints/b2_distance_joint.rs @@ -10,7 +10,7 @@ use crate::private::dynamics::joints::b2_distance_joint as private; impl Default for B2distanceJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EDistanceJoint, ..Default::default() @@ -22,7 +22,7 @@ impl Default for B2distanceJointDef { max_length: B2_MAX_FLOAT, stiffness: 0.0, damping: 0.0, - }; + } } } @@ -51,8 +51,8 @@ pub struct B2distanceJointDef { /// Maximum length. Must be greater than or equal to the minimum length. pub max_length: f32, - - /// The linear stiffness in N/m. + + /// The linear stiffness in N/m. pub damping: f32, } @@ -72,38 +72,38 @@ impl B2distanceJointDef { } impl ToDerivedJoint for B2distanceJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EDistanceJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EDistanceJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EDistanceJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EDistanceJoint(self) } } impl B2jointTraitDyn for B2distanceJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { - return private::get_anchor_a(self); + private::get_anchor_a(self) } fn get_anchor_b(&self) -> B2vec2 { - return private::get_anchor_b(self); + private::get_anchor_b(self) } /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return private::get_reaction_force(self, inv_dt); + private::get_reaction_force(self, inv_dt) } /// Get the reaction torque given the inverse time step. /// Unit is n*m. This is always zero for a distance joint. fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return private::get_reaction_torque(self, inv_dt); + private::get_reaction_torque(self, inv_dt) } fn init_velocity_constraints( @@ -126,9 +126,8 @@ impl B2jointTraitDyn for B2distanceJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } - /// fn draw(&self, draw: &mut dyn B2drawTrait) { private::draw(self, draw); } @@ -137,63 +136,63 @@ impl B2jointTraitDyn for B2distanceJoint { impl B2distanceJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// Get the rest length pub fn get_length(&self) -> f32 { - return self.m_length; + self.m_length } /// Set the rest length - /// + /// /// @returns clamped rest length pub fn set_length(&mut self, length: f32)->f32 { - return private::set_length(self,length); + private::set_length(self,length) } /// Get the minimum length - pub fn get_min_length(&self) -> f32 { - return self.m_min_length; + pub fn get_min_length(&self) -> f32 { + self.m_min_length } /// Set the minimum length - /// + /// /// @returns the clamped minimum length - pub fn set_min_length(&mut self, min_length: f32) -> f32 + pub fn set_min_length(&mut self, min_length: f32) -> f32 { - return private::set_min_length(self, min_length); + private::set_min_length(self, min_length) } /// Get the maximum length - pub fn get_max_length(&self) -> f32 { - return self.m_max_length; + pub fn get_max_length(&self) -> f32 { + self.m_max_length } /// Set the maximum length - /// + /// /// @returns the clamped maximum length pub fn set_max_length(&mut self, max_length: f32) -> f32 { - return private::set_max_length(self, max_length); + private::set_max_length(self, max_length) } /// Get the current length pub fn get_current_length(&self) -> f32 { - return private::get_current_length(self); + private::get_current_length(self) } - + /// Set/get the linear stiffness in n/m pub fn set_stiffness(&mut self, stiffness: f32) { self.m_stiffness = stiffness; } pub fn get_stiffness(&self) -> f32 { - return self.m_stiffness; + self.m_stiffness } /// Set/get linear damping in n*s/m @@ -201,11 +200,11 @@ impl B2distanceJoint { self.m_damping = damping; } pub fn get_damping(&self) -> f32 { - return self.m_damping; - } + self.m_damping + } pub(crate) fn new(data: &B2distanceJointDef) -> Self { - return private::b2_distance_joint_new(data); + private::b2_distance_joint_new(data) } } diff --git a/src/joints/b2_friction_joint.rs b/src/joints/b2_friction_joint.rs index 6a34d61..292e547 100644 --- a/src/joints/b2_friction_joint.rs +++ b/src/joints/b2_friction_joint.rs @@ -8,7 +8,7 @@ use crate::private::dynamics::joints::b2_friction_joint as private; impl Default for B2frictionJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EFrictionJoint, ..Default::default() @@ -17,7 +17,7 @@ impl Default for B2frictionJointDef { local_anchor_b: B2vec2::zero(), max_force: 0.0, max_torque: 0.0, - }; + } } } @@ -50,11 +50,11 @@ impl B2frictionJointDef { } impl ToDerivedJoint for B2frictionJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EFrictionJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EFrictionJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EFrictionJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EFrictionJoint(self) } } @@ -89,11 +89,11 @@ pub struct B2frictionJoint { impl B2frictionJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// Set the maximum friction force in n. pub fn set_max_force(&mut self, force: f32) { @@ -103,7 +103,7 @@ impl B2frictionJoint { /// Get the maximum friction force in n. pub fn get_max_force(&self) -> f32 { - return self.m_max_force; + self.m_max_force } /// Set the maximum friction torque in n*m. @@ -114,11 +114,11 @@ impl B2frictionJoint { /// Get the maximum friction torque in n*m. pub fn get_max_torque(&self) -> f32 { - return self.m_max_torque; + self.m_max_torque } pub(crate) fn new(def: &B2frictionJointDef) -> Self { - return Self { + Self { base: B2joint::new(&def.base), m_local_anchor_a: def.local_anchor_a, m_local_anchor_b: def.local_anchor_b, @@ -141,16 +141,16 @@ impl B2frictionJoint { m_inv_ib: 0.0, m_linear_mass: B2Mat22::new(B2vec2::zero(), B2vec2::zero()), m_angular_mass: 0.0, - }; + } } } impl B2jointTraitDyn for B2frictionJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -170,11 +170,11 @@ impl B2jointTraitDyn for B2frictionJoint { /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return inv_dt * self.m_linear_impulse; + inv_dt * self.m_linear_impulse } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_angular_impulse; + inv_dt * self.m_angular_impulse } fn init_velocity_constraints( &mut self, @@ -196,6 +196,6 @@ impl B2jointTraitDyn for B2frictionJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } } diff --git a/src/joints/b2_gear_joint.rs b/src/joints/b2_gear_joint.rs index 5a69956..68a8bad 100644 --- a/src/joints/b2_gear_joint.rs +++ b/src/joints/b2_gear_joint.rs @@ -8,7 +8,7 @@ use crate::private::dynamics::joints::b2_gear_joint as private; impl Default for B2gearJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EGearJoint, ..Default::default() @@ -16,7 +16,7 @@ impl Default for B2gearJointDef { joint1: None, joint2: None, ratio: 1.0, - }; + } } } @@ -40,20 +40,20 @@ pub struct B2gearJointDef { } impl ToDerivedJoint for B2gearJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EGearJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EGearJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EGearJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EGearJoint(self) } } impl B2jointTraitDyn for B2gearJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -74,12 +74,12 @@ impl B2jointTraitDyn for B2gearJoint { /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { let p: B2vec2 = self.m_impulse * self.m_jv_ac; - return inv_dt * p; + inv_dt * p } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { let l: f32 = self.m_impulse * self.m_jw_a; - return inv_dt * l; + inv_dt * l } fn init_velocity_constraints( &mut self, @@ -101,7 +101,7 @@ impl B2jointTraitDyn for B2gearJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } } @@ -119,12 +119,12 @@ impl B2jointTraitDyn for B2gearJoint { impl B2gearJoint { /// Get the first joint. pub fn get_joint1(&self) -> B2jointPtr { - return self.m_joint1.clone(); + self.m_joint1.clone() } /// Get the second joint. pub fn get_joint2(&self) -> B2jointPtr { - return self.m_joint2.clone(); + self.m_joint2.clone() } /// Set/Get the gear ratio. @@ -133,12 +133,12 @@ impl B2gearJoint { self.m_ratio = ratio; } pub fn get_ratio(&self) -> f32 { - return self.m_ratio; + self.m_ratio } pub(crate) fn new(data: &B2gearJointDef)->Self { - return private::new(data); + private::new(data) } } diff --git a/src/joints/b2_motor_joint.rs b/src/joints/b2_motor_joint.rs index 0b6c276..6cb7e48 100644 --- a/src/joints/b2_motor_joint.rs +++ b/src/joints/b2_motor_joint.rs @@ -8,7 +8,7 @@ use crate::private::dynamics::joints::b2_motor_joint as private; impl Default for B2motorJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EMotorJoint, ..Default::default() @@ -18,7 +18,7 @@ impl Default for B2motorJointDef { max_force: 1.0, max_torque: 1.0, correction_factor: 0.3, - }; + } } } @@ -59,20 +59,20 @@ impl B2motorJointDef { } impl ToDerivedJoint for B2motorJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EMotorJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EMotorJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EMotorJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EMotorJoint(self) } } impl B2jointTraitDyn for B2motorJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self.base.m_body_a.borrow().get_position(); @@ -84,11 +84,11 @@ impl B2jointTraitDyn for B2motorJoint { /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return inv_dt * self.m_linear_impulse; + inv_dt * self.m_linear_impulse } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_angular_impulse; + inv_dt * self.m_angular_impulse } fn init_velocity_constraints( &mut self, @@ -110,7 +110,7 @@ impl B2jointTraitDyn for B2motorJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } } @@ -124,7 +124,7 @@ impl B2motorJoint { } } pub fn get_linear_offset(&self) -> B2vec2 { - return self.m_linear_offset; + self.m_linear_offset } /// Set/get the target angular offset, in radians. @@ -136,7 +136,7 @@ impl B2motorJoint { } } pub fn get_angular_offset(&self) -> f32 { - return self.m_angular_offset; + self.m_angular_offset } /// Set the maximum friction force in n. @@ -147,7 +147,7 @@ impl B2motorJoint { /// Get the maximum friction force in n. pub fn get_max_force(&self) -> f32 { - return self.m_max_force; + self.m_max_force } /// Set the maximum friction torque in n*m. @@ -158,22 +158,22 @@ impl B2motorJoint { /// Get the maximum friction torque in n*m. pub fn get_max_torque(&self) -> f32 { - return self.m_max_torque; + self.m_max_torque } /// Set the position correction factor in the range [0,1]. pub fn set_correction_factor(&mut self, factor: f32) { - b2_assert(b2_is_valid(factor) && 0.0 <= factor && factor <= 1.0); + b2_assert(b2_is_valid(factor) && (0.0..=1.0).contains(&factor)); self.m_correction_factor = factor; } /// Get the position correction factor in the range [0,1]. pub fn get_correction_factor(&self) -> f32 { - return self.m_correction_factor; + self.m_correction_factor } pub(crate) fn new(def: &B2motorJointDef) -> Self { - return Self { + Self { base: B2joint::new(&def.base), m_linear_offset: def.linear_offset, m_angular_offset: def.angular_offset, @@ -199,7 +199,7 @@ impl B2motorJoint { m_inv_ib: 0.0, m_linear_mass: B2Mat22::new(B2vec2::zero(), B2vec2::zero()), m_angular_mass: 0.0, - }; + } } } diff --git a/src/joints/b2_mouse_joint.rs b/src/joints/b2_mouse_joint.rs index a09f161..9ad8851 100644 --- a/src/joints/b2_mouse_joint.rs +++ b/src/joints/b2_mouse_joint.rs @@ -7,7 +7,7 @@ use crate::private::dynamics::joints::b2_mouse_joint as private; impl Default for B2mouseJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EMouseJoint, ..Default::default() @@ -16,16 +16,16 @@ impl Default for B2mouseJointDef { max_force: 0.0, stiffness: 0.0, damping: 0.0, - }; + } } } impl ToDerivedJoint for B2mouseJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EMouseJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EMouseJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EMouseJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EMouseJoint(self) } } @@ -53,13 +53,13 @@ pub struct B2mouseJointDef { impl B2jointTraitDyn for B2mouseJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { - return self.m_target_a; + self.m_target_a } fn get_anchor_b(&self) -> B2vec2 { return self @@ -72,13 +72,13 @@ impl B2jointTraitDyn for B2mouseJoint { /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return inv_dt * self.m_impulse; + inv_dt * self.m_impulse } /// Get the reaction torque given the inverse time step. /// Unit is n*m. This is always zero for a distance joint. fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * 0.0; + inv_dt * 0.0 } fn init_velocity_constraints( @@ -101,7 +101,7 @@ impl B2jointTraitDyn for B2mouseJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } /// Implement B2joint::shift_origin @@ -118,7 +118,7 @@ impl B2mouseJoint { } } pub fn get_target(&self) -> B2vec2 { - return self.m_target_a; + self.m_target_a } /// Set/get the maximum force in Newtons. @@ -126,25 +126,25 @@ impl B2mouseJoint { self.m_max_force = force; } pub fn get_max_force(&self) -> f32 { - return self.m_max_force; + self.m_max_force } /// Set/get the linear stiffness in N/m pub fn set_stiffness(&mut self, stiffness: f32) { self.m_stiffness = stiffness; } - pub fn get_stiffness(&self) -> f32 { return self.m_stiffness; } + pub fn get_stiffness(&self) -> f32 { self.m_stiffness} /// Set/get linear damping in N*s/m pub fn set_damping(&mut self, damping: f32) { self.m_damping = damping; } - pub fn get_damping(&self) -> f32 { return self.m_damping; } + pub fn get_damping(&self) -> f32 { self.m_damping} pub fn new(def: &B2mouseJointDef) -> Self { let m_target_a = def.target; let body_b_transform = def.base.body_b.as_ref().unwrap().borrow().get_transform(); - return B2mouseJoint { + B2mouseJoint { base: B2joint::new(&def.base), - m_target_a: m_target_a, + m_target_a, m_local_anchor_b: b2_mul_t_transform_by_vec2(body_b_transform, m_target_a), m_max_force: def.max_force, @@ -163,7 +163,7 @@ impl B2mouseJoint { m_inv_ib: 0.0, m_mass: B2Mat22::default(), m_c: B2vec2::zero(), - }; + } } } diff --git a/src/joints/b2_prismatic_joint.rs b/src/joints/b2_prismatic_joint.rs index 156005e..6595ca0 100644 --- a/src/joints/b2_prismatic_joint.rs +++ b/src/joints/b2_prismatic_joint.rs @@ -9,7 +9,7 @@ use crate::private::dynamics::joints::b2_prismatic_joint as private; impl Default for B2prismaticJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EPrismaticJoint, ..Default::default() @@ -24,7 +24,7 @@ impl Default for B2prismaticJointDef { enable_motor: false, max_motor_force: 0.0, motor_speed: 0.0, - }; + } } } @@ -89,11 +89,11 @@ impl B2prismaticJointDef { } impl ToDerivedJoint for B2prismaticJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EPrismaticJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EPrismaticJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EPrismaticJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EPrismaticJoint(self) } } @@ -143,37 +143,37 @@ pub struct B2prismaticJoint { impl B2prismaticJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// The local joint axis relative to body_a. pub fn get_local_axis_a(&self) -> B2vec2 { - return self.m_local_xaxis_a; + self.m_local_xaxis_a } /// Get the reference angle. pub fn get_reference_angle(&self) -> f32 { - return self.m_reference_angle; + self.m_reference_angle } /// Get the current joint translation, usually in meters. pub fn get_joint_translation(&self) -> f32 { - return private::get_joint_translation(self); + private::get_joint_translation(self) } /// Get the current joint translation speed, usually in meters per second. pub fn get_joint_speed(&self) -> f32 { - return private::get_joint_speed(self); + private::get_joint_speed(self) } /// Is the joint limit enabled? pub fn is_limit_enabled(&self) -> bool { - return self.m_enable_limit; + self.m_enable_limit } /// Enable/disable the joint limit. @@ -189,12 +189,12 @@ impl B2prismaticJoint { /// Get the lower joint limit, usually in meters. pub fn get_lower_limit(&self) -> f32 { - return self.m_lower_translation; + self.m_lower_translation } /// Get the upper joint limit, usually in meters. pub fn get_upper_limit(&self) -> f32 { - return self.m_upper_translation; + self.m_upper_translation } /// Set the joint limits, usually in meters. @@ -212,7 +212,7 @@ impl B2prismaticJoint { /// Is the joint motor enabled? pub fn is_motor_enabled(&self) -> bool { - return self.m_enable_motor; + self.m_enable_motor } /// Enable/disable the joint motor. @@ -235,7 +235,7 @@ impl B2prismaticJoint { /// Get the motor speed, usually in meters per second. pub fn get_motor_speed(&self) -> f32 { - return self.m_motor_speed; + self.m_motor_speed } /// Set the maximum motor force, usually in n. @@ -248,24 +248,24 @@ impl B2prismaticJoint { } pub fn get_max_motor_force(&self) -> f32 { - return self.m_max_motor_force; + self.m_max_motor_force } /// Get the current motor force given the inverse time step, usually in n. pub fn get_motor_force(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_motor_impulse; + inv_dt * self.m_motor_impulse } pub(crate) fn new(def: &B2prismaticJointDef) -> Self { - return private::new(def); + private::new(def) } } impl B2jointTraitDyn for B2prismaticJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -285,13 +285,13 @@ impl B2jointTraitDyn for B2prismaticJoint { /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return inv_dt + inv_dt * (self.m_impulse.x * self.m_perp - + (self.m_motor_impulse + self.m_lower_impulse - self.m_upper_impulse) * self.m_axis); + + (self.m_motor_impulse + self.m_lower_impulse - self.m_upper_impulse) * self.m_axis) } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_impulse.y; + inv_dt * self.m_impulse.y } fn init_velocity_constraints( &mut self, @@ -313,10 +313,9 @@ impl B2jointTraitDyn for B2prismaticJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } - /// fn draw(&self, draw: &mut dyn B2drawTrait) { private::draw(self, draw); } diff --git a/src/joints/b2_pulley_joint.rs b/src/joints/b2_pulley_joint.rs index f56a023..74131e5 100644 --- a/src/joints/b2_pulley_joint.rs +++ b/src/joints/b2_pulley_joint.rs @@ -10,7 +10,7 @@ use crate::private::dynamics::joints::b2_pulley_joint as private; impl Default for B2pulleyJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EPulleyJoint, collide_connected: true, @@ -23,7 +23,7 @@ impl Default for B2pulleyJointDef { length_a: 0.0, length_b: 0.0, ratio: 1.0, - }; + } } } @@ -56,6 +56,7 @@ pub struct B2pulleyJointDef { impl B2pulleyJointDef { /// initialize the bodies, anchors, lengths, max lengths, and ratio using the world anchors. + #[allow(clippy::too_many_arguments)] pub fn initialize( &mut self, body_a: BodyPtr, @@ -83,20 +84,20 @@ impl B2pulleyJointDef { } impl ToDerivedJoint for B2pulleyJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EPulleyJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EPulleyJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EPulleyJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EPulleyJoint(self) } } impl B2jointTraitDyn for B2pulleyJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -117,12 +118,12 @@ impl B2jointTraitDyn for B2pulleyJoint { /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { let p: B2vec2 = self.m_impulse * self.m_u_b; - return inv_dt * p; + inv_dt * p } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { b2_not_used(inv_dt); - return 0.0; + 0.0 } fn init_velocity_constraints( &mut self, @@ -144,7 +145,7 @@ impl B2jointTraitDyn for B2pulleyJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } /// Implement B2joint::shift_origin @@ -166,27 +167,27 @@ impl B2jointTraitDyn for B2pulleyJoint { impl B2pulleyJoint { /// Get the first ground anchor. pub fn get_ground_anchor_a(&self) -> B2vec2 { - return self.m_ground_anchor_a; + self.m_ground_anchor_a } /// Get the second ground anchor. pub fn get_ground_anchor_b(&self) -> B2vec2 { - return self.m_ground_anchor_b; + self.m_ground_anchor_b } /// Get the current length of the segment attached to body_a. pub fn get_length_a(&self) -> f32 { - return self.m_length_a; + self.m_length_a } /// Get the current length of the segment attached to body_b. pub fn get_length_b(&self) -> f32 { - return self.m_length_b; + self.m_length_b } /// Get the pulley ratio. pub fn get_ratio(&self) -> f32 { - return self.m_ratio; + self.m_ratio } /// Get the current length of the segment attached to body_a. @@ -198,7 +199,7 @@ impl B2pulleyJoint { .get_world_point(self.m_local_anchor_a); let s: B2vec2 = self.m_ground_anchor_a; let d: B2vec2 = p - s; - return d.length(); + d.length() } /// Get the current length of the segment attached to body_b. @@ -210,11 +211,11 @@ impl B2pulleyJoint { .get_world_point(self.m_local_anchor_b); let s: B2vec2 = self.m_ground_anchor_b; let d: B2vec2 = p - s; - return d.length(); + d.length() } pub(crate) fn new(def: &B2pulleyJointDef) -> B2pulleyJoint { - return private::new(def); + private::new(def) } } diff --git a/src/joints/b2_revolute_joint.rs b/src/joints/b2_revolute_joint.rs index db55e47..aca3f87 100644 --- a/src/joints/b2_revolute_joint.rs +++ b/src/joints/b2_revolute_joint.rs @@ -9,7 +9,7 @@ use crate::b2_draw::*; impl Default for B2revoluteJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::ERevoluteJoint, ..Default::default() @@ -23,7 +23,7 @@ impl Default for B2revoluteJointDef { motor_speed: 0.0, enable_limit: false, enable_motor: false, - }; + } } } @@ -83,11 +83,11 @@ impl B2revoluteJointDef { } impl ToDerivedJoint for B2revoluteJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::ERevoluteJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::ERevoluteJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::ERevoluteJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::ERevoluteJoint(self) } } @@ -136,36 +136,36 @@ pub struct B2revoluteJoint { impl B2revoluteJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// Get the reference angle. pub fn get_reference_angle(&self) -> f32 { - return self.m_reference_angle; + self.m_reference_angle } /// Get the current joint angle in radians. pub fn get_joint_angle(&self) -> f32 { let b_a = self.base.m_body_a.borrow(); let b_b = self.base.m_body_b.borrow(); - return b_b.m_sweep.a - b_a.m_sweep.a - self.m_reference_angle; + b_b.m_sweep.a - b_a.m_sweep.a - self.m_reference_angle } /// Get the current joint angle speed in radians per second. pub fn get_joint_speed(&self) -> f32 { let b_a = self.base.m_body_a.borrow(); let b_b = self.base.m_body_b.borrow(); - return b_b.m_angular_velocity - b_a.m_angular_velocity; + b_b.m_angular_velocity - b_a.m_angular_velocity } /// Is the joint limit enabled? pub fn is_limit_enabled(&self) -> bool { - return self.m_enable_limit; + self.m_enable_limit } /// Enable/disable the joint limit. @@ -182,12 +182,12 @@ impl B2revoluteJoint { /// Get the lower joint limit in radians. pub fn get_lower_limit(&self) -> f32 { - return self.m_lower_angle; + self.m_lower_angle } /// Get the upper joint limit in radians. pub fn get_upper_limit(&self) -> f32 { - return self.m_upper_angle; + self.m_upper_angle } /// Set the joint limits in radians. @@ -206,7 +206,7 @@ impl B2revoluteJoint { /// Is the joint motor enabled? pub fn is_motor_enabled(&self) -> bool { - return self.m_enable_motor; + self.m_enable_motor } /// Enable/disable the joint motor. @@ -229,7 +229,7 @@ impl B2revoluteJoint { /// Get the motor speed in radians per second. pub fn get_motor_speed(&self) -> f32 { - return self.m_motor_speed; + self.m_motor_speed } /// Set the maximum motor torque, usually in n-m. @@ -241,17 +241,17 @@ impl B2revoluteJoint { } } pub fn get_max_motor_torque(&self) -> f32 { - return self.m_max_motor_torque; + self.m_max_motor_torque } /// Get the current motor torque given the inverse time step. /// Unit is n*m. pub fn get_motor_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_motor_impulse; + inv_dt * self.m_motor_impulse } pub(crate) fn new(def: &B2revoluteJointDef) -> Self { - return Self { + Self { base: B2joint::new(&def.base), m_local_anchor_a: def.local_anchor_a, @@ -294,10 +294,10 @@ impl B2revoluteJoint { impl B2jointTraitDyn for B2revoluteJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -318,12 +318,12 @@ impl B2jointTraitDyn for B2revoluteJoint { /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { let p = B2vec2::new(self.m_impulse.x, self.m_impulse.y); - return inv_dt * p; + inv_dt * p } /// Get the reaction torque due to the joint limit given the inverse time step. /// Unit is n*m. fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * (self.m_motor_impulse + self.m_lower_impulse - self.m_upper_impulse); + inv_dt * (self.m_motor_impulse + self.m_lower_impulse - self.m_upper_impulse) } fn init_velocity_constraints( &mut self, @@ -345,7 +345,7 @@ impl B2jointTraitDyn for B2revoluteJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } fn draw(&self, draw: &mut dyn B2drawTrait) { diff --git a/src/joints/b2_weld_joint.rs b/src/joints/b2_weld_joint.rs index c39f524..b062bdb 100644 --- a/src/joints/b2_weld_joint.rs +++ b/src/joints/b2_weld_joint.rs @@ -7,7 +7,7 @@ use crate::private::dynamics::joints::b2_weld_joint as private; impl Default for B2weldJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EWeldJoint, ..Default::default() @@ -17,7 +17,7 @@ impl Default for B2weldJointDef { reference_angle: 0.0, stiffness : 0.0, damping : 0.0, - }; + } } } @@ -61,11 +61,11 @@ impl B2weldJointDef { } impl ToDerivedJoint for B2weldJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EWeldJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EWeldJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EWeldJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EWeldJoint(self) } } @@ -101,30 +101,30 @@ pub struct B2weldJoint { impl B2weldJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// Get the reference angle. pub fn get_reference_angle(&self) -> f32 { - return self.m_reference_angle; + self.m_reference_angle } /// Set/get stiffness in n*m pub fn set_stiffness(&mut self,hz: f32) { self.m_stiffness = hz; } - pub fn get_stiffness(&self)-> f32 { return self.m_stiffness; } + pub fn get_stiffness(&self)-> f32 { self.m_stiffness} /// Set/get damping in n*m*s pub fn set_damping(&mut self,damping: f32) { self.m_damping = damping; } - pub fn get_damping(&self) -> f32{ return self.m_damping; } + pub fn get_damping(&self) -> f32{ self.m_damping} pub(crate) fn new(def: &B2weldJointDef) -> Self { - return Self { + Self { base: B2joint::new(&def.base), m_local_anchor_a: def.local_anchor_a, @@ -156,10 +156,10 @@ impl B2weldJoint { impl B2jointTraitDyn for B2weldJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -180,11 +180,11 @@ impl B2jointTraitDyn for B2weldJoint { /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { let p = B2vec2::new(self.m_impulse.x, self.m_impulse.y); - return inv_dt * p; + inv_dt * p } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_impulse.z; + inv_dt * self.m_impulse.z } fn init_velocity_constraints( &mut self, @@ -206,6 +206,6 @@ impl B2jointTraitDyn for B2weldJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } } diff --git a/src/joints/b2_wheel_joint.rs b/src/joints/b2_wheel_joint.rs index a580187..7edb3d3 100644 --- a/src/joints/b2_wheel_joint.rs +++ b/src/joints/b2_wheel_joint.rs @@ -9,7 +9,7 @@ use crate::private::dynamics::joints::b2_wheel_joint as private; impl Default for B2wheelJointDef { fn default() -> Self { - return Self { + Self { base: B2jointDef { jtype: B2jointType::EWheelJoint, ..Default::default() @@ -25,7 +25,7 @@ impl Default for B2wheelJointDef { motor_speed: 0.0, stiffness: 0.0, damping: 0.0, - }; + } } } @@ -92,11 +92,11 @@ impl B2wheelJointDef { } impl ToDerivedJoint for B2wheelJoint { - fn as_derived(&self) -> JointAsDerived { - return JointAsDerived::EWheelJoint(self); + fn as_derived(&self) -> JointAsDerived<'_, D> { + JointAsDerived::EWheelJoint(self) } - fn as_derived_mut(&mut self) -> JointAsDerivedMut { - return JointAsDerivedMut::EWheelJoint(self); + fn as_derived_mut(&mut self) -> JointAsDerivedMut<'_, D> { + JointAsDerivedMut::EWheelJoint(self) } } @@ -160,17 +160,17 @@ pub struct B2wheelJoint { impl B2wheelJoint { /// The local anchor point relative to body_a's origin. pub fn get_local_anchor_a(&self) -> B2vec2 { - return self.m_local_anchor_a; + self.m_local_anchor_a } /// The local anchor point relative to body_b's origin. pub fn get_local_anchor_b(&self) -> B2vec2 { - return self.m_local_anchor_b; + self.m_local_anchor_b } /// The local joint axis relative to body_a. pub fn get_local_axis_a(&self) -> B2vec2 { - return self.m_local_xaxis_a; + self.m_local_xaxis_a } /// Get the current joint translation, usually in meters. @@ -182,7 +182,7 @@ impl B2wheelJoint { let d: B2vec2 = p_b - p_a; let axis: B2vec2 = b_a.get_world_vector(self.m_local_xaxis_a); let translation: f32 = b2_dot(d, axis); - return translation; + translation } /// Get the current joint linear speed, usually in meters per second. @@ -209,26 +209,26 @@ impl B2wheelJoint { axis, v_b + b2_cross_scalar_by_vec(w_b, r_b) - v_a - b2_cross_scalar_by_vec(w_a, r_a), ); - return speed; + speed } /// Get the current joint angle in radians. pub fn get_joint_angle(&self) -> f32 { let b_a = self.base.m_body_a.borrow(); let b_b = self.base.m_body_b.borrow(); - return b_b.m_sweep.a - b_a.m_sweep.a; + b_b.m_sweep.a - b_a.m_sweep.a } /// Get the current joint angular speed in radians per second. pub fn get_joint_angular_speed(&self) -> f32 { let w_a: f32 = self.base.m_body_a.borrow().m_angular_velocity; let w_b: f32 = self.base.m_body_b.borrow().m_angular_velocity; - return w_b - w_a; + w_b - w_a } /// Is the joint limit enabled? pub fn is_limit_enabled(&self) -> bool { - return self.m_enable_limit; + self.m_enable_limit } /// Enable/disable the joint translation limit. @@ -244,12 +244,12 @@ impl B2wheelJoint { /// Get the lower joint translation limit, usually in meters. pub fn get_lower_limit(&self) -> f32 { - return self.m_lower_translation; + self.m_lower_translation } /// Get the upper joint translation limit, usually in meters. pub fn get_upper_limit(&self) -> f32 { - return self.m_upper_translation; + self.m_upper_translation } /// Set the joint translation limits, usually in meters. @@ -267,7 +267,7 @@ impl B2wheelJoint { /// Is the joint motor enabled? pub fn is_motor_enabled(&self) -> bool { - return self.m_enable_motor; + self.m_enable_motor } /// Enable/disable the joint motor. @@ -290,7 +290,7 @@ impl B2wheelJoint { /// Get the motor speed, usually in radians per second. pub fn get_motor_speed(&self) -> f32 { - return self.m_motor_speed; + self.m_motor_speed } /// Set/Get the maximum motor force, usually in n-m. @@ -302,12 +302,12 @@ impl B2wheelJoint { } } pub fn get_max_motor_torque(&self) -> f32 { - return self.m_max_motor_torque; + self.m_max_motor_torque } /// Get the current motor torque given the inverse time step, usually in n-m. pub fn get_motor_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_motor_impulse; + inv_dt * self.m_motor_impulse } /// Access spring stiffness @@ -315,7 +315,7 @@ impl B2wheelJoint { self.m_stiffness = stiffness; } pub fn get_stiffness(&self) -> f32 { - return self.m_stiffness; + self.m_stiffness } /// Access damping @@ -323,11 +323,11 @@ impl B2wheelJoint { self.m_damping = damping; } pub fn get_damping(&self) -> f32 { - return self.m_damping; + self.m_damping } pub(crate) fn new(def: &B2wheelJointDef) -> Self { - return Self { + Self { base: B2joint::new(&def.base), m_local_anchor_a: def.local_anchor_a, m_local_anchor_b: def.local_anchor_b, @@ -376,16 +376,16 @@ impl B2wheelJoint { m_s_bx: 0.0, m_s_ay: 0.0, m_s_by: 0.0, - }; + } } } impl B2jointTraitDyn for B2wheelJoint { fn get_base(&self) -> &B2joint { - return &self.base; + &self.base } fn get_base_mut(&mut self) -> &mut B2joint { - return &mut self.base; + &mut self.base } fn get_anchor_a(&self) -> B2vec2 { return self @@ -405,11 +405,11 @@ impl B2jointTraitDyn for B2wheelJoint { /// Get the reaction force given the inverse time step. /// Unit is n. fn get_reaction_force(&self, inv_dt: f32) -> B2vec2 { - return inv_dt * (self.m_impulse * self.m_ay + (self.m_spring_impulse + self.m_lower_impulse - self.m_upper_impulse) * self.m_ax); + inv_dt * (self.m_impulse * self.m_ay + (self.m_spring_impulse + self.m_lower_impulse - self.m_upper_impulse) * self.m_ax) } fn get_reaction_torque(&self, inv_dt: f32) -> f32 { - return inv_dt * self.m_motor_impulse; + inv_dt * self.m_motor_impulse } fn init_velocity_constraints( @@ -432,7 +432,7 @@ impl B2jointTraitDyn for B2wheelJoint { data: &B2solverData, positions: &mut [B2position], ) -> bool { - return private::solve_position_constraints(self, data, positions); + private::solve_position_constraints(self, data, positions) } /// Debug draw this joint diff --git a/src/private/collision/b2_broad_phase.rs b/src/private/collision/b2_broad_phase.rs index 694a42a..3ee4565 100644 --- a/src/private/collision/b2_broad_phase.rs +++ b/src/private/collision/b2_broad_phase.rs @@ -16,7 +16,7 @@ pub fn b2_broad_phase_b2_broad_phase() -> B2broad let mut m_move_buffer = Vec::::new(); m_move_buffer.resize_with(m_move_capacity as usize, Default::default); - return B2broadPhase:: { + B2broadPhase:: { m_tree: B2dynamicTree::::new(), m_proxy_count, m_move_buffer, @@ -27,7 +27,7 @@ pub fn b2_broad_phase_b2_broad_phase() -> B2broad m_pair_capacity, m_pair_count, }, - }; + } } pub fn b2_broad_phase_create_proxy( @@ -38,7 +38,7 @@ pub fn b2_broad_phase_create_proxy( let proxy_id: i32 = self_.m_tree.create_proxy(aabb, user_data); self_.m_proxy_count += 1; self_.buffer_move(proxy_id); - return proxy_id; + proxy_id } pub fn b2_broad_phase_destroy_proxy(self_: &mut B2broadPhase, proxy_id: i32) { @@ -107,5 +107,5 @@ pub fn b2_broad_phase_query_callback(self_: &mut B2broadPhasePairs, m_query_prox self_.m_pair_buffer[self_.m_pair_count as usize].proxy_id_b = b2_max(proxy_id, m_query_proxy_id); self_.m_pair_count += 1; - return true; + true } diff --git a/src/private/collision/b2_chain_shape.rs b/src/private/collision/b2_chain_shape.rs index 8c72f10..e531bc5 100644 --- a/src/private/collision/b2_chain_shape.rs +++ b/src/private/collision/b2_chain_shape.rs @@ -11,7 +11,7 @@ pub fn b2_chain_shape_clear(self_: &mut B2chainShape) { pub fn b2_chain_shape_create_loop(self_: &mut B2chainShape, vertices: &[B2vec2]) { let count = vertices.len(); - b2_assert(self_.m_vertices.len() == 0); + b2_assert(self_.m_vertices.is_empty()); b2_assert(count >= 3); if count < 3 { return; @@ -24,14 +24,14 @@ pub fn b2_chain_shape_create_loop(self_: &mut B2chainShape, vertices: &[B2vec2]) b2_assert(b2_distance_vec2_squared(v1, v2) > B2_LINEAR_SLOP * B2_LINEAR_SLOP); } - self_.m_vertices = Vec::from([vertices, &[vertices[0]]].concat()); + self_.m_vertices = [vertices, &[vertices[0]]].concat(); self_.m_prev_vertex = self_.m_vertices[self_.m_vertices.len() - 2]; self_.m_next_vertex = self_.m_vertices[1]; } pub fn b2_chain_shape_create_chain(self_: &mut B2chainShape, vertices: &[B2vec2], prev_vertex: B2vec2, next_vertex: B2vec2) { let count = vertices.len(); - b2_assert(self_.m_vertices.len() == 0); + b2_assert(self_.m_vertices.is_empty()); b2_assert(count >= 2); for i in 1..count { // If the code crashes here, it means your vertices are too close together. @@ -48,12 +48,12 @@ pub fn b2_chain_shape_create_chain(self_: &mut B2chainShape, vertices: &[B2vec2] } pub fn b2_shape_dyn_trait_clone(self_: &B2chainShape) -> Box { - return Box::new(B2chainShape::clone(&self_)); + Box::new(B2chainShape::clone(self_)) } pub fn b2_shape_dyn_trait_get_child_count(self_: &B2chainShape) -> usize { // edge count = vertex count - 1 - return self_.m_vertices.len() - 1; + self_.m_vertices.len() - 1 } pub fn b2_chain_shape_get_child_edge(self_: &B2chainShape, edge: &mut B2edgeShape, index: usize) { @@ -61,7 +61,7 @@ pub fn b2_chain_shape_get_child_edge(self_: &B2chainShape, edge: &mut B2edgeShap edge.base.m_type = B2ShapeType::EEdge; edge.base.m_radius = self_.base.m_radius; - edge.m_vertex1 = self_.m_vertices[index + 0]; + edge.m_vertex1 = self_.m_vertices[index]; edge.m_vertex2 = self_.m_vertices[index + 1]; edge.m_one_sided = true; @@ -81,7 +81,7 @@ pub fn b2_chain_shape_get_child_edge(self_: &B2chainShape, edge: &mut B2edgeShap pub fn b2_shape_dyn_trait_test_point(_self: &B2chainShape, xf: B2Transform, p: B2vec2) -> bool { b2_not_used(xf); b2_not_used(p); - return false; + false } pub fn b2_shape_dyn_trait_ray_cast( self_: &B2chainShape, @@ -103,7 +103,7 @@ pub fn b2_shape_dyn_trait_ray_cast( edge_shape.m_vertex1 = self_.m_vertices[i1]; edge_shape.m_vertex2 = self_.m_vertices[i2]; - return edge_shape.ray_cast(output, &input, xf, 0); + edge_shape.ray_cast(output, input, xf, 0) } pub fn b2_shape_dyn_trait_compute_aabb( diff --git a/src/private/collision/b2_circle_shape.rs b/src/private/collision/b2_circle_shape.rs index 09255ff..8fd2ae5 100644 --- a/src/private/collision/b2_circle_shape.rs +++ b/src/private/collision/b2_circle_shape.rs @@ -5,17 +5,17 @@ use crate::b2_common::*; use crate::b2_shape::*; pub fn clone(self_: &B2circleShape) -> Box { - return Box::new(B2circleShape::clone(&self_)); + Box::new(B2circleShape::clone(self_)) } pub fn get_child_count(_self: &B2circleShape) -> usize { - return 1; + 1 } pub fn test_point(self_: &B2circleShape, transform: B2Transform, p: B2vec2) -> bool { let center: B2vec2 = transform.p + b2_mul_rot_by_vec2(transform.q, self_.m_p); let d: B2vec2 = p - center; - return b2_dot(d, d) <= self_.base.m_radius * self_.base.m_radius; + b2_dot(d, d) <= self_.base.m_radius * self_.base.m_radius } // Collision Detection in Interactive 3D Environments by Gino van den Bergen @@ -59,7 +59,7 @@ pub fn ray_cast( return true; } - return false; + false } pub fn compute_aabb( self_: &B2circleShape, diff --git a/src/private/collision/b2_collide_edge.rs b/src/private/collision/b2_collide_edge.rs index bd9344f..43ab5c9 100644 --- a/src/private/collision/b2_collide_edge.rs +++ b/src/private/collision/b2_collide_edge.rs @@ -37,9 +37,11 @@ pub fn b2_collide_edge_and_circle( let v: f32 = b2_dot(e, q - a); let radius: f32 = edge_a.base.m_radius + circle_b.base.m_radius; - let mut cf = B2contactFeature::default(); - cf.index_b = 0; - cf.type_b = B2contactFeatureType::EVertex as u8; + let mut cf = B2contactFeature { + index_b: 0, + type_b: B2contactFeatureType::EVertex as u8, + ..Default::default() + }; // Region A if v <= 0.0 { let p: B2vec2 = a; @@ -131,7 +133,7 @@ enum B2ePAxisType { impl Default for B2ePAxisType { fn default() -> Self { - return B2ePAxisType::EUnknown; + B2ePAxisType::EUnknown } } @@ -180,12 +182,12 @@ fn b2_compute_edge_separation(polygon_b: B2tempPolygon, v1: B2vec2, normal1: B2v let axes: [B2vec2; 2] = [normal1, -normal1]; // Find axis with least overlap (min-max problem) - for j in 0..2 { + for (j, axis_vec) in axes.iter().enumerate() { let mut sj: f32 = B2_MAX_FLOAT; // Find deepest polygon vertex along axis j for i in 0..polygon_b.count { - let si: f32 = b2_dot(axes[j], polygon_b.vertices[i] - v1); + let si: f32 = b2_dot(*axis_vec, polygon_b.vertices[i] - v1); if si < sj { sj = si; } @@ -194,11 +196,11 @@ fn b2_compute_edge_separation(polygon_b: B2tempPolygon, v1: B2vec2, normal1: B2v if sj > axis.separation { axis.index = j as i32; axis.separation = sj; - axis.normal = axes[j]; + axis.normal = *axis_vec; } } - return axis; + axis } fn b2_compute_polygon_separation(polygon_b: B2tempPolygon, v1: B2vec2, v2: B2vec2) -> B2epaxis { @@ -224,7 +226,7 @@ fn b2_compute_polygon_separation(polygon_b: B2tempPolygon, v1: B2vec2, v2: B2vec } } - return axis; + axis } pub fn b2_collide_edge_and_polygon( @@ -256,8 +258,10 @@ pub fn b2_collide_edge_and_polygon( } // Get polygon_b in frameA - let mut temp_polygon_b = B2tempPolygon::default(); - temp_polygon_b.count = polygon_b.m_count; + let mut temp_polygon_b = B2tempPolygon { + count: polygon_b.m_count, + ..Default::default() + }; for i in 0..polygon_b.m_count { temp_polygon_b.vertices[i] = b2_mul_transform_by_vec2(xf, polygon_b.m_vertices[i]); temp_polygon_b.normals[i] = b2_mul_rot_by_vec2(xf.q, polygon_b.m_normals[i]); @@ -306,6 +310,7 @@ pub fn b2_collide_edge_and_polygon( let side1: bool = b2_dot(primary_axis.normal, edge1) <= 0.0; // Check Gauss Map + #[allow(clippy::collapsible_else_if)] if side1 { if convex1 { if b2_cross(primary_axis.normal, normal0) > SIN_TOL { @@ -448,23 +453,23 @@ pub fn b2_collide_edge_and_polygon( } let mut point_count: usize = 0; - for i in 0..B2_MAX_MANIFOLD_POINTS { - let separation: f32; + for cp2 in clip_points2.iter().take(B2_MAX_MANIFOLD_POINTS) { + - separation = b2_dot(rf.normal, clip_points2[i].v - rf.v1); + let separation: f32 = b2_dot(rf.normal, cp2.v - rf.v1); if separation <= radius { let cp: &mut B2manifoldPoint = &mut manifold.points[point_count]; if primary_axis.axis_type == B2ePAxisType::EEdgeA { - cp.local_point = b2_mul_t_transform_by_vec2(xf, clip_points2[i].v); - cp.id = clip_points2[i].id; + cp.local_point = b2_mul_t_transform_by_vec2(xf, cp2.v); + cp.id = cp2.id; } else { - cp.local_point = clip_points2[i].v; - cp.id.cf.type_a = clip_points2[i].id.cf.type_b; - cp.id.cf.type_b = clip_points2[i].id.cf.type_a; - cp.id.cf.index_a = clip_points2[i].id.cf.index_b; - cp.id.cf.index_b = clip_points2[i].id.cf.index_a; + cp.local_point = cp2.v; + cp.id.cf.type_a = cp2.id.cf.type_b; + cp.id.cf.type_b = cp2.id.cf.type_a; + cp.id.cf.index_a = cp2.id.cf.index_b; + cp.id.cf.index_b = cp2.id.cf.index_a; } point_count += 1; diff --git a/src/private/collision/b2_collide_polygon.rs b/src/private/collision/b2_collide_polygon.rs index 11a551d..28a7df9 100644 --- a/src/private/collision/b2_collide_polygon.rs +++ b/src/private/collision/b2_collide_polygon.rs @@ -28,8 +28,8 @@ fn b2_find_max_separation( // Find deepest point for normal i. let mut si: f32 = B2_MAX_FLOAT; - for j in 0..count2 { - let sij: f32 = b2_dot(n, v2s[j] - v1); + for v2 in v2s.iter().take(count2) { + let sij: f32 = b2_dot(n, *v2 - v1); if sij < si { si = sij; } @@ -42,7 +42,7 @@ fn b2_find_max_separation( } *edge_index = best_index; - return max_separation; + max_separation } pub fn b2_find_incident_edge( @@ -67,8 +67,8 @@ pub fn b2_find_incident_edge( // Find the incident edge on poly2. let mut index: usize = 0; let mut min_dot: f32 = B2_MAX_FLOAT; - for i in 0..count2 { - let dot: f32 = b2_dot(normal1, normals2[i]); + for (i, normal2) in normals2.iter().enumerate().take(count2) { + let dot: f32 = b2_dot(normal1, *normal2); if dot < min_dot { min_dot = dot; index = i; @@ -201,13 +201,13 @@ pub fn b2_collide_polygons( manifold.local_point = plane_point; let mut point_count: usize = 0; - for i in 0..B2_MAX_MANIFOLD_POINTS { - let separation: f32 = b2_dot(normal, clip_points2[i].v) - front_offset; + for cp2 in clip_points2.iter().take(B2_MAX_MANIFOLD_POINTS) { + let separation: f32 = b2_dot(normal, cp2.v) - front_offset; if separation <= total_radius { let cp = &mut manifold.points[point_count]; - cp.local_point = b2_mul_t_transform_by_vec2(xf2, clip_points2[i].v); - cp.id = clip_points2[i].id; + cp.local_point = b2_mul_t_transform_by_vec2(xf2, cp2.v); + cp.id = cp2.id; if flip != 0 { // Swap features diff --git a/src/private/collision/b2_collision.rs b/src/private/collision/b2_collision.rs index 155e02f..59bc1c7 100644 --- a/src/private/collision/b2_collision.rs +++ b/src/private/collision/b2_collision.rs @@ -79,30 +79,30 @@ pub fn b2_get_point_states( } // Detect persists and removes. - for i in 0..manifold1.point_count { + for (i, state) in state1.iter_mut().enumerate().take(manifold1.point_count) { let id: B2contactId = manifold1.points[i].id; - state1[i] = B2pointState::B2RemoveState; + *state = B2pointState::B2RemoveState; for j in 0..manifold2.point_count { - + if manifold2.points[j].id.cf == id.cf { - state1[i] = B2pointState::B2PersistState; + *state = B2pointState::B2PersistState; break; } - + } } // Detect persists and adds. - for i in 0..manifold2.point_count { + for (i, state) in state2.iter_mut().enumerate().take(manifold2.point_count) { let id: B2contactId = manifold2.points[i].id; - state2[i] = B2pointState::B2AddState; + *state = B2pointState::B2AddState; for j in 0..manifold1.point_count { if manifold1.points[j].id == id { - state2[i] = B2pointState::B2PersistState; + *state = B2pointState::B2PersistState; break; } } @@ -164,7 +164,7 @@ pub fn b2_aabb_ray_cast(self_: B2AABB, output: &mut B2rayCastOutput, input: &B2r // Intersection. output.fraction = tmin; output.normal = normal; - return true; + true } // Sutherland-Hodgman clipping. @@ -200,9 +200,9 @@ pub fn b2_clip_segment_to_line( // VertexA is hitting edgeB. v_out[count].id.cf.index_a = vertex_index_a as u8; - + v_out[count].id.cf.index_b = v_in[0].id.cf.index_b; - + v_out[count].id.cf.type_a = B2contactFeatureType::EVertex as u8; v_out[count].id.cf.type_b = B2contactFeatureType::EFace as u8; count += 1; @@ -210,7 +210,7 @@ pub fn b2_clip_segment_to_line( b2_assert(count == 2); } - return count; + count } pub fn b2_test_overlap( @@ -232,12 +232,14 @@ pub fn b2_test_overlap( input.proxy_a.set_shape(shape_a,index_a); input.proxy_b.set_shape(shape_b, index_b); - let mut cache = B2simplexCache::default(); - cache.count = 0; + let mut cache = B2simplexCache { + count: 0, + ..Default::default() + }; let mut output = B2distanceOutput::default(); b2_distance_fn(&mut output, &mut cache, &input); - return output.distance < 10.0 * B2_EPSILON; + output.distance < 10.0 * B2_EPSILON } diff --git a/src/private/collision/b2_distance.rs b/src/private/collision/b2_distance.rs index 617aa15..736b6a7 100644 --- a/src/private/collision/b2_distance.rs +++ b/src/private/collision/b2_distance.rs @@ -135,7 +135,7 @@ impl B2simplex { fn get_search_direction(&self) -> B2vec2 { match self.m_count { 1 => { - return -self.m_v[0].w; + -self.m_v[0].w } 2 => { @@ -143,16 +143,16 @@ impl B2simplex { let sgn: f32 = b2_cross(e12, -self.m_v[0].w); if sgn > 0.0 { // Origin is left of e12. - return b2_cross_scalar_by_vec(1.0, e12); + b2_cross_scalar_by_vec(1.0, e12) } else { // Origin is right of e12. - return b2_cross_vec_by_scalar(e12, 1.0); + b2_cross_vec_by_scalar(e12, 1.0) } } _ => { b2_assert(false); - return B2vec2::zero(); + B2vec2::zero() } } } @@ -161,23 +161,23 @@ impl B2simplex { match self.m_count { 0 => { b2_assert(false); - return B2vec2::zero(); + B2vec2::zero() } 1 => { - return self.m_v[0].w; + self.m_v[0].w } 2 => { - return self.m_v[0].a * self.m_v[0].w + self.m_v[1].a * self.m_v[1].w; + self.m_v[0].a * self.m_v[0].w + self.m_v[1].a * self.m_v[1].w } 3 => { - return B2vec2::zero(); + B2vec2::zero() } _ => { b2_assert(false); - return B2vec2::zero(); + B2vec2::zero() } } } @@ -215,20 +215,20 @@ impl B2simplex { match self.m_count { 0 => { b2_assert(false); - return 0.0; + 0.0 } 1 => { - return 0.0; + 0.0 } 2 => { - return b2_distance_vec2(self.m_v[0].w, self.m_v[1].w); + b2_distance_vec2(self.m_v[0].w, self.m_v[1].w) } 3 => { - return b2_cross(self.m_v[1].w - self.m_v[0].w, self.m_v[2].w - self.m_v[0].w); + b2_cross(self.m_v[1].w - self.m_v[0].w, self.m_v[2].w - self.m_v[0].w) } _ => { b2_assert(false); - return 0.0; + 0.0 } } } @@ -415,7 +415,10 @@ pub fn b2_distance_fn( let transform_b: B2Transform = input.transform_b; // initialize the simplex. - let mut simplex = B2simplex::default(); + let mut simplex = B2simplex { + m_count: 0, + ..Default::default() + }; simplex.read_cache(cache, proxy_a, transform_a, proxy_b, transform_b); // Get simplex vertices as an array. @@ -499,7 +502,7 @@ pub fn b2_distance_fn( // New vertex is ok and needed. simplex.m_count += 1; } - + B2_GJK_MAX_ITERS.fetch_max(iter, Ordering::SeqCst); // Prepare output. @@ -559,7 +562,6 @@ pub fn b2_shape_cast(output: &mut B2shapeCastOutput, input: B2shapeCastInput) -> // Initial simplex let mut simplex = B2simplex::default(); - simplex.m_count = 0; // Get simplex vertices as an array. //b2SimplexVertex* vertices = &simplex.m_v[0]; @@ -669,5 +671,5 @@ pub fn b2_shape_cast(output: &mut B2shapeCastOutput, input: B2shapeCastInput) -> output.normal = n; output.lambda = lambda; output.iterations = iter; - return true; + true } diff --git a/src/private/collision/b2_dynamic_tree.rs b/src/private/collision/b2_dynamic_tree.rs index 55619a4..45beee4 100644 --- a/src/private/collision/b2_dynamic_tree.rs +++ b/src/private/collision/b2_dynamic_tree.rs @@ -14,20 +14,20 @@ pub fn b2_dynamic_tree() -> B2dynamicTree { // Build a linked list for the free list. for i in 0..m_node_capacity - 1 { - m_nodes[i as usize].parent = (i + 1) as i32;//parent is next free node + m_nodes[i as usize].parent = i + 1;//parent is next free node m_nodes[i as usize].height = -1; } m_nodes[(m_node_capacity - 1) as usize].parent = B2_NULL_NODE; m_nodes[(m_node_capacity - 1) as usize].height = -1; - return B2dynamicTree:: { + B2dynamicTree:: { m_root, m_node_capacity, m_node_count, m_nodes, m_free_list: 0, m_insertion_count: 0, - }; + } } // Allocate a node from the pool. Grow the pool if necessary. @@ -62,7 +62,7 @@ pub fn allocate_node(self_: &mut B2dynamicTree) -> i32 { self_.m_nodes[node_id].user_data = None; self_.m_nodes[node_id].moved = false; self_.m_node_count += 1; - return node_id.try_into().unwrap(); + node_id.try_into().unwrap() } // Return a node to the pool. @@ -95,7 +95,7 @@ pub fn create_proxy( insert_leaf(self_, proxy_id); - return proxy_id; + proxy_id } pub fn destroy_proxy(self_: &mut B2dynamicTree, proxy_id: i32) { @@ -164,7 +164,7 @@ pub fn move_proxy( self_.m_nodes[proxy_id as usize].moved = true; - return true; + true } pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) { @@ -172,14 +172,14 @@ pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) if self_.m_root == B2_NULL_NODE { self_.m_root = leaf; - self_.m_nodes[self_.m_root as usize].parent = B2_NULL_NODE; + self_.m_nodes[self_.m_root as usize].parent = B2_NULL_NODE; return; } // Find the best sibling for this node let leaf_aabb: B2AABB = self_.m_nodes[leaf as usize].aabb; let mut index: i32 = self_.m_root; - while self_.m_nodes[index as usize].is_leaf() == false { + while !self_.m_nodes[index as usize].is_leaf() { let child1: i32 = self_.m_nodes[index as usize].child1; let child2: i32 = self_.m_nodes[index as usize].child2; @@ -196,32 +196,30 @@ pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) let inheritance_cost: f32 = 2.0 * (combined_area - area); // Cost of descending into child1 - let cost1: f32; - if self_.m_nodes[child1 as usize].is_leaf() { + let cost1: f32 = if self_.m_nodes[child1 as usize].is_leaf() { let mut aabb = B2AABB::default(); aabb.combine_two(leaf_aabb, self_.m_nodes[child1 as usize].aabb); - cost1 = aabb.get_perimeter() + inheritance_cost; + aabb.get_perimeter() + inheritance_cost } else { let mut aabb = B2AABB::default(); aabb.combine_two(leaf_aabb, self_.m_nodes[child1 as usize].aabb); let old_area: f32 = self_.m_nodes[child1 as usize].aabb.get_perimeter(); let new_area: f32 = aabb.get_perimeter(); - cost1 = (new_area - old_area) + inheritance_cost; - } + (new_area - old_area) + inheritance_cost + }; // Cost of descending into child2 - let cost2: f32; - if self_.m_nodes[child2 as usize].is_leaf() { + let cost2: f32 = if self_.m_nodes[child2 as usize].is_leaf() { let mut aabb = B2AABB::default(); aabb.combine_two(leaf_aabb, self_.m_nodes[child2 as usize].aabb); - cost2 = aabb.get_perimeter() + inheritance_cost; + aabb.get_perimeter() + inheritance_cost } else { let mut aabb = B2AABB::default(); aabb.combine_two(leaf_aabb, self_.m_nodes[child2 as usize].aabb); let old_area: f32 = self_.m_nodes[child2 as usize].aabb.get_perimeter(); let new_area: f32 = aabb.get_perimeter(); - cost2 = new_area - old_area + inheritance_cost; - } + new_area - old_area + inheritance_cost + }; // Descend according to the minimum cost. if cost < cost1 && cost < cost2 { @@ -239,9 +237,9 @@ pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) let sibling: i32 = index; // create a new parent. - let old_parent: i32 = self_.m_nodes[sibling as usize].parent; + let old_parent: i32 = self_.m_nodes[sibling as usize].parent; let new_parent: i32 = self_.allocate_node(); - self_.m_nodes[new_parent as usize].parent = old_parent; + self_.m_nodes[new_parent as usize].parent = old_parent; self_.m_nodes[new_parent as usize].user_data = None; let temp_aabb = self_.m_nodes[sibling as usize].aabb; self_.m_nodes[new_parent as usize] @@ -259,19 +257,19 @@ pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) self_.m_nodes[new_parent as usize].child1 = sibling; self_.m_nodes[new_parent as usize].child2 = leaf; - self_.m_nodes[sibling as usize].parent = new_parent; - self_.m_nodes[leaf as usize].parent = new_parent; + self_.m_nodes[sibling as usize].parent = new_parent; + self_.m_nodes[leaf as usize].parent = new_parent; } else { // The sibling was the root. self_.m_nodes[new_parent as usize].child1 = sibling; self_.m_nodes[new_parent as usize].child2 = leaf; - self_.m_nodes[sibling as usize].parent = new_parent; - self_.m_nodes[leaf as usize].parent = new_parent; + self_.m_nodes[sibling as usize].parent = new_parent; + self_.m_nodes[leaf as usize].parent = new_parent; self_.m_root = new_parent; } // Walk back up the tree fixing heights and AABBs - index = self_.m_nodes[leaf as usize].parent; + index = self_.m_nodes[leaf as usize].parent; while index != B2_NULL_NODE { index = self_.balance(index); @@ -291,7 +289,7 @@ pub fn insert_leaf(self_: &mut B2dynamicTree, leaf: i32) .aabb .combine_two(temp_aabb1, temp_aabb2); - index = self_.m_nodes[index as usize].parent; + index = self_.m_nodes[index as usize].parent; } //validate(); @@ -303,14 +301,13 @@ pub fn remove_leaf(self_: &mut B2dynamicTree, leaf: i32) return; } - let parent: i32 = self_.m_nodes[leaf as usize].parent; - let grand_parent: i32 = self_.m_nodes[parent as usize].parent; - let sibling: i32; - if self_.m_nodes[parent as usize].child1 == leaf { - sibling = self_.m_nodes[parent as usize].child2; + let parent: i32 = self_.m_nodes[leaf as usize].parent; + let grand_parent: i32 = self_.m_nodes[parent as usize].parent; + let sibling: i32 = if self_.m_nodes[parent as usize].child1 == leaf { + self_.m_nodes[parent as usize].child2 } else { - sibling = self_.m_nodes[parent as usize].child1; - } + self_.m_nodes[parent as usize].child1 + }; if grand_parent != B2_NULL_NODE { // destroy parent and connect sibling to grandParent. @@ -319,7 +316,7 @@ pub fn remove_leaf(self_: &mut B2dynamicTree, leaf: i32) } else { self_.m_nodes[grand_parent as usize].child2 = sibling; } - self_.m_nodes[sibling as usize].parent = grand_parent; + self_.m_nodes[sibling as usize].parent = grand_parent; self_.free_node(parent); // Adjust ancestor bounds. @@ -341,11 +338,11 @@ pub fn remove_leaf(self_: &mut B2dynamicTree, leaf: i32) self_.m_nodes[child2 as usize].height, ); - index = self_.m_nodes[index as usize].parent; + index = self_.m_nodes[index as usize].parent; } } else { self_.m_root = sibling; - self_.m_nodes[sibling as usize].parent = B2_NULL_NODE; + self_.m_nodes[sibling as usize].parent = B2_NULL_NODE; self_.free_node(parent); } @@ -372,7 +369,7 @@ pub fn balance(self_: &mut B2dynamicTree, i_a: i32) -> i3 let balance: i32 = c.height - b.height; - + // Rotate c up if balance > 1 { @@ -485,7 +482,7 @@ pub fn balance(self_: &mut B2dynamicTree, i_a: i32) -> i3 return i_b; } - return i_a; + i_a } pub fn get_height(self_: &B2dynamicTree) -> i32 { @@ -493,7 +490,7 @@ pub fn get_height(self_: &B2dynamicTree) -> i32 { return 0; } - return self_.m_nodes[self_.m_root as usize].height; + self_.m_nodes[self_.m_root as usize].height } // @@ -516,7 +513,7 @@ pub fn get_area_ratio(self_: &B2dynamicTree) -> f32 { total_area += node.aabb.get_perimeter(); } - return total_area / root_area; + total_area / root_area } // Compute the height of a sub-tree. @@ -533,12 +530,12 @@ pub fn compute_height_by_node( let height1: i32 = self_.compute_height_by_node(node.child1); let height2: i32 = self_.compute_height_by_node(node.child2); - return 1 + b2_max(height1, height2); + 1 + b2_max(height1, height2) } pub fn compute_height(self_: &B2dynamicTree) -> i32 { let height: i32 = compute_height_by_node(self_, self_.m_root); - return height; + height } pub fn validate_structure(self_: &B2dynamicTree, index: i32) { @@ -546,7 +543,7 @@ pub fn validate_structure(self_: &B2dynamicTree, index: i return; } - + if index == self_.m_root { b2_assert(self_.m_nodes[index as usize].parent == B2_NULL_NODE); @@ -596,8 +593,7 @@ pub fn validate_metrics(self_: &B2dynamicTree, index: i32 let height1: i32 = self_.m_nodes[child1 as usize].height; let height2: i32 = self_.m_nodes[child2 as usize].height; - let height: i32; - height = 1 + b2_max(height1, height2); + let height: i32 = 1 + b2_max(height1, height2); b2_assert(node.height == height); let mut aabb = B2AABB::default(); @@ -641,7 +637,7 @@ pub fn get_max_balance(self_: &B2dynamicTree) -> i32 { continue; } - b2_assert(node.is_leaf() == false); + b2_assert(!node.is_leaf()); let child1: i32 = node.child1; let child2: i32 = node.child2; @@ -650,7 +646,7 @@ pub fn get_max_balance(self_: &B2dynamicTree) -> i32 { max_balance = b2_max(max_balance, balance); } - return max_balance; + max_balance } pub fn rebuild_bottom_up(self_: &mut B2dynamicTree) { diff --git a/src/private/collision/b2_edge_shape.rs b/src/private/collision/b2_edge_shape.rs index d8ab2da..08382eb 100644 --- a/src/private/collision/b2_edge_shape.rs +++ b/src/private/collision/b2_edge_shape.rs @@ -19,17 +19,17 @@ pub fn b2_set_two_sided(self_: &mut B2edgeShape, v1: B2vec2, v2: B2vec2) { } pub fn b2_shape_dyn_trait_clone(self_: &B2edgeShape) -> Box { - return Box::new(B2edgeShape::clone(&self_)); + Box::new(B2edgeShape::clone(self_)) } pub fn b2_shape_dyn_trait_get_child_count(_self: &B2edgeShape) -> usize { - return 1; + 1 } pub fn b2_shape_dyn_trait_test_point(_self: &B2edgeShape, xf: B2Transform, p: B2vec2) -> bool { b2_not_used(xf); b2_not_used(p); - return false; + false } // p = p1 + t * d @@ -88,7 +88,7 @@ pub fn b2_shape_dyn_trait_ray_cast( } let s: f32 = b2_dot(q - v1, r) / rr; - if s < 0.0 || 1.0 < s { + if !(0.0..=1.0).contains(&s) { return false; } @@ -98,7 +98,7 @@ pub fn b2_shape_dyn_trait_ray_cast( } else { output.normal = b2_mul_rot_by_vec2(xf.q, normal); } - return true; + true } pub fn b2_shape_dyn_trait_compute_aabb( diff --git a/src/private/collision/b2_polygon_shape.rs b/src/private/collision/b2_polygon_shape.rs index 5b28678..c84e00e 100644 --- a/src/private/collision/b2_polygon_shape.rs +++ b/src/private/collision/b2_polygon_shape.rs @@ -6,7 +6,7 @@ use crate::b2_settings::*; use crate::b2_shape::*; pub fn b2_shape_dyn_trait_clone(self_: &B2polygonShape) -> Box { - return Box::new(B2polygonShape::clone(&self_)); + Box::new(B2polygonShape::clone(self_)) } pub fn b2_polygon_shape_set_as_box(self_: &mut B2polygonShape, hx: f32, hy: f32) { @@ -53,7 +53,7 @@ pub fn b2_polygon_shape_set_as_box_angle( } pub fn b2_shape_dyn_trait_get_child_count(_self: &B2polygonShape) -> usize { - return 1; + 1 } fn compute_centroid(vs: &[B2vec2]) -> B2vec2 { @@ -90,12 +90,12 @@ fn compute_centroid(vs: &[B2vec2]) -> B2vec2 { // Centroid b2_assert(area > B2_EPSILON); c = (1.0 / area)*c+s; - return c; + c } pub fn b2_polygon_shape_set(self_: &mut B2polygonShape, vertices: &[B2vec2]) { let count = vertices.len(); - b2_assert(3 <= count && count <= B2_MAX_POLYGON_VERTICES); + b2_assert((3..=B2_MAX_POLYGON_VERTICES).contains(&count)); if count < 3 { b2_polygon_shape_set_as_box(self_, 1.0, 1.0); return; @@ -105,12 +105,11 @@ pub fn b2_polygon_shape_set(self_: &mut B2polygonShape, vertices: &[B2vec2]) { // Perform welding and copy vertices into local buffer. let mut ps = <[B2vec2; B2_MAX_POLYGON_VERTICES]>::default(); let mut temp_count: usize = 0; - for i in 0..n { - let v: B2vec2 = vertices[i]; + for v in vertices.iter().take(n).copied() { let mut unique: bool = true; - for j in 0..temp_count { - if b2_distance_vec2_squared(v, ps[j as usize]) + for p in ps.iter().take(temp_count) { + if b2_distance_vec2_squared(v, *p) < ((0.5 * B2_LINEAR_SLOP) * (0.5 * B2_LINEAR_SLOP)) { unique = false; @@ -220,7 +219,7 @@ pub fn b2_shape_dyn_trait_test_point(self_: &B2polygonShape, xf: B2Transform, p: } } - return true; + true } pub fn b2_shape_dyn_trait_ray_cast( @@ -286,7 +285,7 @@ pub fn b2_shape_dyn_trait_ray_cast( return true; } - return false; + false } pub fn b2_shape_dyn_trait_compute_aabb( @@ -409,5 +408,5 @@ pub fn b2_polygon_shape_validate(self_: B2polygonShape) -> bool { } } - return true; + true } diff --git a/src/private/collision/b2_time_of_impact.rs b/src/private/collision/b2_time_of_impact.rs index be5bbad..984fe54 100644 --- a/src/private/collision/b2_time_of_impact.rs +++ b/src/private/collision/b2_time_of_impact.rs @@ -62,7 +62,7 @@ impl<'a> B2separationFunction<'a> { result.m_axis = point_b - point_a; let s: f32 = result.m_axis.normalize(); *separation = s; - return result; + result } else if cache.index_a[0] == cache.index_a[1] { // Two points on b and one on A. result.m_type = B2separationFunctionType::EFaceB; @@ -85,7 +85,7 @@ impl<'a> B2separationFunction<'a> { s = -s; } *separation = s; - return result; + result } else { // Two points on A and one or two points on b. result.m_type = B2separationFunctionType::EFaceA; @@ -107,7 +107,7 @@ impl<'a> B2separationFunction<'a> { s = -s; } *separation = s; - return result; + result } } @@ -133,7 +133,7 @@ impl<'a> B2separationFunction<'a> { let point_b: B2vec2 = b2_mul_transform_by_vec2(xf_b, local_point_b); let separation: f32 = b2_dot(point_b - point_a, self.m_axis); - return separation; + separation } B2separationFunctionType::EFaceA => { @@ -148,7 +148,7 @@ impl<'a> B2separationFunction<'a> { let point_b: B2vec2 = b2_mul_transform_by_vec2(xf_b, local_point_b); let separation: f32 = b2_dot(point_b - point_a, normal); - return separation; + separation } B2separationFunctionType::EFaceB => { @@ -164,7 +164,7 @@ impl<'a> B2separationFunction<'a> { let point_a: B2vec2 = b2_mul_transform_by_vec2(xf_a, local_point_a); let separation: f32 = b2_dot(point_a - point_b, normal); - return separation; + separation } //unreachable @@ -193,7 +193,7 @@ impl<'a> B2separationFunction<'a> { let point_b: B2vec2 = b2_mul_transform_by_vec2(xf_b, local_point_b); let separation: f32 = b2_dot(point_b - point_a, self.m_axis); - return separation; + separation } B2separationFunctionType::EFaceA => { @@ -204,7 +204,7 @@ impl<'a> B2separationFunction<'a> { let point_b: B2vec2 = b2_mul_transform_by_vec2(xf_b, local_point_b); let separation: f32 = b2_dot(point_b - point_a, normal); - return separation; + separation } B2separationFunctionType::EFaceB => { @@ -215,7 +215,7 @@ impl<'a> B2separationFunction<'a> { let point_a: B2vec2 = b2_mul_transform_by_vec2(xf_a, local_point_a); let separation: f32 = b2_dot(point_a - point_b, normal); - return separation; + separation } //unreachable @@ -260,14 +260,17 @@ pub fn b2_time_of_impact(output: &mut B2toioutput, input: &B2toiinput) { let mut iter: i32 = 0; // Prepare input for distance query. - let mut cache = B2simplexCache::default(); - cache.count = 0; - let mut distance_input = B2distanceInput::default(); - + let mut cache = B2simplexCache { + count: 0, + ..Default::default() + }; //box2d-rs: because of borrowing and lifetime problems - distance_input.proxy_a = input.proxy_a.clone(); - distance_input.proxy_b = input.proxy_b.clone(); - distance_input.use_radii = false; + let mut distance_input = B2distanceInput { + proxy_a: input.proxy_a.clone(), + proxy_b: input.proxy_b.clone(), + use_radii: false, + ..Default::default() + }; // The outer loop progressively attempts to compute new separating axes. // This loop terminates when an axis is repeated (no progress is made). @@ -391,19 +394,18 @@ pub fn b2_time_of_impact(output: &mut B2toioutput, input: &B2toiinput) { let mut a2: f32 = t2; loop { // Use a mix of the secant rule and bisection. - let t: f32; - if (root_iter_count & 1) == 1 { + let t: f32 = if (root_iter_count & 1) == 1 { // Secant rule to improve convergence. - t = a1 + (target - s1) * (a2 - a1) / (s2 - s1); + a1 + (target - s1) * (a2 - a1) / (s2 - s1) } else { // Bisection to guarantee progress. - t = 0.5 * (a1 + a2); - } + 0.5 * (a1 + a2) + }; root_iter_count += 1; - + B2_TOI_ROOT_ITERS.fetch_add(1, Ordering::SeqCst); - + let s: f32 = fcn.evaluate(index_a, index_b, t); @@ -426,7 +428,7 @@ pub fn b2_time_of_impact(output: &mut B2toioutput, input: &B2toiinput) { break; } } - + B2_TOI_MAX_ROOT_ITERS.fetch_max(root_iter_count as usize, Ordering::SeqCst); push_back_iter += 1; @@ -453,11 +455,11 @@ pub fn b2_time_of_impact(output: &mut B2toioutput, input: &B2toiinput) { } B2_TOI_MAX_ITERS.fetch_max(iter as usize, Ordering::SeqCst); - + let time = timer.precise_time_ns(); B2_TOI_MAX_TIME.fetch_max(time, Ordering::SeqCst); B2_TOI_TIME.fetch_add(time, Ordering::SeqCst); - + } diff --git a/src/private/common/b2_math.rs b/src/private/common/b2_math.rs index 485baee..65a5032 100644 --- a/src/private/common/b2_math.rs +++ b/src/private/common/b2_math.rs @@ -7,12 +7,12 @@ pub fn solve33(self_: B2Mat33, b: B2Vec3) -> B2Vec3 { if det != 0.0 { det = 1.0 / det; } - let x = B2Vec3 { + + B2Vec3 { x: det * b2_dot_vec3(b, b2_cross_vec3(self_.ey, self_.ez)), y: det * b2_dot_vec3(self_.ex, b2_cross_vec3(b, self_.ez)), z: det * b2_dot_vec3(self_.ex, b2_cross_vec3(self_.ey, b)), - }; - return x; + } } /// solve A * x = b, where b is a column vector. This is more efficient /// than computing the inverse in one-shot cases. @@ -22,13 +22,12 @@ pub fn solve22(self_: B2Mat33, b: B2vec2) -> B2vec2 { if det != 0.0 { det = 1.0 / det; } - let x = B2vec2 { + + B2vec2 { x: det * (a22 * b.x - a12 * b.y), y: det * (a11 * b.y - a21 * b.x), - }; - return x; + } } -/// pub fn get_inverse22(self_: B2Mat33, m: &mut B2Mat33) { let (a, b, c, d) = (self_.ex.x, self_.ey.x, self_.ex.y, self_.ey.y); let mut det: f32 = a * d - b * c; diff --git a/src/private/dynamics/b2_body.rs b/src/private/dynamics/b2_body.rs index 27ea53b..71983d7 100644 --- a/src/private/dynamics/b2_body.rs +++ b/src/private/dynamics/b2_body.rs @@ -40,10 +40,10 @@ pub fn b2_body(bd: &B2bodyDef, world: B2worldPtr) -> B2bo let m_xf = B2Transform::new(bd.position, B2Rot::new(bd.angle)); - return B2body:: { + B2body:: { m_world: Rc::downgrade(&world), - m_xf: m_xf, + m_xf, m_sweep: B2Sweep { local_center: B2vec2::zero(), @@ -83,9 +83,9 @@ pub fn b2_body(bd: &B2bodyDef, world: B2worldPtr) -> B2bo m_fixture_list: LinkedList::default(), m_fixture_count: 0, - m_flags: m_flags, + m_flags, m_island_index: -1, - }; + } } pub fn set_type(self_: BodyPtr, body_type: B2bodyType) { @@ -94,8 +94,8 @@ pub fn set_type(self_: BodyPtr, body_type: B2bodyType) { { let mut self_ = self_.borrow_mut(); world = upgrade(&self_.m_world); - b2_assert(world.borrow().is_locked() == false); - if world.borrow().is_locked() == true { + b2_assert(!world.borrow().is_locked()); + if world.borrow().is_locked() { return; } @@ -155,8 +155,8 @@ pub fn set_type(self_: BodyPtr, body_type: B2bodyType) { pub fn create_fixture(self_: BodyPtr, def: &B2fixtureDef) -> FixturePtr { let mut self_mut = self_.borrow_mut(); let world = upgrade(&self_mut.m_world); - b2_assert(world.borrow().is_locked() == false); - if world.borrow().is_locked() == true { + b2_assert(!world.borrow().is_locked()); + if world.borrow().is_locked() { panic!(); } @@ -196,7 +196,7 @@ pub fn create_fixture(self_: BodyPtr, def: &B2fixtureDef) // to be created at the beginning of the next time step. world.borrow_mut().m_new_contacts = true; - return fixture; + fixture } pub fn create_fixture_by_shape( @@ -204,11 +204,13 @@ pub fn create_fixture_by_shape( shape: ShapeDefPtr, density: f32, ) -> FixturePtr { - let mut def = B2fixtureDef::default(); - def.shape = Some(shape); - def.density = density; + let def = B2fixtureDef { + shape: Some(shape), + density, + ..Default::default() + }; - return create_fixture(self_, &def); + create_fixture(self_, &def) } pub fn destroy_fixture(self_: BodyPtr, fixture: FixturePtr) { @@ -222,8 +224,8 @@ pub fn destroy_fixture(self_: BodyPtr, fixture: FixturePtr(self_: &mut B2body) { pub fn set_mass_data(self_: &mut B2body, mass_data: &B2massData) { let world = upgrade(&self_.m_world); - b2_assert(world.borrow().is_locked() == false); - if world.borrow().is_locked() == true { + b2_assert(!world.borrow().is_locked()); + if world.borrow().is_locked() { return; } @@ -400,25 +402,23 @@ pub fn should_collide(self_: &B2body, other: BodyPtr) -> for jn_ in self_.m_joint_list.iter() { let jn = jn_.borrow(); let jn_other = upgrade(&jn.other); - if Rc::ptr_eq(&jn_other, &other) { - if upgrade(&jn.joint) + if Rc::ptr_eq(&jn_other, &other) + && !upgrade(&jn.joint) .borrow() .get_base() .get_collide_connected() - == false { return false; } - } } - return true; + true } pub fn set_transform(self_: &mut B2body, position: B2vec2, angle: f32) { let world = upgrade(&self_.m_world); - b2_assert(world.borrow().is_locked() == false); - if world.borrow().is_locked() == true { + b2_assert(!world.borrow().is_locked()); + if world.borrow().is_locked() { return; } @@ -488,8 +488,8 @@ pub fn set_enabled(self_: BodyPtr, flag: bool) { let contact_manager = world.borrow().m_contact_manager.clone(); broad_phase_rc = contact_manager.borrow().m_broad_phase.clone(); broad_phase = broad_phase_rc.borrow_mut(); - b2_assert(world.borrow().is_locked() == false); - if world.borrow().is_locked() == true { + b2_assert(!world.borrow().is_locked()); + if world.borrow().is_locked() { return; } diff --git a/src/private/dynamics/b2_contact.rs b/src/private/dynamics/b2_contact.rs index 2a52dc7..af5cefd 100644 --- a/src/private/dynamics/b2_contact.rs +++ b/src/private/dynamics/b2_contact.rs @@ -24,9 +24,9 @@ pub fn b2_contact_create( let create_fcn = s_register.create_fcn.unwrap(); if s_register.primary { - return create_fcn(fixture_a, index_a, fixture_b, index_b); + create_fcn(fixture_a, index_a, fixture_b, index_b) } else { - return create_fcn(fixture_b, index_b, fixture_a, index_a); + create_fcn(fixture_b, index_b, fixture_a, index_a) } } @@ -37,8 +37,8 @@ pub fn b2_contact_destroy(self_: &dyn B2contactDynTrait) { let fixture_b = contact_base.m_fixture_b.borrow(); if contact_base.m_manifold.point_count > 0 - && fixture_a.is_sensor() == false - && fixture_b.is_sensor() == false + && !fixture_a.is_sensor() + && !fixture_b.is_sensor() { fixture_a.get_body().borrow_mut().set_awake(true); fixture_b.get_body().borrow_mut().set_awake(true); @@ -203,15 +203,15 @@ pub fn b2_contact_update( let mut contact_listener = contact_listener.borrow_mut(); - if was_touching == false && touching == true { + if !was_touching && touching { contact_listener.begin_contact(self_); } - if was_touching == true && touching == false { + if was_touching && !touching { contact_listener.end_contact(self_); } - if sensor == false && touching { + if !sensor && touching { contact_listener.pre_solve(self_, &old_manifold); } } diff --git a/src/private/dynamics/b2_contact_manager.rs b/src/private/dynamics/b2_contact_manager.rs index d9485ef..a2d5288 100644 --- a/src/private/dynamics/b2_contact_manager.rs +++ b/src/private/dynamics/b2_contact_manager.rs @@ -104,17 +104,16 @@ pub fn b2_contact_manager_collide(self_: B2contactManagerPtr .contains(ContactFlags::E_FILTER_FLAG) { // Should these bodies collide? - if body_b.borrow().should_collide(body_a.clone()) == false { + if !body_b.borrow().should_collide(body_a.clone()) { contacts_to_destroy.push(c); continue; } // Check user filtering. if let Some(m_contact_filter) = m_contact_filter.clone() { - if m_contact_filter + if !m_contact_filter .borrow() .should_collide(fixture_a.clone(), fixture_b.clone()) - == false { contacts_to_destroy.push(c); continue; @@ -134,7 +133,7 @@ pub fn b2_contact_manager_collide(self_: B2contactManagerPtr body_b.borrow().is_awake() && body_b.borrow().m_type != B2bodyType::B2StaticBody; // At least one body must be awake and it must be dynamic or kinematic. - if active_a == false && active_b == false { + if !active_a && !active_b { continue; } @@ -149,7 +148,7 @@ pub fn b2_contact_manager_collide(self_: B2contactManagerPtr .test_overlap(proxy_id_a, proxy_id_b); // Here we destroy contacts that cease to overlap in the broad-phase. - if overlap == false { + if !overlap { contacts_to_destroy.push(c); continue; } @@ -161,7 +160,7 @@ pub fn b2_contact_manager_collide(self_: B2contactManagerPtr ); } - if contacts_to_destroy.len()>0 + if !contacts_to_destroy.is_empty() { let mut self_ = self_.borrow_mut(); for c in contacts_to_destroy { @@ -235,19 +234,18 @@ pub fn b2_contact_manager_add_pair( } // Does a joint override collision? Is at least one body dynamic? - if body_b.borrow().should_collide(body_a) == false { + if !body_b.borrow().should_collide(body_a) { return; } // Check user filtering. if self_.m_contact_filter.is_some() - && self_ + && !self_ .m_contact_filter .as_ref() .unwrap() .borrow() .should_collide(fixture_a.clone(), fixture_b.clone()) - == false { return; } diff --git a/src/private/dynamics/b2_contact_registers.rs b/src/private/dynamics/b2_contact_registers.rs index d5ee8a5..94f1ba3 100644 --- a/src/private/dynamics/b2_contact_registers.rs +++ b/src/private/dynamics/b2_contact_registers.rs @@ -36,7 +36,7 @@ impl Default for ContactRegisters { s_registers: [def_value(),def_value(),def_value(),def_value()] }; ContactRegisters::initialize_registers(&mut result); - return result; + result } } diff --git a/src/private/dynamics/b2_contact_solver.rs b/src/private/dynamics/b2_contact_solver.rs index f31b307..e7af5ee 100644 --- a/src/private/dynamics/b2_contact_solver.rs +++ b/src/private/dynamics/b2_contact_solver.rs @@ -55,7 +55,7 @@ impl B2contactSolver { pub fn new(def: &B2contactSolverDef, contacts: &Vec>)->Self{ - return private::new(def, contacts); + private::new(def, contacts) } pub fn initialize_velocity_constraints(&mut self, @@ -75,12 +75,12 @@ impl B2contactSolver pub fn solve_position_constraints(&mut self, m_positions: &mut [B2position]) -> bool { - return private::solve_position_constraints(self, m_positions); + private::solve_position_constraints(self, m_positions) } pub fn solve_toiposition_constraints(&mut self, toi_index_a: i32, toi_index_b: i32, m_positions: &mut [B2position]) -> bool { - return private::solve_toiposition_constraints(self, toi_index_a, toi_index_b, m_positions); + private::solve_toiposition_constraints(self, toi_index_a, toi_index_b, m_positions) } } diff --git a/src/private/dynamics/b2_contact_solver_private.rs b/src/private/dynamics/b2_contact_solver_private.rs index b37a60b..994d587 100644 --- a/src/private/dynamics/b2_contact_solver_private.rs +++ b/src/private/dynamics/b2_contact_solver_private.rs @@ -17,20 +17,20 @@ const B2_DEBUG_SOLVER: bool = false; //struct B2contactPositionConstraint //moved to header -pub(crate) fn new(def: &B2contactSolverDef, contacts: &Vec>) -> B2contactSolver +pub(crate) fn new(def: &B2contactSolverDef, contacts: &[ContactPtr]) -> B2contactSolver { let mut result = B2contactSolver::default(); let count = contacts.len(); - + result.m_position_constraints.resize(count,Default::default()); result.m_velocity_constraints.resize(count,Default::default()); result.m_step = def.step; // initialize position independent portions of the constraints. - for i in 0..count + for (i, contact_ptr) in contacts.iter().enumerate() { - let contact = contacts[i].borrow(); + let contact = contact_ptr.borrow(); let contact = contact.get_base(); let fixture_a = &contact.m_fixture_a; @@ -48,7 +48,7 @@ pub(crate) fn new(def: &B2contactSolverDef, contacts: &Vec 0); - let mut vc = &mut result.m_velocity_constraints[i]; + let vc = &mut result.m_velocity_constraints[i]; vc.friction = contact.m_friction; vc.restitution = contact.m_restitution; vc.threshold = contact.m_restitution_threshold; @@ -64,7 +64,7 @@ pub(crate) fn new(def: &B2contactSolverDef, contacts: &Vec(def: &B2contactSolverDef, contacts: &Vec(def: &B2contactSolverDef, contacts: &Vec(self_: &mut B2con let point_count: usize = vc.point_count as usize; for j in 0..point_count { - let mut vcp = &mut vc.points[j]; + let vcp = &mut vc.points[j]; vcp.r_a = world_manifold.points[j] - c_a; vcp.r_b = world_manifold.points[j] - c_b; @@ -294,7 +294,7 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti // than friction. for j in 0..point_count { - let mut vcp = &mut vc.points[j]; + let vcp = &mut vc.points[j]; // Relative velocity at contact let dv: B2vec2 =v_b + b2_cross_scalar_by_vec(w_b, vcp.r_b) - v_a - b2_cross_scalar_by_vec(w_a, vcp.r_a); @@ -308,7 +308,7 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti let new_impulse: f32 =b2_clamp(vcp.tangent_impulse + lambda, -max_friction, max_friction); lambda = new_impulse - vcp.tangent_impulse; vcp.tangent_impulse = new_impulse; - + // Apply contact impulse let p: B2vec2 =lambda * tangent; @@ -321,11 +321,11 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti // solve normal constraints let g_block_solve: bool = G_BLOCK_SOLVE.load(Ordering::SeqCst); - if point_count == 1 || g_block_solve == false + if point_count == 1 || !g_block_solve { for j in 0..point_count { - let mut vcp = &mut vc.points[j]; + let vcp = &mut vc.points[j]; // Relative velocity at contact let dv: B2vec2 =v_b + b2_cross_scalar_by_vec(w_b, vcp.r_b) - v_a - b2_cross_scalar_by_vec(w_a, vcp.r_a); @@ -362,17 +362,17 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti // implies that we must have in any solution either vn_i = 0 or x_i = 0. So for the 2D contact problem the cases // vn1 = 0 and vn2 = 0, x1 = 0 and x2 = 0, x1 = 0 and vn2 = 0, x2 = 0 and vn1 = 0 need to be tested. The first valid // solution that satisfies the problem is chosen. - // + // // In order to account of the accumulated impulse 'a' (because of the iterative nature of the solver which only requires // that the accumulated impulse is clamped and not the incremental impulse) we change the impulse variable (x_i). // // Substitute: - // + // // x = a + d - // + // // a := old total impulse // x := new total impulse - // d := incremental impulse + // d := incremental impulse // // For the current iteration we extend the formula for the incremental impulse // to compute the new total impulse: @@ -384,7 +384,7 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti // b' = b - A * a; let (cp1, tail) = vc.points.split_first_mut().unwrap(); - let mut cp2 = &mut tail[0]; + let cp2 = &mut tail[0]; let a = B2vec2::new(cp1.normal_impulse, cp2.normal_impulse); b2_assert(a.x >= 0.0 && a.y >= 0.0); @@ -408,6 +408,7 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti const K_ERROR_TOL: f32 = 1e-3; b2_not_used(K_ERROR_TOL); + #[allow(clippy::never_loop)] loop { // @@ -458,7 +459,7 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2contactSolver, m_velociti // // Case 2: vn1 = 0 and x2 = 0 // - // 0 = a11 * x1 + a12 * 0 + b1' + // 0 = a11 * x1 + a12 * 0 + b1' // vn2 = a21 * x1 + a22 * 0 + b2' // x.x = - cp1.normal_mass * b.x; @@ -500,7 +501,7 @@ if B2_DEBUG_SOLVER // // Case 3: vn2 = 0 and x1 = 0 // - // vn1 = a11 * 0 + a12 * x2 + b1' + // vn1 = a11 * 0 + a12 * x2 + b1' // 0 = a21 * 0 + a22 * x2 + b2' // x.x = 0.0; @@ -541,7 +542,7 @@ if B2_DEBUG_SOLVER // // Case 4: x1 = 0 and x2 = 0 - // + // // vn1 = b1 // vn2 = b2; x.x = 0.0; @@ -549,7 +550,7 @@ if B2_DEBUG_SOLVER vn1 = b.x; vn2 = b.y; - if vn1 >= 0.0 && vn2 >= 0.0 + if vn1 >= 0.0 && vn2 >= 0.0 { // Resubstitute for the incremental impulse let d: B2vec2 =x - a; @@ -587,7 +588,7 @@ pub(crate) fn store_impulses(self_: &mut B2contactSolver, m_cont for vc in &self_.m_velocity_constraints { let mut contact = m_contacts[vc.contact_index as usize].borrow_mut(); - let mut manifold = contact.get_base_mut().get_manifold_mut(); + let manifold = contact.get_base_mut().get_manifold_mut(); for j in 0..vc.point_count as usize { @@ -726,11 +727,11 @@ pub(crate) fn solve_position_constraints(self_: &mut B2contactSolver, m_positio // We can't expect minSpeparation >= -B2_LINEAR_SLOP because we don't // push the separation above -B2_LINEAR_SLOP. - return min_separation >= -3.0 * B2_LINEAR_SLOP; + min_separation >= -3.0 * B2_LINEAR_SLOP } // Sequential position solver for position constraints. -pub(crate) fn solve_toiposition_constraints(self_: &mut B2contactSolver, toi_index_a: i32, toi_index_b: i32, +pub(crate) fn solve_toiposition_constraints(self_: &mut B2contactSolver, toi_index_a: i32, toi_index_b: i32, m_positions: &mut [B2position]) -> bool { let mut min_separation: f32 =0.0; @@ -819,5 +820,5 @@ pub(crate) fn solve_toiposition_constraints(self_: &mut B2contactSolver, toi_ind // We can't expect minSpeparation >= -B2_LINEAR_SLOP because we don't // push the separation above -B2_LINEAR_SLOP. - return min_separation >= -1.5 * B2_LINEAR_SLOP; + min_separation >= -1.5 * B2_LINEAR_SLOP } diff --git a/src/private/dynamics/b2_fixture.rs b/src/private/dynamics/b2_fixture.rs index 6c118cf..9cf5b70 100644 --- a/src/private/dynamics/b2_fixture.rs +++ b/src/private/dynamics/b2_fixture.rs @@ -9,7 +9,7 @@ use crate::b2_common::*; use crate::b2rs_common::*; pub fn b2_fixture_default() -> B2fixture { - return B2fixture:: { + B2fixture:: { m_user_data: None, m_body: None, m_next: None, @@ -22,7 +22,7 @@ pub fn b2_fixture_default() -> B2fixture { m_is_sensor: false, m_restitution: 0.0, m_restitution_threshold: 0.0 - }; + } } pub fn b2_fixture_create( diff --git a/src/private/dynamics/b2_island.rs b/src/private/dynamics/b2_island.rs index 9a17a08..60fa273 100644 --- a/src/private/dynamics/b2_island.rs +++ b/src/private/dynamics/b2_island.rs @@ -21,7 +21,7 @@ impl B2island { let mut m_velocities = Vec::::new(); m_positions.resize(body_capacity, Default::default()); m_velocities.resize(body_capacity, Default::default()); - return Self + Self { m_listener: listener, m_bodies: Vec::with_capacity(body_capacity), diff --git a/src/private/dynamics/b2_island_private.rs b/src/private/dynamics/b2_island_private.rs index 774809f..d338b18 100644 --- a/src/private/dynamics/b2_island_private.rs +++ b/src/private/dynamics/b2_island_private.rs @@ -133,7 +133,7 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr let h: f32 = step.dt; // Integrate velocities and apply damping. initialize the body state. - for (i, b) in (&self_.m_bodies).iter().enumerate() + for (i, b) in self_.m_bodies.iter().enumerate() { let mut b = b.borrow_mut(); @@ -172,7 +172,7 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr timer.reset(); // Solver data - let mut solver_data = B2solverData{ + let solver_data = B2solverData{ step : *step, //positions : &mut self_.m_positions, //velocities : &mut self_.m_velocities, @@ -194,10 +194,10 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr { contact_solver.warm_start(&mut self_.m_velocities); } - + for j in &self_.m_joints { - j.borrow_mut().init_velocity_constraints(&mut solver_data, &mut self_.m_positions, &mut self_.m_velocities); + j.borrow_mut().init_velocity_constraints(&solver_data, &self_.m_positions, &mut self_.m_velocities); } profile.solve_init = timer.get_milliseconds(); @@ -208,7 +208,7 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr { for joint in &self_.m_joints { - joint.borrow_mut().solve_velocity_constraints(&mut solver_data, &mut self_.m_velocities); + joint.borrow_mut().solve_velocity_constraints(&solver_data, &mut self_.m_velocities); } contact_solver.solve_velocity_constraints(&mut self_.m_velocities); @@ -261,7 +261,7 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr let mut joints_okay: bool = true; for joint in &self_.m_joints { - let joint_okay: bool = joint.borrow_mut().solve_position_constraints(&mut solver_data, &mut self_.m_positions); + let joint_okay: bool = joint.borrow_mut().solve_position_constraints(&solver_data, &mut self_.m_positions); joints_okay = joints_okay && joint_okay; } @@ -274,7 +274,7 @@ pub(crate) fn solve(self_: &mut B2island, profile: &mut B2Pr } // Copy state buffers back to the bodies - for (i,body) in (&self_.m_bodies).iter().enumerate() + for (i,body) in self_.m_bodies.iter().enumerate() { let mut body = body.borrow_mut(); body.m_sweep.c = self_.m_positions[i].c; @@ -468,13 +468,15 @@ pub(crate) fn report(self_: &B2island, constraints: &[B2cont assert_eq!(self_.m_contacts.len(), constraints.len()); - for (i,c) in (&self_.m_contacts).iter().enumerate() + for (i,c) in self_.m_contacts.iter().enumerate() { let mut c = c.borrow_mut(); let vc = &constraints[i]; - - let mut impulse = B2contactImpulse::default(); - impulse.count = vc.point_count; + + let mut impulse = B2contactImpulse { + count: vc.point_count, + ..Default::default() + }; for j in 0..vc.point_count { diff --git a/src/private/dynamics/b2_joint.rs b/src/private/dynamics/b2_joint.rs index de1083f..c16a325 100644 --- a/src/private/dynamics/b2_joint.rs +++ b/src/private/dynamics/b2_joint.rs @@ -83,7 +83,7 @@ pub(crate) fn create(def: &B2JointDefEnum) -> B2jointPtr B2JointDefEnum::RevoluteJoint(ref def)=> Rc::new(RefCell::new(B2revoluteJoint::new(def))), B2JointDefEnum::PrismaticJoint(ref def)=> Rc::new(RefCell::new(B2prismaticJoint::new(def))), B2JointDefEnum::WeldJoint(ref def)=> Rc::new(RefCell::new(B2weldJoint::new(def))), - B2JointDefEnum::WheelJoint(ref def)=> Rc::new(RefCell::new(B2wheelJoint::new(def))), + B2JointDefEnum::WheelJoint(ref def)=> Rc::new(RefCell::new(B2wheelJoint::new(def))), } } @@ -91,14 +91,14 @@ pub(crate) fn new(def: &B2jointDef)-> B2joint { b2_assert(!Rc::ptr_eq(def.body_a.as_ref().unwrap(), def.body_b.as_ref().unwrap())); - return B2joint + B2joint { m_type : def.jtype, m_prev : None, m_next : None, m_body_a : def.body_a.clone().unwrap(), m_body_b : def.body_b.clone().unwrap(), - m_index : 0, + //m_index : 0, m_collide_connected : def.collide_connected, m_island_flag : false, m_user_data : def.user_data.clone(), @@ -125,17 +125,17 @@ pub(crate) fn draw+?Sized>(_self: &T, dr match _self.as_derived() { - JointAsDerived::EDistanceJoint(ref _def)=>{ + JointAsDerived::EDistanceJoint(_def)=>{ draw.draw_segment(p1, p2, color); }, - JointAsDerived::EPulleyJoint(ref pulley)=>{ + JointAsDerived::EPulleyJoint(pulley)=>{ let s1:B2vec2 = pulley.get_ground_anchor_a(); let s2:B2vec2 = pulley.get_ground_anchor_b(); draw.draw_segment(s1, p1, color); draw.draw_segment(s2, p2, color); draw.draw_segment(s1, s2, color); }, - JointAsDerived::EMouseJoint(ref _def)=>{ + JointAsDerived::EMouseJoint(_def)=>{ let c = B2color::new(0.0, 1.0, 0.0); draw.draw_point(p1, 4.0, c); draw.draw_point(p2, 4.0, c); diff --git a/src/private/dynamics/b2_world.rs b/src/private/dynamics/b2_world.rs index 87add4b..091647d 100644 --- a/src/private/dynamics/b2_world.rs +++ b/src/private/dynamics/b2_world.rs @@ -24,7 +24,7 @@ use std::cell::RefCell; use std::rc::Rc; pub(crate) fn b2_world_new(gravity: B2vec2) -> B2worldPtr { - return Rc::new(RefCell::new(B2world { + Rc::new(RefCell::new(B2world { m_destruction_listener: None, m_debug_draw: None, @@ -52,7 +52,7 @@ pub(crate) fn b2_world_new(gravity: B2vec2) -> B2worldPtr { m_contact_manager: Rc::new(RefCell::new(B2contactManager::new())), m_profile: Default::default(), - })); + })) } pub(crate) fn set_destruction_listener( @@ -81,7 +81,7 @@ pub(crate) fn set_debug_draw(self_: &mut B2world, debug_draw } pub(crate) fn create_body(self_: B2worldPtr, def: &B2bodyDef) -> BodyPtr { - b2_assert(self_.borrow().is_locked() == false); + b2_assert(!self_.borrow().is_locked()); if self_.borrow().is_locked() { panic!(); } @@ -94,17 +94,17 @@ pub(crate) fn create_body(self_: B2worldPtr, def: &B2bodyDef self_.m_body_count += 1; } - return b; + b } pub(crate) fn destroy_body(self_: &mut B2world, b: BodyPtr) { b2_assert(self_.m_body_count > 0); - b2_assert(self_.is_locked() == false); + b2_assert(!self_.is_locked()); if self_.is_locked() { panic!(); } - // Delete the attached joints. + // Delete the attached joints. let m_joint_list = b.borrow().m_joint_list.clone(); for je in m_joint_list.iter() { let joint = upgrade(&je.borrow().joint); @@ -157,7 +157,7 @@ pub(crate) fn create_joint( self_: &mut B2world, def: &B2JointDefEnum, ) -> B2jointPtr { - b2_assert(self_.is_locked() == false); + b2_assert(!self_.is_locked()); if self_.is_locked() { panic!(); } @@ -256,7 +256,7 @@ pub(crate) fn create_joint( }; // If the joint prevents collisions, then flag any contacts for filtering. - if collide_connected == false { + if !collide_connected { for edge_ in body_b.borrow().get_contact_list().iter() { let edge = edge_.borrow_mut(); if Rc::ptr_eq(&edge.other.upgrade().unwrap(), &body_a) { @@ -272,11 +272,11 @@ pub(crate) fn create_joint( // Note: creating a joint doesn't wake the bodies. - return j; + j } pub(crate) fn destroy_joint(self_: &mut B2world, j: B2jointPtr) { - b2_assert(self_.is_locked() == false); + b2_assert(!self_.is_locked()); if self_.is_locked() { panic!(); } @@ -323,7 +323,7 @@ pub(crate) fn destroy_joint(self_: &mut B2world, j: B2jointP self_.m_joint_count -= 1; // If the joint prevents collisions, then flag any contacts for filtering. - if collide_connected == false { + if !collide_connected { for edge in body_b.borrow().get_contact_list().iter() { let edge = edge.borrow(); if Rc::ptr_eq(&edge.other.upgrade().unwrap(), &body_a) { @@ -345,7 +345,7 @@ pub(crate) fn set_allow_sleeping(self_: &mut B2world, flag: } self_.m_allow_sleep = flag; - if self_.m_allow_sleep == false { + if !self_.m_allow_sleep { for b in self_.m_body_list.iter() { b.borrow_mut().set_awake(true); } @@ -364,7 +364,7 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { // Size the island for the worst case. island = B2island::new( self_.m_body_count, - contact_manager.m_contact_count as usize, + contact_manager.m_contact_count, self_.m_joint_count, contact_manager .m_contact_listener @@ -387,7 +387,7 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { } // Build and simulate all awake islands. - let mut stack = Vec::>::with_capacity(self_.m_body_count as usize); + let mut stack = Vec::>::with_capacity(self_.m_body_count); for seed in self_.m_body_list.iter() { { let seed = seed.borrow(); @@ -395,7 +395,7 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { continue; } - if seed.is_awake() == false || seed.is_enabled() == false { + if !seed.is_awake() || !seed.is_enabled() { continue; } @@ -414,7 +414,7 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { // Perform a depth first search (DFS) on the constraint graph. while let Some(b) = stack.pop() { // Grab the next body off the stack and add it to the island. - b2_assert(b.borrow().is_enabled() == true); + b2_assert(b.borrow().is_enabled()); island.add_body(b.clone()); // To keep islands as small as possible, we don't @@ -437,7 +437,7 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { } // Is this contact solid and touching? - if contact_base.is_enabled() == false || contact_base.is_touching() == false { + if !contact_base.is_enabled() || !contact_base.is_touching() { continue; } @@ -467,14 +467,14 @@ pub(crate) fn solve(self_: &mut B2world, step: B2timeStep) { for je in b.borrow().m_joint_list.iter() { let je = je.borrow(); let joint = upgrade(&je.joint); - if joint.borrow().get_base().m_island_flag == true { + if joint.borrow().get_base().m_island_flag { continue; } let other = upgrade(&je.other); // Don't simulate joints connected to disabled bodies. - if other.borrow().is_enabled() == false { + if !other.borrow().is_enabled() { continue; } @@ -568,9 +568,9 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte for c_ptr in self_.m_contact_manager.borrow().m_contact_list.iter() { let mut c = c_ptr.borrow_mut(); - let mut c_base = c.get_base_mut(); + let c_base = c.get_base_mut(); // Is this contact disabled? - if c_base.is_enabled() == false { + if !c_base.is_enabled() { continue; } @@ -609,7 +609,7 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte let active_b: bool = b_b.is_awake() && type_b != B2bodyType::B2StaticBody; // Is at least one body active (awake and dynamic or kinematic)? - if active_a == false && active_b == false { + if !active_a && !active_b { continue; } @@ -617,7 +617,7 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte let collide_b: bool = b_b.is_bullet() || type_b != B2bodyType::B2DynamicBody; // Are these two non-bullet dynamic bodies? - if collide_a == false && collide_b == false { + if !collide_a && !collide_b { continue; } @@ -709,8 +709,8 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte min_contact.borrow_mut().get_base_mut().m_toi_count += 1; // Is the contact solid? - if min_contact.borrow().get_base().is_enabled() == false - || min_contact.borrow().get_base().is_touching() == false + if !min_contact.borrow().get_base().is_enabled() + || !min_contact.borrow().get_base().is_touching() { // Restore the sweeps. min_contact.borrow_mut().get_base_mut().set_enabled(false); @@ -740,8 +740,8 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte // Get contacts on body_a and body_b. let bodies: [_; 2] = [b_a.clone(), b_b.clone()]; - for i in 0..2 { - let body = bodies[i].clone(); + for body in &bodies { + let body = body.clone(); if body.borrow().m_type == B2bodyType::B2DynamicBody { let contact_list = body.borrow().m_contact_list.clone(); for ce in contact_list.iter() { @@ -773,8 +773,8 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte { let mut other = other_ptr.borrow_mut(); if other.m_type == B2bodyType::B2DynamicBody - && body.borrow().is_bullet() == false - && other.is_bullet() == false + && !body.borrow().is_bullet() + && !other.is_bullet() { continue; } @@ -813,14 +813,14 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte let mut other = other_ptr.borrow_mut(); // Was the contact disabled by the user? - if contact_base.is_enabled() == false { + if !contact_base.is_enabled() { other.m_sweep = backup; other.synchronize_transform(); continue; } // Are there contact points? - if contact_base.is_touching() == false { + if !contact_base.is_touching() { other.m_sweep = backup; other.synchronize_transform(); continue; @@ -849,7 +849,7 @@ pub(crate) fn solve_toi(self_: &mut B2world, step: B2timeSte let dt = (1.0 - min_alpha) * step.dt; let sub_step = B2timeStep { - dt: dt, + dt, inv_dt: 1.0 / dt, dt_ratio: 1.0, position_iterations: 20, @@ -917,9 +917,9 @@ pub(crate) fn step( self_.m_locked = true; let step = B2timeStep { - dt: dt, - velocity_iterations: velocity_iterations, - position_iterations: position_iterations, + dt, + velocity_iterations, + position_iterations, inv_dt: if dt > 0.0 { 1.0 / dt } else { 0.0 }, dt_ratio: self_.m_inv_dt0 * dt, warm_starting: self_.m_warm_starting, @@ -1051,7 +1051,7 @@ pub(crate) fn ray_cast>( return callback(fixture, point, output.normal, fraction); } - return input.max_fraction; + input.max_fraction }, &input); } @@ -1078,7 +1078,7 @@ pub(crate) fn draw_shape( let v2: B2vec2 = b2_mul_transform_by_vec2(*xf, edge.m_vertex2); m_debug_draw.draw_segment(v1, v2, *color); - if edge.m_one_sided == false + if !edge.m_one_sided { m_debug_draw.draw_point(v1, 4.0, *color); m_debug_draw.draw_point(v2, 4.0, *color); @@ -1092,22 +1092,22 @@ pub(crate) fn draw_shape( let mut v1: B2vec2 = b2_mul_transform_by_vec2(*xf, vertices[0]); - for i in 1..count + for v in vertices.iter().take(count).skip(1) { - let v2: B2vec2 = b2_mul_transform_by_vec2(*xf, vertices[i]); + let v2: B2vec2 = b2_mul_transform_by_vec2(*xf, *v); m_debug_draw.draw_segment(v1, v2, *color); v1 = v2; } } - ShapeAsDerived::AsPolygon(poly) => + ShapeAsDerived::AsPolygon(poly) => { let vertex_count = poly.m_count; b2_assert(vertex_count <= B2_MAX_POLYGON_VERTICES); let mut vertices= <[B2vec2;B2_MAX_POLYGON_VERTICES]>::default(); - for i in 0..vertex_count + for (i, v) in poly.m_vertices.iter().enumerate().take(vertex_count) { - vertices[i] = b2_mul_transform_by_vec2(*xf, poly.m_vertices[i]); + vertices[i] = b2_mul_transform_by_vec2(*xf, *v); } m_debug_draw.draw_solid_polygon(&vertices[..vertex_count], *color); @@ -1135,13 +1135,13 @@ pub(crate) fn debug_draw(self_: &B2world) { let b = b.borrow(); let xf:B2Transform = b.get_transform(); for f in b.get_fixture_list().iter() - { + { if b.get_type() == B2bodyType::B2DynamicBody && b.m_mass == 0.0 { // Bad body self_.draw_shape(f, &xf, &B2color::new(1.0, 0.0, 0.0)); } - else if b.is_enabled() == false + else if !b.is_enabled() { self_.draw_shape(f, &xf, &B2color::new(0.5, 0.5, 0.3)); } @@ -1153,7 +1153,7 @@ pub(crate) fn debug_draw(self_: &B2world) { { self_.draw_shape(f, &xf, &B2color::new(0.5, 0.5, 0.9)); } - else if b.is_awake() == false + else if !b.is_awake() { self_.draw_shape(f, &xf, &B2color::new(0.6, 0.6, 0.6)); } @@ -1204,7 +1204,7 @@ pub(crate) fn debug_draw(self_: &B2world) { for b in self_.m_body_list.iter() { let b = b.borrow(); - if b.is_enabled() == false + if !b.is_enabled() { continue; } @@ -1276,7 +1276,7 @@ pub(crate) fn get_tree_quality(self_: &B2world) -> f32 { } pub(crate) fn shift_origin(self_: &B2world, new_origin: B2vec2) { - b2_assert(self_.is_locked() == false); + b2_assert(!self_.is_locked()); if self_.is_locked() { panic!(); } diff --git a/src/private/dynamics/b2_world_callbacks.rs b/src/private/dynamics/b2_world_callbacks.rs index 86987b7..da5b2f8 100644 --- a/src/private/dynamics/b2_world_callbacks.rs +++ b/src/private/dynamics/b2_world_callbacks.rs @@ -14,5 +14,5 @@ pub fn should_collide(fixture_a: FixturePtr, fixture_b: Fixtu } let collide:bool = (filter_a.mask_bits & filter_b.category_bits) != 0 && (filter_a.category_bits & filter_b.mask_bits) != 0; - return collide; + collide } diff --git a/src/private/dynamics/contacts/b2_chain_circle_contact.rs b/src/private/dynamics/contacts/b2_chain_circle_contact.rs index 01565b0..1260fb2 100644 --- a/src/private/dynamics/contacts/b2_chain_circle_contact.rs +++ b/src/private/dynamics/contacts/b2_chain_circle_contact.rs @@ -19,7 +19,7 @@ impl B2chainAndCircleContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2chainAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2chainAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -27,21 +27,21 @@ impl B2chainAndCircleContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EChain); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::ECircle); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2chainAndCircleContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_chain_polygon_contact.rs b/src/private/dynamics/contacts/b2_chain_polygon_contact.rs index fb04adc..f4bcbd4 100644 --- a/src/private/dynamics/contacts/b2_chain_polygon_contact.rs +++ b/src/private/dynamics/contacts/b2_chain_polygon_contact.rs @@ -18,7 +18,7 @@ impl B2chainAndPolygonContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2chainAndPolygonContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2chainAndPolygonContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -26,21 +26,21 @@ impl B2chainAndPolygonContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EChain); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::EPolygon); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2chainAndPolygonContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_circle_contact.rs b/src/private/dynamics/contacts/b2_circle_contact.rs index 8f59459..1337975 100644 --- a/src/private/dynamics/contacts/b2_circle_contact.rs +++ b/src/private/dynamics/contacts/b2_circle_contact.rs @@ -17,7 +17,7 @@ impl B2circleContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2circleContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2circleContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -25,21 +25,21 @@ impl B2circleContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::ECircle); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::ECircle); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2circleContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_edge_circle_contact.rs b/src/private/dynamics/contacts/b2_edge_circle_contact.rs index afe56b8..2eb127c 100644 --- a/src/private/dynamics/contacts/b2_edge_circle_contact.rs +++ b/src/private/dynamics/contacts/b2_edge_circle_contact.rs @@ -17,7 +17,7 @@ impl B2edgeAndCircleContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2edgeAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2edgeAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -25,21 +25,21 @@ impl B2edgeAndCircleContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EEdge); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::ECircle); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2edgeAndCircleContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_edge_polygon_contact.rs b/src/private/dynamics/contacts/b2_edge_polygon_contact.rs index c485cff..d5ee8d4 100644 --- a/src/private/dynamics/contacts/b2_edge_polygon_contact.rs +++ b/src/private/dynamics/contacts/b2_edge_polygon_contact.rs @@ -17,7 +17,7 @@ impl B2edgeAndPolygonContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2edgeAndPolygonContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2edgeAndPolygonContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -25,21 +25,21 @@ impl B2edgeAndPolygonContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EEdge); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::EPolygon); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2edgeAndPolygonContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_polygon_circle_contact.rs b/src/private/dynamics/contacts/b2_polygon_circle_contact.rs index ef8e5f3..6504249 100644 --- a/src/private/dynamics/contacts/b2_polygon_circle_contact.rs +++ b/src/private/dynamics/contacts/b2_polygon_circle_contact.rs @@ -17,7 +17,7 @@ impl B2polygonAndCircleContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2polygonAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2polygonAndCircleContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -25,21 +25,21 @@ impl B2polygonAndCircleContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EPolygon); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::ECircle); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2polygonAndCircleContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/contacts/b2_polygon_contact.rs b/src/private/dynamics/contacts/b2_polygon_contact.rs index c51e664..7de843a 100644 --- a/src/private/dynamics/contacts/b2_polygon_contact.rs +++ b/src/private/dynamics/contacts/b2_polygon_contact.rs @@ -17,7 +17,7 @@ impl B2polygonContact { pub fn create(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> ContactPtr { - return Rc::new(RefCell::new(B2polygonContact::new(fixture_a,index_a, fixture_b, index_b))); + Rc::new(RefCell::new(B2polygonContact::new(fixture_a,index_a, fixture_b, index_b))) } pub fn new(fixture_a: FixturePtr, index_a: i32, fixture_b: FixturePtr, index_b: i32) -> Self @@ -25,21 +25,21 @@ impl B2polygonContact b2_assert(fixture_a.as_ref().borrow().get_type() == B2ShapeType::EPolygon); b2_assert(fixture_b.as_ref().borrow().get_type() == B2ShapeType::EPolygon); - return Self{ + Self{ base: B2contact::new(fixture_a, index_a, fixture_b, index_b) - }; + } } } impl B2contactDynTrait for B2polygonContact { - fn get_base<'a>(&'a self) -> &'a B2contact + fn get_base(&self) -> &B2contact { - return &self.base; + &self.base } - fn get_base_mut<'a>(&'a mut self) -> &'a mut B2contact + fn get_base_mut(&mut self) -> &mut B2contact { - return &mut self.base; + &mut self.base } fn evaluate(&self, manifold: &mut B2manifold, xf_a: &B2Transform, xf_b: &B2Transform) diff --git a/src/private/dynamics/joints/b2_distance_joint.rs b/src/private/dynamics/joints/b2_distance_joint.rs index 0675253..a287a73 100644 --- a/src/private/dynamics/joints/b2_distance_joint.rs +++ b/src/private/dynamics/joints/b2_distance_joint.rs @@ -43,12 +43,12 @@ pub(crate) fn b2_distance_joint_new( def: &B2distanceJointDef, ) -> B2distanceJoint { let m_min_length = b2_max(def.min_length, B2_LINEAR_SLOP); - return B2distanceJoint { + B2distanceJoint { base: B2joint::new(&def.base), m_local_anchor_a: def.local_anchor_a, m_local_anchor_b: def.local_anchor_b, m_length: b2_max(def.length, B2_LINEAR_SLOP), - m_min_length: m_min_length, + m_min_length, m_max_length: b2_max(def.max_length, m_min_length), m_stiffness: def.stiffness, m_damping: def.damping, @@ -72,7 +72,7 @@ pub(crate) fn b2_distance_joint_new( m_inv_ib: 0.0, m_mass: 0.0, m_soft_mass: 0.0, - }; + } } pub(crate) fn init_velocity_constraints( @@ -278,7 +278,7 @@ pub(crate) fn solve_position_constraints( _data: &B2solverData, positions: &mut [B2position], ) -> bool { - + let mut c_a: B2vec2 = positions[self_.m_index_a].c; let mut a_a: f32 = positions[self_.m_index_a].a; let mut c_b: B2vec2 = positions[self_.m_index_b].c; @@ -292,9 +292,7 @@ pub(crate) fn solve_position_constraints( let length: f32 = u.normalize(); let c: f32; - if self_.m_min_length == self_.m_max_length { - c = length - self_.m_min_length; - } else if length < self_.m_min_length { + if self_.m_min_length == self_.m_max_length || length < self_.m_min_length { c = length - self_.m_min_length; } else if self_.m_max_length < length { c = length - self_.m_max_length; @@ -315,7 +313,7 @@ pub(crate) fn solve_position_constraints( positions[self_.m_index_b].c = c_b; positions[self_.m_index_b].a = a_b; - return b2_abs(c) < B2_LINEAR_SLOP; + b2_abs(c) < B2_LINEAR_SLOP } pub(crate) fn get_anchor_a(self_: &B2distanceJoint) -> B2vec2 { @@ -340,30 +338,30 @@ pub(crate) fn get_reaction_force( ) -> B2vec2 { let f: B2vec2 = inv_dt * (self_.m_impulse + self_.m_lower_impulse - self_.m_upper_impulse) * self_.m_u; - return f; + f } pub(crate) fn get_reaction_torque(_self: &B2distanceJoint, inv_dt: f32) -> f32 { b2_not_used(inv_dt); - return 0.0; + 0.0 } pub(crate) fn set_length(self_: &mut B2distanceJoint, length: f32) -> f32 { self_.m_impulse = 0.0; self_.m_length = b2_max(B2_LINEAR_SLOP, length); - return self_.m_length; + self_.m_length } pub(crate) fn set_min_length(self_: &mut B2distanceJoint, min_length: f32) -> f32 { self_.m_lower_impulse = 0.0; self_.m_min_length = b2_clamp(min_length, B2_LINEAR_SLOP, self_.m_max_length); - return self_.m_min_length; + self_.m_min_length } pub(crate) fn set_max_length(self_: &mut B2distanceJoint, max_length: f32) -> f32 { self_.m_upper_impulse = 0.0; self_.m_max_length = b2_max(max_length, self_.m_min_length); - return self_.m_max_length; + self_.m_max_length } pub(crate) fn get_current_length(self_: &B2distanceJoint) -> f32 { @@ -379,7 +377,7 @@ pub(crate) fn get_current_length(self_: &B2distanceJoint) -> .get_world_point(self_.m_local_anchor_b); let d: B2vec2 = p_b - p_a; let length: f32 = d.length(); - return length; + length } pub(crate) fn draw(self_: &B2distanceJoint, draw: &mut dyn B2drawTrait) { diff --git a/src/private/dynamics/joints/b2_friction_joint.rs b/src/private/dynamics/joints/b2_friction_joint.rs index 98286ae..f62627a 100644 --- a/src/private/dynamics/joints/b2_friction_joint.rs +++ b/src/private/dynamics/joints/b2_friction_joint.rs @@ -163,5 +163,5 @@ pub(crate) fn solve_position_constraints( ) -> bool { b2_not_used(data); - return true; + true } diff --git a/src/private/dynamics/joints/b2_gear_joint.rs b/src/private/dynamics/joints/b2_gear_joint.rs index 152b11a..3883da3 100644 --- a/src/private/dynamics/joints/b2_gear_joint.rs +++ b/src/private/dynamics/joints/b2_gear_joint.rs @@ -62,7 +62,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint match m_joint1.borrow().as_derived() { - JointAsDerived::ERevoluteJoint(ref revolute) => { + JointAsDerived::ERevoluteJoint(revolute) => { m_local_anchor_c = revolute.m_local_anchor_a; m_local_anchor_a = revolute.m_local_anchor_b; m_reference_angle_a = revolute.m_reference_angle; @@ -70,7 +70,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint coordinate_a = a_a - a_c - m_reference_angle_a; } - JointAsDerived::EPrismaticJoint(ref prismatic) => { + JointAsDerived::EPrismaticJoint(prismatic) => { m_local_anchor_c = prismatic.m_local_anchor_a; m_local_anchor_a = prismatic.m_local_anchor_b; m_reference_angle_a = prismatic.m_reference_angle; @@ -102,7 +102,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint match m_joint2.borrow().as_derived() { - JointAsDerived::ERevoluteJoint(ref revolute) => { + JointAsDerived::ERevoluteJoint(revolute) => { m_local_anchor_d = revolute.m_local_anchor_a; m_local_anchor_b = revolute.m_local_anchor_b; m_reference_angle_b = revolute.m_reference_angle; @@ -110,7 +110,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint coordinate_b = a_b - a_d - m_reference_angle_b; } - JointAsDerived::EPrismaticJoint(ref prismatic) => { + JointAsDerived::EPrismaticJoint(prismatic) => { m_local_anchor_d = prismatic.m_local_anchor_a; m_local_anchor_b = prismatic.m_local_anchor_b; m_reference_angle_b = prismatic.m_reference_angle; @@ -129,7 +129,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint let m_impulse = 0.0; - return B2gearJoint{ + B2gearJoint{ base: B2joint::new(&def.base), @@ -181,7 +181,7 @@ pub(crate) fn new(def: &B2gearJointDef)->B2gearJoint m_jw_c: 0.0, m_jw_d: 0.0, m_mass: 0.0, - }; + } } pub(crate) fn init_velocity_constraints(self_: &mut B2gearJoint, @@ -433,5 +433,5 @@ pub(crate) fn solve_position_constraints(self_: &B2gearJoint positions[self_.m_index_d as usize].a = a_d; // TODO_ERIN not implemented - return linear_error < B2_LINEAR_SLOP; + linear_error < B2_LINEAR_SLOP } \ No newline at end of file diff --git a/src/private/dynamics/joints/b2_motor_joint.rs b/src/private/dynamics/joints/b2_motor_joint.rs index 3554b69..643fd02 100644 --- a/src/private/dynamics/joints/b2_motor_joint.rs +++ b/src/private/dynamics/joints/b2_motor_joint.rs @@ -195,5 +195,5 @@ pub(crate) fn solve_position_constraints( ) -> bool { b2_not_used(data); - return true; + true } \ No newline at end of file diff --git a/src/private/dynamics/joints/b2_mouse_joint.rs b/src/private/dynamics/joints/b2_mouse_joint.rs index c8fd894..83caeeb 100644 --- a/src/private/dynamics/joints/b2_mouse_joint.rs +++ b/src/private/dynamics/joints/b2_mouse_joint.rs @@ -106,5 +106,5 @@ pub(crate) fn solve_velocity_constraints(self_: &mut B2mouseJo pub(crate) fn solve_position_constraints(_self: &mut B2mouseJoint, data: &B2solverData, _positions: &mut [B2position]) -> bool { b2_not_used(data); - return true; + true } diff --git a/src/private/dynamics/joints/b2_prismatic_joint.rs b/src/private/dynamics/joints/b2_prismatic_joint.rs index fcebeba..8aa236c 100644 --- a/src/private/dynamics/joints/b2_prismatic_joint.rs +++ b/src/private/dynamics/joints/b2_prismatic_joint.rs @@ -78,7 +78,7 @@ pub(crate) fn new(def: &B2prismaticJointDef) -> B2prismaticJ let m_axis = B2vec2::zero(); let m_perp = B2vec2::zero(); - return B2prismaticJoint { + B2prismaticJoint { base: B2joint::new(&def.base), m_local_anchor_a, @@ -114,7 +114,7 @@ pub(crate) fn new(def: &B2prismaticJointDef) -> B2prismaticJ m_k: B2Mat22::default(), m_translation: 0.0, m_axial_mass: 0.0, - }; + } } pub(crate) fn init_velocity_constraints( @@ -194,7 +194,7 @@ pub(crate) fn init_velocity_constraints( self_.m_upper_impulse = 0.0; } - if self_.m_enable_motor == false { + if !self_.m_enable_motor { self_.m_motor_impulse = 0.0; } @@ -456,7 +456,7 @@ pub(crate) fn solve_position_constraints( positions[self_.m_index_b as usize].c = c_b; positions[self_.m_index_b as usize].a = a_b; - return linear_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP; + linear_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP } pub(crate) fn get_joint_translation(self_: &B2prismaticJoint) -> f32 { @@ -478,7 +478,7 @@ pub(crate) fn get_joint_translation(self_: &B2prismaticJoint .get_world_vector(self_.m_local_xaxis_a); let translation: f32 = b2_dot(d, axis); - return translation; + translation } pub(crate) fn get_joint_speed(self_: &B2prismaticJoint) -> f32 { @@ -504,7 +504,7 @@ pub(crate) fn get_joint_speed(self_: &B2prismaticJoint) -> f axis, v_b + b2_cross_scalar_by_vec(w_b, r_b) - v_a - b2_cross_scalar_by_vec(w_a, r_a), ); - return speed; + speed } pub(crate) fn draw(self_: &B2prismaticJoint, draw: &mut dyn B2drawTrait) { diff --git a/src/private/dynamics/joints/b2_pulley_joint.rs b/src/private/dynamics/joints/b2_pulley_joint.rs index 63f443a..5e282ce 100644 --- a/src/private/dynamics/joints/b2_pulley_joint.rs +++ b/src/private/dynamics/joints/b2_pulley_joint.rs @@ -33,7 +33,7 @@ pub(crate) fn new(def: &B2pulleyJointDef) -> B2pulleyJoint(def: &B2pulleyJointDef) -> B2pulleyJoint( @@ -273,5 +273,5 @@ pub(crate) fn solve_position_constraints( positions[self_.m_index_a as usize] = B2position{c: c_a, a: a_a}; positions[self_.m_index_b as usize] = B2position{c: c_b, a: a_b}; - return linear_error < B2_LINEAR_SLOP; + linear_error < B2_LINEAR_SLOP } \ No newline at end of file diff --git a/src/private/dynamics/joints/b2_revolute_joint.rs b/src/private/dynamics/joints/b2_revolute_joint.rs index b94d0cd..fc356d6 100644 --- a/src/private/dynamics/joints/b2_revolute_joint.rs +++ b/src/private/dynamics/joints/b2_revolute_joint.rs @@ -79,12 +79,12 @@ pub(crate) fn init_velocity_constraints( } self_.m_angle = a_b - a_a - self_.m_reference_angle; - if self_.m_enable_limit == false || fixed_rotation { + if !self_.m_enable_limit || fixed_rotation { self_.m_lower_impulse = 0.0; self_.m_upper_impulse = 0.0; } - if self_.m_enable_motor == false || fixed_rotation { + if !self_.m_enable_motor || fixed_rotation { self_.m_motor_impulse = 0.0; } @@ -142,7 +142,7 @@ pub(crate) fn solve_velocity_constraints( let fixed_rotation: bool = i_a + i_b == 0.0; // solve motor constraint. - if self_.m_enable_motor && fixed_rotation == false { + if self_.m_enable_motor && !fixed_rotation { let cdot: f32 = w_b - w_a - self_.m_motor_speed; let mut impulse: f32 = -self_.m_axial_mass * cdot; let old_impulse: f32 = self_.m_motor_impulse; @@ -154,7 +154,7 @@ pub(crate) fn solve_velocity_constraints( w_b += i_b * impulse; } - if self_.m_enable_limit && fixed_rotation == false { + if self_.m_enable_limit && !fixed_rotation { // Lower limit { let c: f32 = self_.m_angle - self_.m_lower_angle; @@ -227,7 +227,7 @@ pub(crate) fn solve_position_constraints( let fixed_rotation: bool = self_.m_inv_ia + self_.m_inv_ib == 0.0; // Solve angular limit constraint - if self_.m_enable_limit && fixed_rotation == false { + if self_.m_enable_limit && !fixed_rotation { let angle: f32 = a_b - a_a - self_.m_reference_angle; let mut c: f32 = 0.0; @@ -292,7 +292,7 @@ pub(crate) fn solve_position_constraints( positions[self_.m_index_a as usize] = B2position { c: c_a, a: a_a }; positions[self_.m_index_b as usize] = B2position { c: c_b, a: a_b }; - return position_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP; + position_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP } pub(crate) fn draw(self_: &B2revoluteJoint, draw: &mut dyn B2drawTrait) { diff --git a/src/private/dynamics/joints/b2_weld_joint.rs b/src/private/dynamics/joints/b2_weld_joint.rs index 83ad5a1..04abfd8 100644 --- a/src/private/dynamics/joints/b2_weld_joint.rs +++ b/src/private/dynamics/joints/b2_weld_joint.rs @@ -228,9 +228,6 @@ pub(crate) fn solve_position_constraints( let r_a: B2vec2 = b2_mul_rot_by_vec2(q_a, self_.m_local_anchor_a - self_.m_local_center_a); let r_b: B2vec2 = b2_mul_rot_by_vec2(q_b, self_.m_local_anchor_b - self_.m_local_center_b); - let position_error: f32; - let angular_error: f32; - let mut k = B2Mat33::default(); k.ex.x = m_a + m_b + r_a.y * r_a.y * i_a + r_b.y * r_b.y * i_b; k.ey.x = -r_a.y * r_a.x * i_a - r_b.y * r_b.x * i_b; @@ -242,12 +239,9 @@ pub(crate) fn solve_position_constraints( k.ey.z = k.ez.y; k.ez.z = i_a + i_b; - if self_.m_stiffness > 0.0 { + let (position_error, angular_error) = if self_.m_stiffness > 0.0 { let c1: B2vec2 = c_b + r_b - c_a - r_a; - position_error = c1.length(); - angular_error = 0.0; - let p: B2vec2 = -k.solve22(c1); c_a -= m_a * p; @@ -255,21 +249,19 @@ pub(crate) fn solve_position_constraints( c_b += m_b * p; a_b += i_b * b2_cross(r_b, p); + + (c1.length(), 0.0) } else { let c1: B2vec2 = c_b + r_b - c_a - r_a; let c2: f32 = a_b - a_a - self_.m_reference_angle; - position_error = c1.length(); - angular_error = b2_abs(c2); - let c = B2Vec3::new(c1.x, c1.y, c2); - let impulse: B2Vec3; - if k.ez.z > 0.0 { - impulse = -k.solve33(c); + let impulse: B2Vec3 = if k.ez.z > 0.0 { + -k.solve33(c) } else { let impulse2: B2vec2 = -k.solve22(c1); - impulse = B2Vec3::new(impulse2.x, impulse2.y, 0.0); - } + B2Vec3::new(impulse2.x, impulse2.y, 0.0) + }; let p = B2vec2::new(impulse.x, impulse.y); @@ -278,12 +270,14 @@ pub(crate) fn solve_position_constraints( c_b += m_b * p; a_b += i_b * (b2_cross(r_b, p) + impulse.z); - } + + (c1.length(), b2_abs(c2)) + }; positions[self_.m_index_a as usize] = B2position { c: c_a, a: a_a }; positions[self_.m_index_b as usize] = B2position { c: c_b, a: a_b }; - return position_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP; + position_error <= B2_LINEAR_SLOP && angular_error <= B2_ANGULAR_SLOP } // void B2weldJoint::dump() diff --git a/src/private/dynamics/joints/b2_wheel_joint.rs b/src/private/dynamics/joints/b2_wheel_joint.rs index 6caa2b8..3c73c04 100644 --- a/src/private/dynamics/joints/b2_wheel_joint.rs +++ b/src/private/dynamics/joints/b2_wheel_joint.rs @@ -371,7 +371,7 @@ pub(crate) fn solve_position_constraints( positions[self_.m_index_a as usize] = B2position { c: c_a, a: a_a }; positions[self_.m_index_b as usize] = B2position { c: c_b, a: a_b }; - return linear_error <= B2_LINEAR_SLOP; + linear_error <= B2_LINEAR_SLOP } // void B2wheelJoint::dump() @@ -396,7 +396,6 @@ pub(crate) fn solve_position_constraints( // b2Log(" joints[%d] = m_world->create_joint(&jd);\n", m_index); // } -/// pub(crate) fn draw(self_: &B2wheelJoint, draw: &mut dyn B2drawTrait) { let xf_a = self_.base.m_body_a.borrow().get_transform(); let xf_b = self_.base.m_body_b.borrow().get_transform(); diff --git a/src/private/rope/b2_rope.rs b/src/private/rope/b2_rope.rs index 9ebfe3e..45ffcc0 100644 --- a/src/private/rope/b2_rope.rs +++ b/src/private/rope/b2_rope.rs @@ -25,18 +25,16 @@ pub(crate) fn create(_self: &mut B2rope, def: &B2ropeDef) { _self.m_positions.resize(m_count, Default::default()); for (i,def) in def.vertices.iter().enumerate() { - let mut new_pos = B2ropePositions::default(); - new_pos.m_bind_positions = def.position; - new_pos.m_ps = def.position + _self.m_position; - new_pos.m_p0s = def.position + _self.m_position; - new_pos.m_vs.set_zero(); - let m: f32 = def.mass; - if m > 0.0 { - new_pos.m_inv_masses = 1.0 / m; - } else { - new_pos.m_inv_masses = 0.0; - } + let inv_masses = if m > 0.0 { 1.0 / m } else { 0.0 }; + + let new_pos = B2ropePositions { + m_bind_positions: def.position, + m_ps: def.position + _self.m_position, + m_p0s: def.position + _self.m_position, + m_vs: B2vec2::zero(), + m_inv_masses: inv_masses, + }; _self.m_positions[i]=new_pos; } @@ -347,16 +345,11 @@ pub(crate) fn solve_bend_pbd_angle(_self: &mut B2rope) { let angle: f32 = b2_atan2(a, b); - let l1sqr: f32; - let l2sqr: f32; - - if _self.m_tuning.isometric { - l1sqr = c.l1 * c.l1; - l2sqr = c.l2 * c.l2; + let (l1sqr, l2sqr) = if _self.m_tuning.isometric { + (c.l1 * c.l1, c.l2 * c.l2) } else { - l1sqr = d1.length_squared(); - l2sqr = d2.length_squared(); - } + (d1.length_squared(), d2.length_squared()) + }; if l1sqr * l2sqr == 0.0 { continue; @@ -369,14 +362,13 @@ pub(crate) fn solve_bend_pbd_angle(_self: &mut B2rope) { let j2: B2vec2 = jd1 - jd2; let j3: B2vec2 = jd2; - let mut sum: f32; - if _self.m_tuning.fixed_effective_mass { - sum = c.inv_effective_mass; + let mut sum: f32 = if _self.m_tuning.fixed_effective_mass { + c.inv_effective_mass } else { - sum = c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass2 * b2_dot(j2, j2) - + c.inv_mass3 * b2_dot(j3, j3); - } + + c.inv_mass3 * b2_dot(j3, j3) + }; if sum == 0.0 { sum = c.inv_effective_mass; @@ -409,16 +401,11 @@ pub(crate) fn solve_bend_xpbd_angle(_self: &mut B2rope, dt: f32) { let d1: B2vec2 = p2 - p1; let d2: B2vec2 = p3 - p2; - let l1sqr: f32; - let l2sqr: f32; - - if _self.m_tuning.isometric { - l1sqr = c.l1 * c.l1; - l2sqr = c.l2 * c.l2; + let (l1sqr, l2sqr) = if _self.m_tuning.isometric { + (c.l1 * c.l1, c.l2 * c.l2) } else { - l1sqr = d1.length_squared(); - l2sqr = d2.length_squared(); - } + (d1.length_squared(), d2.length_squared()) + }; if l1sqr * l2sqr == 0.0 { continue; @@ -436,14 +423,13 @@ pub(crate) fn solve_bend_xpbd_angle(_self: &mut B2rope, dt: f32) { let j2: B2vec2 = jd1 - jd2; let j3: B2vec2 = jd2; - let sum: f32; - if _self.m_tuning.fixed_effective_mass { - sum = c.inv_effective_mass; + let sum: f32 = if _self.m_tuning.fixed_effective_mass { + c.inv_effective_mass } else { - sum = c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass2 * b2_dot(j2, j2) - + c.inv_mass3 * b2_dot(j3, j3); - } + + c.inv_mass3 * b2_dot(j3, j3) + }; if sum == 0.0 { continue; @@ -489,16 +475,11 @@ pub(crate) fn apply_bend_forces(_self: &mut B2rope, dt: f32) { let d1: B2vec2 = p2 - p1; let d2: B2vec2 = p3 - p2; - let l1sqr: f32; - let l2sqr: f32; - - if _self.m_tuning.isometric { - l1sqr = c.l1 * c.l1; - l2sqr = c.l2 * c.l2; + let (l1sqr, l2sqr) = if _self.m_tuning.isometric { + (c.l1 * c.l1, c.l2 * c.l2) } else { - l1sqr = d1.length_squared(); - l2sqr = d2.length_squared(); - } + (d1.length_squared(), d2.length_squared()) + }; if l1sqr * l2sqr == 0.0 { continue; @@ -516,14 +497,13 @@ pub(crate) fn apply_bend_forces(_self: &mut B2rope, dt: f32) { let j2: B2vec2 = jd1 - jd2; let j3: B2vec2 = jd2; - let sum: f32; - if _self.m_tuning.fixed_effective_mass { - sum = c.inv_effective_mass; + let sum: f32 = if _self.m_tuning.fixed_effective_mass { + c.inv_effective_mass } else { - sum = c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass1 * b2_dot(j1, j1) + c.inv_mass2 * b2_dot(j2, j2) - + c.inv_mass3 * b2_dot(j3, j3); - } + + c.inv_mass3 * b2_dot(j3, j3) + }; if sum == 0.0 { continue; diff --git a/src/shapes/b2_chain_shape.rs b/src/shapes/b2_chain_shape.rs index b1711cb..4701c07 100644 --- a/src/shapes/b2_chain_shape.rs +++ b/src/shapes/b2_chain_shape.rs @@ -28,7 +28,7 @@ pub struct B2chainShape { impl Default for B2chainShape { fn default() -> Self { - return inline::b2_chain_shape(); + inline::b2_chain_shape() } } @@ -62,28 +62,28 @@ impl B2chainShape { impl B2shapeDynTrait for B2chainShape { fn get_base(&self) -> &B2Shape { - return &self.base; + &self.base } fn get_type(&self) -> B2ShapeType { - return self.base.get_type(); + self.base.get_type() } /// Implement b2Shape. Vertices are cloned using b2Alloc. fn clone_box(&self) -> Box { - return private::b2_shape_dyn_trait_clone(self); + private::b2_shape_dyn_trait_clone(self) } fn clone_rc(&self) -> ShapePtr { - return Rc::new(self.clone()); + Rc::new(self.clone()) } /// [see](B2shapeDynTrait::get_child_count) fn get_child_count(&self) -> usize { - return private::b2_shape_dyn_trait_get_child_count(self); + private::b2_shape_dyn_trait_get_child_count(self) } /// This always return false. /// [see](B2shapeDynTrait::test_point) fn test_point(&self, transform: B2Transform, p: B2vec2) -> bool { - return private::b2_shape_dyn_trait_test_point(self, transform, p); + private::b2_shape_dyn_trait_test_point(self, transform, p) } /// Implement b2Shape. @@ -94,7 +94,7 @@ impl B2shapeDynTrait for B2chainShape { xf: B2Transform, child_index: usize, ) -> bool { - return private::b2_shape_dyn_trait_ray_cast(self, output, input, xf, child_index); + private::b2_shape_dyn_trait_ray_cast(self, output, input, xf, child_index) } /// [see](B2shapeDynTrait::compute_aabb) @@ -112,7 +112,7 @@ impl B2shapeDynTrait for B2chainShape { mod inline { use super::*; pub fn b2_chain_shape() -> B2chainShape { - return B2chainShape { + B2chainShape { base: B2Shape { m_type: B2ShapeType::EChain, m_radius: B2_POLYGON_RADIUS, @@ -120,6 +120,6 @@ mod inline { m_next_vertex: B2vec2 { x: 0.0, y: 0.0 }, m_prev_vertex: B2vec2 { x: 0.0, y: 0.0 }, m_vertices: Vec::::new(), - }; + } } } diff --git a/src/shapes/b2_circle_shape.rs b/src/shapes/b2_circle_shape.rs index 1b029e5..1ec576a 100644 --- a/src/shapes/b2_circle_shape.rs +++ b/src/shapes/b2_circle_shape.rs @@ -17,7 +17,7 @@ pub struct B2circleShape { impl Default for B2circleShape { fn default() -> Self { - return inline::b2_circle_shape(); + inline::b2_circle_shape() } } @@ -25,30 +25,30 @@ impl Default for B2circleShape { impl B2shapeDynTrait for B2circleShape { fn get_base(&self) -> &B2Shape { - return &self.base; + &self.base } fn get_type(&self) -> B2ShapeType { - return self.base.get_type(); + self.base.get_type() } /// Implement b2Shape. fn clone_box(&self) -> Box { - return private::clone(self); + private::clone(self) } fn clone_rc(&self) -> ShapePtr { - return Rc::new(self.clone()); + Rc::new(*self) } /// [see](B2shapeDynTrait::get_child_count) fn get_child_count(&self) -> usize { - return private::get_child_count(self); + private::get_child_count(self) } /// Implement b2Shape. fn test_point(&self, transform: B2Transform, p: B2vec2) -> bool { - return private::test_point(self, transform, p); + private::test_point(self, transform, p) } /// Implement b2Shape. @@ -61,9 +61,9 @@ impl B2shapeDynTrait for B2circleShape { xf: B2Transform, child_index: usize, ) -> bool { - return private::ray_cast( + private::ray_cast( self, output, input, xf, child_index, - ); + ) } /// [see](B2shapeDynTrait::compute_aabb) @@ -83,12 +83,12 @@ mod inline { use super::*; pub fn b2_circle_shape() -> B2circleShape { - return B2circleShape { + B2circleShape { base: B2Shape { m_type: B2ShapeType::ECircle, m_radius: 0.0, }, m_p: B2vec2::zero(), - }; + } } } \ No newline at end of file diff --git a/src/shapes/b2_edge_shape.rs b/src/shapes/b2_edge_shape.rs index 646d740..187a47a 100644 --- a/src/shapes/b2_edge_shape.rs +++ b/src/shapes/b2_edge_shape.rs @@ -29,7 +29,7 @@ pub struct B2edgeShape { impl Default for B2edgeShape { fn default() -> Self { - return inline::b2_edge_shape(); + inline::b2_edge_shape() } } @@ -54,27 +54,27 @@ impl B2edgeShape { impl B2shapeDynTrait for B2edgeShape { fn get_base(&self) -> &B2Shape { - return &self.base; + &self.base } fn get_type(&self) -> B2ShapeType { - return self.base.get_type(); + self.base.get_type() } /// Implement b2Shape. fn clone_box(&self) -> Box { - return private::b2_shape_dyn_trait_clone(self); + private::b2_shape_dyn_trait_clone(self) } fn clone_rc(&self) -> ShapePtr { - return Rc::new(self.clone()); + Rc::new(*self) } /// [see](B2shapeDynTrait::get_child_count) fn get_child_count(&self) -> usize { - return private::b2_shape_dyn_trait_get_child_count(self); + private::b2_shape_dyn_trait_get_child_count(self) } /// [see](B2shapeDynTrait::test_point) fn test_point(&self, transform: B2Transform, p: B2vec2) -> bool { - return private::b2_shape_dyn_trait_test_point(self, transform, p); + private::b2_shape_dyn_trait_test_point(self, transform, p) } /// Implement b2Shape. @@ -85,9 +85,9 @@ impl B2shapeDynTrait for B2edgeShape { xf: B2Transform, child_index: usize, ) -> bool { - return private::b2_shape_dyn_trait_ray_cast( - &self, output, input, xf, child_index, - ); + private::b2_shape_dyn_trait_ray_cast( + self, output, input, xf, child_index, + ) } /// [see](B2shapeDynTrait::compute_aabb) @@ -105,7 +105,7 @@ mod inline { use super::*; pub fn b2_edge_shape() -> B2edgeShape { - return B2edgeShape { + B2edgeShape { base: B2Shape { m_type: B2ShapeType::EEdge, m_radius: B2_POLYGON_RADIUS, @@ -115,6 +115,6 @@ mod inline m_vertex0: B2vec2 { x: 0.0, y: 0.0 }, m_vertex3: B2vec2 { x: 0.0, y: 0.0 }, m_one_sided: false, - }; + } } } \ No newline at end of file diff --git a/src/shapes/b2_polygon_shape.rs b/src/shapes/b2_polygon_shape.rs index 6125f66..06efffd 100644 --- a/src/shapes/b2_polygon_shape.rs +++ b/src/shapes/b2_polygon_shape.rs @@ -21,32 +21,32 @@ pub struct B2polygonShape { impl Default for B2polygonShape { fn default() -> Self { - return inline::b2_polygon_shape(); + inline::b2_polygon_shape() } } impl B2shapeDynTrait for B2polygonShape { fn get_base(&self) -> &B2Shape { - return &self.base; + &self.base } fn get_type(&self) -> B2ShapeType { - return self.base.get_type(); + self.base.get_type() } /// Implement b2Shape. fn clone_box(&self) -> Box { - return private::b2_shape_dyn_trait_clone(self); + private::b2_shape_dyn_trait_clone(self) } fn clone_rc(&self) -> ShapePtr { - return Rc::new(self.clone()); + Rc::new(*self) } /// [see](B2shapeDynTrait::get_child_count) fn get_child_count(&self) -> usize { - return private::b2_shape_dyn_trait_get_child_count(self); + private::b2_shape_dyn_trait_get_child_count(self) } /// [see](B2shapeDynTrait::test_point) fn test_point(&self, transform: B2Transform, p: B2vec2) -> bool { - return private::b2_shape_dyn_trait_test_point(self, transform, p); + private::b2_shape_dyn_trait_test_point(self, transform, p) } /// Implement b2Shape. @@ -59,7 +59,7 @@ impl B2shapeDynTrait for B2polygonShape { xf: B2Transform, child_index: usize, ) -> bool { - return private::b2_shape_dyn_trait_ray_cast(self, output, input, xf, child_index); + private::b2_shape_dyn_trait_ray_cast(self, output, input, xf, child_index) } /// [see](B2shapeDynTrait::compute_aabb) @@ -108,14 +108,14 @@ impl B2polygonShape { /// /// @returns true if valid pub fn validate(self) -> bool { - return private::b2_polygon_shape_validate(self); + private::b2_polygon_shape_validate(self) } } mod inline { use super::*; pub fn b2_polygon_shape() -> B2polygonShape { - return B2polygonShape { + B2polygonShape { base: B2Shape { m_type: B2ShapeType::EPolygon, m_radius: B2_POLYGON_RADIUS, @@ -124,6 +124,6 @@ mod inline { m_count: 0, m_vertices: <[B2vec2; B2_MAX_POLYGON_VERTICES]>::default(), m_normals: <[B2vec2; B2_MAX_POLYGON_VERTICES]>::default(), - }; + } } } diff --git a/src/shapes/b2rs_to_derived_shape.rs b/src/shapes/b2rs_to_derived_shape.rs index bc97279..4407a36 100644 --- a/src/shapes/b2rs_to_derived_shape.rs +++ b/src/shapes/b2rs_to_derived_shape.rs @@ -5,7 +5,7 @@ use super::b2_polygon_shape::*; pub trait ToDerivedShape { - fn as_derived(&self) -> ShapeAsDerived; + fn as_derived(&self) -> ShapeAsDerived<'_>; fn as_circle(&self) -> Option<&B2circleShape>; fn as_edge(&self) -> Option<&B2edgeShape>; @@ -23,8 +23,8 @@ pub enum ShapeAsDerived<'a> impl ToDerivedShape for B2circleShape { - fn as_derived(&self) -> ShapeAsDerived{ - return ShapeAsDerived::AsCircle(&self); + fn as_derived(&self) -> ShapeAsDerived<'_>{ + ShapeAsDerived::AsCircle(self) } fn as_circle(&self) -> Option<&B2circleShape> { @@ -45,8 +45,8 @@ impl ToDerivedShape for B2circleShape { } impl ToDerivedShape for B2edgeShape { - fn as_derived(&self) -> ShapeAsDerived{ - return ShapeAsDerived::AsEdge(&self); + fn as_derived(&self) -> ShapeAsDerived<'_>{ + ShapeAsDerived::AsEdge(self) } fn as_circle(&self) -> Option<&B2circleShape> { @@ -67,8 +67,8 @@ impl ToDerivedShape for B2edgeShape { } impl ToDerivedShape for B2polygonShape { - fn as_derived(&self) -> ShapeAsDerived{ - return ShapeAsDerived::AsPolygon(&self); + fn as_derived(&self) -> ShapeAsDerived<'_>{ + ShapeAsDerived::AsPolygon(self) } fn as_circle(&self) -> Option<&B2circleShape> { None @@ -88,8 +88,8 @@ impl ToDerivedShape for B2polygonShape { } impl ToDerivedShape for B2chainShape { - fn as_derived(&self) -> ShapeAsDerived{ - return ShapeAsDerived::AsChain(&self); + fn as_derived(&self) -> ShapeAsDerived<'_>{ + ShapeAsDerived::AsChain(self) } fn as_circle(&self) -> Option<&B2circleShape> { None