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