Skip to content

Commit

Permalink
when ratio is locked, you don't need a trend of values to calculate v…
Browse files Browse the repository at this point in the history
…elocity, #360
  • Loading branch information
zepumph committed Mar 2, 2021
1 parent ff00707 commit 74121a0
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions js/common/model/RAPRatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ class RAPRatio {
phetioType: Property.PropertyIO( RAPRatioTuple.RAPRatioTupleIO )
} );

// @private
this.antecedentVelocityTracker = new VelocityTracker();
this.consequentVelocityTracker = new VelocityTracker();

// @public - when true, moving one ratio value will maintain the current ratio by updating the other value Property
this.lockedProperty = new BooleanProperty( false, { tandem: tandem.createTandem( 'lockedProperty' ) } );

// @private
this.antecedentVelocityTracker = new VelocityTracker( this.lockedProperty );
this.consequentVelocityTracker = new VelocityTracker( this.lockedProperty );

// @public - if the ratio is in the "moving in direction" state: whether or not the two hands are moving fast
// enough together in the same direction. This indicates, among other things a bimodal interaction.
this.movingInDirectionProperty = new DerivedProperty( [
Expand Down Expand Up @@ -234,7 +234,10 @@ class RAPRatio {

// Private class to keep details about tracking the velocity of each ratio term encapsulated.
class VelocityTracker {
constructor() {
constructor( ratioLockedProperty ) {

// @private
this.ratioLockedProperty = ratioLockedProperty;

// @private - keep track of previous values to calculate the change, only unique values are appended to this
this.previousValues = [];
Expand All @@ -244,7 +247,8 @@ class VelocityTracker {
// is determined by STEP_FRAME_GRANULARITY.
this.currentVelocityProperty = new NumberProperty( 0 );

this.stepCountTracker = 0; // Used for keeping track of how often dVelocity is checked.
// @private - Used for keeping track of how often dVelocity is checked.
this.stepCountTracker = 0;
}

/**
Expand Down Expand Up @@ -276,8 +280,9 @@ class VelocityTracker {

// There must be at least VELOCITY_MEMORY number of unique values (VELOCITY_MEMORY-1 number of changes) in order
// to have velocity in this model. This doesn't account for the case in which you change from A -> B -> A, but that
// is acceptable for our particular case since this velocity is very directional.
if ( this.previousValues.length >= VELOCITY_MEMORY && _.uniq( this.previousValues ).length >= VELOCITY_MEMORY ) {
// is acceptable for our particular case since this velocity is very directional. When locked
if ( this.previousValues.length >= VELOCITY_MEMORY &&
( _.uniq( this.previousValues ).length >= VELOCITY_MEMORY || this.ratioLockedProperty.value ) ) {
this.currentVelocityProperty.value = this.previousValues[ this.previousValues.length - 1 ] - this.previousValues[ 0 ];
}
else {
Expand Down

0 comments on commit 74121a0

Please sign in to comment.