Skip to content

Commit

Permalink
refactor: use early returns
Browse files Browse the repository at this point in the history
  • Loading branch information
zOadT authored and shakiba committed Aug 4, 2023
1 parent c76525b commit 65eaf4d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 49 deletions.
7 changes: 3 additions & 4 deletions src/dynamics/joint/MouseJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,9 @@ export class MouseJoint extends Joint {
* Use this to update the target point.
*/
setTarget(target: Vec2Value): void {
if (!Vec2.areEqual(target, this.m_targetA)) {
this.m_bodyB.setAwake(true);
this.m_targetA = Vec2.clone(target);
}
if (Vec2.areEqual(target, this.m_targetA)) return;
this.m_bodyB.setAwake(true);
this.m_targetA = Vec2.clone(target);
}

getTarget(): Vec2 {
Expand Down
27 changes: 12 additions & 15 deletions src/dynamics/joint/PrismaticJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,33 +449,30 @@ export class PrismaticJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag != this.m_enableMotor) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}

/**
* Set the motor speed, usually in meters per second.
*/
setMotorSpeed(speed: number): void {
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}

/**
* Set the maximum motor force, usually in N.
*/
setMaxMotorForce(force: number): void {
if (force != this.m_maxMotorForce) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force;
}
if (force == this.m_maxMotorForce) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorForce = force;
}

getMaxMotorForce(): number {
Expand Down
27 changes: 12 additions & 15 deletions src/dynamics/joint/RevoluteJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,10 @@ export class RevoluteJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag != this.m_enableMotor) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}

/**
Expand All @@ -320,11 +319,10 @@ export class RevoluteJoint extends Joint {
* Set the motor speed in radians per second.
*/
setMotorSpeed(speed: number): void {
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}

/**
Expand All @@ -338,11 +336,10 @@ export class RevoluteJoint extends Joint {
* Set the maximum motor torque, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
if (torque != this.m_maxMotorTorque) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}
if (torque == this.m_maxMotorTorque) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}

getMaxMotorTorque(): number {
Expand Down
27 changes: 12 additions & 15 deletions src/dynamics/joint/WheelJoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,22 +314,20 @@ export class WheelJoint extends Joint {
* Enable/disable the joint motor.
*/
enableMotor(flag: boolean): void {
if (flag != this.m_enableMotor) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}
if (flag == this.m_enableMotor) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_enableMotor = flag;
}

/**
* Set the motor speed, usually in radians per second.
*/
setMotorSpeed(speed: number): void {
if (speed != this.m_motorSpeed) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}
if (speed == this.m_motorSpeed) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_motorSpeed = speed;
}

/**
Expand All @@ -343,11 +341,10 @@ export class WheelJoint extends Joint {
* Set/Get the maximum motor force, usually in N-m.
*/
setMaxMotorTorque(torque: number): void {
if (torque != this.m_maxMotorTorque) {
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}
if (torque == this.m_maxMotorTorque) return;
this.m_bodyA.setAwake(true);
this.m_bodyB.setAwake(true);
this.m_maxMotorTorque = torque;
}

getMaxMotorTorque(): number {
Expand Down

0 comments on commit 65eaf4d

Please sign in to comment.