Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: allowed specifying FixtureDef properties via constructor #52

Merged
merged 4 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions packages/forge2d/lib/src/dynamics/fixture_def.dart
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
import '../../forge2d.dart';

/// A fixture definition is used to create a fixture. This class defines an abstract fixture
/// definition. You can reuse fixture definitions safely.
/// Used to create a [Fixture].
///
/// You can reuse fixture definitions safely.
class FixtureDef {
/// The shape, this must be set. The shape will be cloned, so you can create the shape on the
FixtureDef(
this.shape, {
this.userData,
this.friction = 0.2,
this.restitution = 0,
this.density = 0,
this.isSensor = false,
Filter? filter,
}) : filter = filter ?? Filter();

/// The [Shape], this must be set.
///
/// The [Shape] will be [Shape.clone]d, so you can create the shape on the
/// stack.
Shape shape;

FixtureDef(this.shape);

/// Use this to store application specific fixture data.
Object? userData;

/// The friction coefficient, usually in the range [0,1].
double friction = 0.2;
double friction;

/// The restitution (elasticity) usually in the range [0,1].
double restitution = 0.0;
double restitution;

/// The density, usually in kg/m^2
double density = 0.0;
/// The density, usually in kg/m^2.
double density;

/// A sensor shape collects contact information but never generates a collision response.
bool isSensor = false;
/// A sensor shape collects contact information but never generates a
/// collision response.
bool isSensor;

/// Contact filtering data;
Filter filter = Filter();
/// Contact filtering data.
Filter filter;
}
24 changes: 24 additions & 0 deletions packages/forge2d/test/dynamics/fixture_def_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import 'package:forge2d/forge2d.dart';
import 'package:test/test.dart';

void main() {
group('FixtureDef', () {
group('can be instantiated', () {
test('when Shape is a ChainShape', () {
expect(FixtureDef(ChainShape()), isA<FixtureDef>());
});

test('when Shape is a CircleShape', () {
expect(FixtureDef(CircleShape()), isA<FixtureDef>());
});

test('when Shape is a EdgeShape', () {
expect(FixtureDef(EdgeShape()), isA<FixtureDef>());
});

test('when Shape is a PolygonShape', () {
expect(FixtureDef(PolygonShape()), isA<FixtureDef>());
});
});
});
}