Skip to content

Commit

Permalink
refactor!: used getter and setters for maxMotorForce (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago committed Aug 22, 2022
1 parent 2dfe1e8 commit 4ab2eb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
16 changes: 7 additions & 9 deletions packages/forge2d/lib/src/dynamics/joints/prismatic_joint.dart
Expand Up @@ -276,20 +276,18 @@ class PrismaticJoint extends Joint {
/// Get the motor speed, usually in meters per second.
double get motorSpeed => _motorSpeed;

/// Set the maximum motor force, usually in N.
void setMaxMotorForce(double force) {
bodyA.setAwake(true);
bodyB.setAwake(true);
_maxMotorForce = force;
}

/// Get the current motor force, usually in N.
double getMotorForce(double invDt) {
return _motorImpulse * invDt;
}

double getMaxMotorForce() {
return _maxMotorForce;
double get maxMotorForce => _maxMotorForce;

/// Set the maximum motor force, usually in N.
set maxMotorForce(double force) {
bodyA.setAwake(true);
bodyB.setAwake(true);
_maxMotorForce = force;
}

double getReferenceAngle() {
Expand Down
19 changes: 19 additions & 0 deletions packages/forge2d/test/dynamics/joints/prismatic_joint_test.dart
Expand Up @@ -42,6 +42,25 @@ void main() {
});
});

group('maxMotorForce', () {
test('can change maxMotorForce', () {
final joint = PrismaticJoint(jointDef);

final newMaxMotorForce = joint.maxMotorForce + 1;
joint.maxMotorForce = newMaxMotorForce;

expect(joint.maxMotorForce, equals(newMaxMotorForce));
});

test('wakes up both bodies', () {
final joint = PrismaticJoint(jointDef);
joint.maxMotorForce = 1;

verify(() => joint.bodyA.setAwake(true)).called(1);
verify(() => joint.bodyB.setAwake(true)).called(1);
});
});

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

Expand Down

0 comments on commit 4ab2eb2

Please sign in to comment.