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

refactor!: used setters and getters for motorSpeed #58

Merged
merged 5 commits into from
May 14, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
10 changes: 2 additions & 8 deletions packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -275,20 +275,14 @@ class PrismaticJoint extends Joint {
}

/// Set the motor speed, usually in meters per second.
///
/// @param speed
void setMotorSpeed(double speed) {
set motorSpeed(double speed) {
bodyA.setAwake(true);
bodyB.setAwake(true);
_motorSpeed = speed;
}

/// Get the motor speed, usually in meters per second.
///
/// @return
double getMotorSpeed() {
return _motorSpeed;
}
double get motorSpeed => _motorSpeed;

/// Set the maximum motor force, usually in N.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ class RevoluteJoint extends Joint {
_enableMotor = flag;
}

void setMotorSpeed(final double speed) {
set motorSpeed(double speed) {
bodyA.setAwake(true);
bodyB.setAwake(true);
_motorSpeed = speed;
Expand Down
6 changes: 2 additions & 4 deletions packages/forge2d/lib/src/dynamics/joints/wheel_joint.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,13 @@ class WheelJoint extends Joint {
_enableMotor = flag;
}

void setMotorSpeed(double speed) {
set motorSpeed(double speed) {
bodyA.setAwake(true);
bodyB.setAwake(true);
_motorSpeed = speed;
}

double getMotorSpeed() {
return _motorSpeed;
}
double get motorSpeed => _motorSpeed;

double getMaxMotorTorque() {
return _maxMotorTorque;
Expand Down
34 changes: 22 additions & 12 deletions packages/forge2d/test/dynamics/joints/prismatic_joint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,43 @@ import '../../helpers/helpers.dart';

void main() {
group('PrismaticJoint', () {
test('can be instantiated', () {
final world = World();
final jointDef = PrismaticJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world);
late PrismaticJointDef jointDef;

setUp(
() {
final world = World();
jointDef = PrismaticJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world);
},
);

test('can be instantiated', () {
expect(PrismaticJoint(jointDef), isA<PrismaticJoint>());
});

test('can change motor speed', () {
final joint = PrismaticJoint(jointDef);

final oldMotorSpeed = joint.motorSpeed;
final newMotorSpeed = oldMotorSpeed + 1;
joint.motorSpeed = newMotorSpeed;

expect(joint.motorSpeed, equals(newMotorSpeed));
});

group('render', () {
late World world;
late DebugDraw debugDraw;

setUp(() {
world = World();
debugDraw = MockDebugDraw();

registerFallbackValue(Vector2.zero());
registerFallbackValue(Color3i.black);
});

test('draws three segments', () {
final joint = PrismaticJoint(
PrismaticJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world),
);
final joint = PrismaticJoint(jointDef);
joint.render(debugDraw);
verify(() => debugDraw.drawSegment(any(), any(), any())).called(3);
});
Expand Down
26 changes: 17 additions & 9 deletions packages/forge2d/test/dynamics/joints/revolute_joint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,41 @@ import '../../helpers/helpers.dart';

void main() {
group('RevoluteJoint', () {
test('can be instantiated', () {
late RevoluteJointDef jointDef;

setUp(() {
final world = World();
final jointDef = RevoluteJointDef()
jointDef = RevoluteJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world);
});

test('can be instantiated', () {
expect(RevoluteJoint(jointDef), isA<RevoluteJoint>());
});

test('can change motor speed', () {
final joint = RevoluteJoint(jointDef);

final oldMotorSpeed = joint.motorSpeed;
final newMotorSpeed = oldMotorSpeed + 1;
joint.motorSpeed = newMotorSpeed;

expect(joint.motorSpeed, equals(newMotorSpeed));
});

group('render', () {
late World world;
late DebugDraw debugDraw;

setUp(() {
world = World();
debugDraw = MockDebugDraw();

registerFallbackValue(Vector2.zero());
registerFallbackValue(Color3i.black);
});

test('draws three segments', () {
final joint = RevoluteJoint(
RevoluteJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world),
);
final joint = RevoluteJoint(jointDef);
joint.render(debugDraw);
verify(() => debugDraw.drawSegment(any(), any(), any())).called(3);
});
Expand Down
26 changes: 17 additions & 9 deletions packages/forge2d/test/dynamics/joints/wheel_joint_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,41 @@ import '../../helpers/helpers.dart';

void main() {
group('WheelJoint', () {
test('can be instantiated', () {
late WheelJointDef jointDef;

setUp(() {
final world = World();
final jointDef = WheelJointDef()
jointDef = WheelJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world);
});

test('can be instantiated', () {
expect(WheelJoint(jointDef), isA<WheelJoint>());
});

test('can change motor speed', () {
final joint = WheelJoint(jointDef);

final oldMotorSpeed = joint.motorSpeed;
final newMotorSpeed = oldMotorSpeed + 1;
joint.motorSpeed = newMotorSpeed;

expect(joint.motorSpeed, equals(newMotorSpeed));
});

group('render', () {
late World world;
late DebugDraw debugDraw;

setUp(() {
world = World();
debugDraw = MockDebugDraw();

registerFallbackValue(Vector2.zero());
registerFallbackValue(Color3i.black);
});

test('draws three segments', () {
final joint = WheelJoint(
WheelJointDef()
..bodyA = Body(BodyDef(), world)
..bodyB = Body(BodyDef(), world),
);
final joint = WheelJoint(jointDef);
joint.render(debugDraw);
verify(() => debugDraw.drawSegment(any(), any(), any())).called(3);
});
Expand Down