Skip to content

Commit

Permalink
Merge branch 'master' into preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
zepumph committed May 7, 2021
2 parents ff895fd + 01e4010 commit f493080
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 137 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.idea/
build/
build-phet-io-api/
node_modules/
*.iml
.DS_Store
Expand Down
62 changes: 31 additions & 31 deletions dependencies.json
Original file line number Diff line number Diff line change
@@ -1,107 +1,107 @@
{
"comment": "# ratio-and-proportion 1.1.0-preferences.1 Tue Apr 27 2021 18:07:45 GMT-0800 (Alaska Daylight Time)",
"comment": "# ratio-and-proportion 1.1.0-dev.11 Fri Apr 30 2021 13:02:27 GMT-0800 (Alaska Daylight Time)",
"assert": {
"sha": "423d662a3672e3de42852ee6d6fdec705ac98dd5",
"sha": "1820bb58c7c5cfd5e3dca0043ba4cc8c9c80fb42",
"branch": "master"
},
"axon": {
"sha": "a0a82670922be91f20faca8223af68c2c580eeff",
"sha": "d8fbd0284be6972f501b3450ca451f3e4b6aab0f",
"branch": "master"
},
"brand": {
"sha": "0bbc0a38a8526ce83961f05afdd62c54c52d0598",
"sha": "34245e01d6a1031dd6cb3cad400d3d56368acaea",
"branch": "master"
},
"chipper": {
"sha": "338f4d2358c16eb79b6c2b8bcaae50f30b861bd7",
"sha": "ae21ede418ce0f8313940604d70ca035fb446841",
"branch": "master"
},
"dot": {
"sha": "a169119af94214488251620363253acafa01a39d",
"sha": "edece2944d45157d241d62e1d1e0e11c2c40e3dc",
"branch": "master"
},
"griddle": {
"sha": "c3b258de46b4f33c378178dabc8c462654e762ea",
"sha": "16c7db5a2089a79de71549643cf8eee9bd5a1be3",
"branch": "master"
},
"joist": {
"sha": "db14fb7fefd7104c034bd025a8e538dbff6d53f2",
"branch": "preferences"
"sha": "4c0954c185bc3acb5625eb80d1e438b0758e9ca3",
"branch": "master"
},
"kite": {
"sha": "92bcdf54e64e8f0a8f6da4c8f67d7ca8b6d07a59",
"sha": "eb134ead250454d4bbbe6cd83b909ba28ff83f7d",
"branch": "master"
},
"phet-core": {
"sha": "1c57e441cce0cb5074855224ebc324dcbbcd4c70",
"sha": "064c34073bb0eefad679b35ed124596858b98d77",
"branch": "master"
},
"phet-io": {
"sha": "2dfc6f54f83c6d40f414a186a261c1b23f4b8dd1",
"sha": "001a6d9d2832aa431e731f2f2dcf4e0984792298",
"branch": "master"
},
"phet-io-client-guides": {
"sha": "6aaf84728c95068d75656674d330242a73e8cb61",
"sha": "346871673bfd4f45581bb93b290e27739eae013f",
"branch": "master"
},
"phet-io-wrappers": {
"sha": "ed674a3de78f45cec323b0e6b994f64d0d52c077",
"sha": "060b8d5836e6c2ea19a1899d71859792083d00b2",
"branch": "master"
},
"phetcommon": {
"sha": "6b667aab3691469e423abdf2fd7ad4d0ce7ad8df",
"sha": "c55ab48df2cd59a092603a4047ce979d5003e7db",
"branch": "master"
},
"phetmarks": {
"sha": "2ff2d6d0058c53d95ae064e282cff3fc2094f8b5",
"sha": "11103e4aa87f0f3ddcb6877f43e9a3f96a00adb4",
"branch": "master"
},
"query-string-machine": {
"sha": "090c44b0ba8e0a7effd2f6a7830f35eac92d59cc",
"sha": "b9bc26fe6c949a0353a003c454e15eba5141ac7d",
"branch": "master"
},
"ratio-and-proportion": {
"sha": "eaebd78118a9fa9d7b0a752922229fe31b79b1a6",
"branch": "preferences"
"sha": "7c891323b014fa146b04ed5a04fef730b94e9920",
"branch": "master"
},
"scenery": {
"sha": "32514cee5c0aa98462fddf23ec0d8f53a5940b45",
"sha": "69220950bad3891beb0e4016a065938008c1c816",
"branch": "master"
},
"scenery-phet": {
"sha": "f191d28dede668bcb7dd02738e7bac81094ac742",
"sha": "36bd3946b0e3b95a672bb6d13cc070207ca74f84",
"branch": "master"
},
"sherpa": {
"sha": "f6b2ee4d7039bdf1757dbbce88cfaa8b43dd667d",
"sha": "4d63708c1686faa73f9a62b876b2a0943204252e",
"branch": "master"
},
"studio": {
"sha": "c6f4728e6a5ef6b69640c9152090a910788a0fd9",
"sha": "dcf1fe68e68b978a852c381e8d665d777f321ca2",
"branch": "master"
},
"sun": {
"sha": "1ebd40455451252ca6f7e8a680cdab6c67363c8f",
"branch": "preferences"
"sha": "1c65b742f539ae32e4cfc4ebd0410470dcb7c3d8",
"branch": "master"
},
"tambo": {
"sha": "39ab871e99f3cd5069568ae7bbb94932ffa1eb73",
"branch": "preferences"
"sha": "bbc6e6f4f33a1a7b93bea4bd6625d77406a0819f",
"branch": "master"
},
"tandem": {
"sha": "7362dcda687ee669c6ab9067a66274810e3b52e8",
"sha": "403bcefb0960b97ae10c346b54163838a17fe120",
"branch": "master"
},
"tangible": {
"sha": "dd9ccbc2fb5f02470471650a4cda499d18655864",
"sha": "a56aa82f7f617748b19d2f5d8401028782b444e4",
"branch": "master"
},
"twixt": {
"sha": "141f9a395def6a3e5da48cac968bcea70ee20331",
"sha": "56b97dd8ed186f4276310dd351beeab623318380",
"branch": "master"
},
"utterance-queue": {
"sha": "30ffcbd69fd2e8a0b3f53386974812c5071b2860",
"sha": "35ec385a6ef4b6515024277ea1befb125fb8e3dd",
"branch": "master"
}
}
45 changes: 0 additions & 45 deletions js/common/RAPConstants.js

This file was deleted.

34 changes: 19 additions & 15 deletions js/common/model/RAPModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import DerivedProperty from '../../../../axon/js/DerivedProperty.js';
import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Utils from '../../../../dot/js/Utils.js';
import Vector2 from '../../../../dot/js/Vector2.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import NumberIO from '../../../../tandem/js/types/NumberIO.js';
import ratioAndProportion from '../../ratioAndProportion.js';
import RAPConstants from '../RAPConstants.js';
import rapConstants from '../rapConstants.js';
import RAPRatio from './RAPRatio.js';
import RatioTerm from './RatioTerm.js';

Expand All @@ -29,7 +30,7 @@ const MIN_CLAMPED_FITNESS_DISTANCE = 0.08944271909999162 / 0.5;
// usability with small ratios, see https://github.com/phetsims/ratio-and-proportion/issues/369
const MINIMUM_DISTANCE_FORCES_IN_PROPORTION = 0.001;

const TOTAL_RANGE = RAPConstants.TOTAL_RATIO_TERM_VALUE_RANGE;
const TOTAL_RANGE = rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE;

class RAPModel {

Expand Down Expand Up @@ -74,7 +75,7 @@ class RAPModel {

// In this case, the normal model behavior looks buggy because both values are equal, but still in proportion.
this.ratioEvenButNotAtTarget() ) ) {
unclampedFitness = RAPConstants.RATIO_FITNESS_RANGE.max - this.getInProportionThreshold() - 0.01;
unclampedFitness = rapConstants.RATIO_FITNESS_RANGE.max - this.getInProportionThreshold() - 0.01;
}

phet.log && phet.log( `
Expand All @@ -89,7 +90,7 @@ unclampedFitness: ${unclampedFitness}

return unclampedFitness;
}, {
isValidValue: value => value <= RAPConstants.RATIO_FITNESS_RANGE.max,
isValidValue: value => value <= rapConstants.RATIO_FITNESS_RANGE.max,

// phet-io
tandem: tandem.createTandem( 'unclampedFitnessProperty' ),
Expand All @@ -106,15 +107,18 @@ unclampedFitness: ${unclampedFitness}
// is preferable to the unclampedFitnessProperty because it is normalized, and simpler when comparing the current ratio
// to the target ratio.
this.ratioFitnessProperty = new DerivedProperty( [ this.unclampedFitnessProperty ],
unclampedFitness => Utils.clamp( unclampedFitness, RAPConstants.RATIO_FITNESS_RANGE.min, RAPConstants.RATIO_FITNESS_RANGE.max ), {
isValidValue: value => RAPConstants.RATIO_FITNESS_RANGE.contains( value )
unclampedFitness => Utils.clamp( unclampedFitness, rapConstants.RATIO_FITNESS_RANGE.min, rapConstants.RATIO_FITNESS_RANGE.max ), {
isValidValue: value => rapConstants.RATIO_FITNESS_RANGE.contains( value )
} );

// @public - whether or not the model is in its "in proportion" state.
this.inProportionProperty = new DerivedProperty( [
this.unclampedFitnessProperty,
this.ratio.movingInDirectionProperty
], this.inProportion.bind( this ) );
], this.inProportion.bind( this ), {
tandem: tandem.createTandem( 'inProportionProperty' ),
phetioType: DerivedProperty.DerivedPropertyIO( BooleanIO )
} );

// This must be done here, because of the reentrant nature of how fitness changes when the ratio is locked
this.targetRatioProperty.link( () => {
Expand All @@ -134,7 +138,7 @@ unclampedFitness: ${unclampedFitness}
* larger term value. Thus moving the consequent when the target ratio is 1/2 will yield identical fitness to moving the
* antecedent when the target ratio is 2.
*
* (see RAPConstants.TOTAL_RATIO_TERM_VALUE_RANGE).
* (see rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE).
* @param {number} antecedent
* @param {number} consequent
* @param {number} targetRatio
Expand All @@ -160,7 +164,7 @@ unclampedFitness: ${unclampedFitness}
// for small displays that may not have as much granularity for very small or very large ratios.
if ( Math.abs( antecedent - idealAntecedent ) < MINIMUM_DISTANCE_FORCES_IN_PROPORTION ||
Math.abs( consequent - idealConsequent ) < MINIMUM_DISTANCE_FORCES_IN_PROPORTION ) {
return RAPConstants.RATIO_FITNESS_RANGE.max;
return rapConstants.RATIO_FITNESS_RANGE.max;
}

// Calculate the inverse slope from the current target ratio.
Expand All @@ -176,7 +180,7 @@ unclampedFitness: ${unclampedFitness}
// Find the distance between the current ratio, and the calculated intersection with the target ratio function.
const distanceFromTarget = new Vector2( consequent, antecedent ).distance( pointOnTarget );

return RAPConstants.RATIO_FITNESS_RANGE.max - ( RAPConstants.RATIO_FITNESS_RANGE.max * distanceFromTarget ) / ( MIN_CLAMPED_FITNESS_DISTANCE * targetRatio );
return rapConstants.RATIO_FITNESS_RANGE.max - ( rapConstants.RATIO_FITNESS_RANGE.max * distanceFromTarget ) / ( MIN_CLAMPED_FITNESS_DISTANCE * targetRatio );
}

/**
Expand All @@ -201,18 +205,18 @@ unclampedFitness: ${unclampedFitness}
*/
valuesTooSmallForInProportion() {
const currentTuple = this.ratio.tupleProperty.value;
return currentTuple.antecedent < RAPConstants.NO_SUCCESS_VALUE_THRESHOLD ||
currentTuple.consequent < RAPConstants.NO_SUCCESS_VALUE_THRESHOLD;
return currentTuple.antecedent < rapConstants.NO_SUCCESS_VALUE_THRESHOLD ||
currentTuple.consequent < rapConstants.NO_SUCCESS_VALUE_THRESHOLD;
}

/**
* @public
* @returns {number}
*/
getInProportionThreshold() {
let threshold = RAPConstants.IN_PROPORTION_FITNESS_THRESHOLD;
let threshold = rapConstants.IN_PROPORTION_FITNESS_THRESHOLD;
if ( this.ratio.movingInDirectionProperty.value ) {
threshold = RAPConstants.MOVING_IN_PROPORTION_FITNESS_THRESHOLD;
threshold = rapConstants.MOVING_IN_PROPORTION_FITNESS_THRESHOLD;
}
return threshold;
}
Expand All @@ -225,7 +229,7 @@ unclampedFitness: ${unclampedFitness}
* @returns {boolean}
*/
inProportion( fitness = this.ratioFitnessProperty.value ) {
return fitness > RAPConstants.RATIO_FITNESS_RANGE.max - this.getInProportionThreshold();
return fitness > rapConstants.RATIO_FITNESS_RANGE.max - this.getInProportionThreshold();
}

/**
Expand Down
12 changes: 8 additions & 4 deletions js/common/model/RAPRatio.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import NumberProperty from '../../../../axon/js/NumberProperty.js';
import Property from '../../../../axon/js/Property.js';
import Range from '../../../../dot/js/Range.js';
import Utils from '../../../../dot/js/Utils.js';
import BooleanIO from '../../../../tandem/js/types/BooleanIO.js';
import ratioAndProportion from '../../ratioAndProportion.js';
import RAPConstants from '../RAPConstants.js';
import rapConstants from '../rapConstants.js';
import RAPRatioTuple from './RAPRatioTuple.js';

// The threshold for velocity of a moving ratio value to indicate that it is "moving."
Expand All @@ -26,11 +27,11 @@ const STEP_FRAME_GRANULARITY = 30;
// How many values must be different within the STEP_FRAME_GRANULARITY number of frames to trigger a velocity calculation.
const VELOCITY_MEMORY = 3;

const DEFAULT_TERM_VALUE_RANGE = RAPConstants.TOTAL_RATIO_TERM_VALUE_RANGE;
const DEFAULT_TERM_VALUE_RANGE = rapConstants.TOTAL_RATIO_TERM_VALUE_RANGE;

// Use the same value as the no-success region threshold. This cannot be the same as the no-success threshold though
// because that threshold value, by definition, will unlock the ratio, see https://github.com/phetsims/ratio-and-proportion/issues/257#issuecomment-748285667
const LOCK_RATIO_RANGE_MIN = RAPConstants.NO_SUCCESS_VALUE_THRESHOLD + Number.EPSILON;
const LOCK_RATIO_RANGE_MIN = rapConstants.NO_SUCCESS_VALUE_THRESHOLD + Number.EPSILON;

class RAPRatio {

Expand Down Expand Up @@ -85,6 +86,9 @@ class RAPRatio {

// Ignore the speed component when the ratio is locked
return bothMoving && movingInSameDirection && ( movingFastEnough || ratioLocked );
}, {
tandem: tandem.createTandem( 'movingInDirectionProperty' ),
phetioType: DerivedProperty.DerivedPropertyIO( BooleanIO )
} );

// @private - To avoid an infinite loop as setting the tupleProperty from inside its lock-ratio-support
Expand All @@ -107,7 +111,7 @@ class RAPRatio {
if ( this.enabledRatioTermsRangeProperty.value.contains( oldTuple.antecedent ) &&
this.enabledRatioTermsRangeProperty.value.contains( oldTuple.consequent ) &&
antecedentChanged && consequentChanged ) {
assert && assert( RAPConstants.toFixed( tuple.getRatio() ) === RAPConstants.toFixed( oldTuple.getRatio() ), // eslint-disable-line bad-sim-text
assert && assert( rapConstants.toFixed( tuple.getRatio() ) === rapConstants.toFixed( oldTuple.getRatio() ), // eslint-disable-line bad-sim-text
'if both values change while locked, the ratio should be maintained.' );
}

Expand Down
2 changes: 1 addition & 1 deletion js/common/model/RAPRatioTuple.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class RAPRatioTuple {
* @param {Object} stateObject see toStateObject
* @returns {RAPRatioTuple}
*/
fromStateObject( stateObject ) {
static fromStateObject( stateObject ) {
return new RAPRatioTuple( stateObject.antecedent, stateObject.consequent );
}
}
Expand Down
Loading

0 comments on commit f493080

Please sign in to comment.