-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allowed specifying
FixtureDef
properties via constructor (#52)
* feat: allowed specifying FixtureDef properties via constructor * refactor!: made default friction 0 * feat: made friction default 0.2
- Loading branch information
Showing
2 changed files
with
49 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>()); | ||
}); | ||
}); | ||
}); | ||
} |