From cd4fdbbd1fbe325e65ae9d59b16db5b1d6274dc1 Mon Sep 17 00:00:00 2001 From: samreid Date: Mon, 11 Sep 2017 09:13:25 -0600 Subject: [PATCH] Made TNumber nonparametric and moved range/units to NumberProperty, see https://github.com/phetsims/axon/issues/137 --- js/AtomIdentifier.js | 2 +- js/model/NumberAtom.js | 27 +++++++++++++++------------ js/model/Particle.js | 39 ++++++++++++++++----------------------- js/model/ParticleAtom.js | 18 ++++++++++++------ 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/js/AtomIdentifier.js b/js/AtomIdentifier.js index 090f95c..66470d9 100644 --- a/js/AtomIdentifier.js +++ b/js/AtomIdentifier.js @@ -756,7 +756,7 @@ define( function( require ) { }, getNumNeutronsInMostCommonIsotope: function( atomicNumber ) { - return numNeutronsInMostStableIsotope[ atomicNumber ]; + return numNeutronsInMostStableIsotope[ atomicNumber ] || 0; }, getStandardAtomicMass: function( numProtons ) { diff --git a/js/model/NumberAtom.js b/js/model/NumberAtom.js index d44e49a..b7f790d 100644 --- a/js/model/NumberAtom.js +++ b/js/model/NumberAtom.js @@ -10,11 +10,11 @@ define( function( require ) { 'use strict'; // modules - var AtomIdentifier = require( 'SHRED/AtomIdentifier' ); var DerivedProperty = require( 'AXON/DerivedProperty' ); var Emitter = require( 'AXON/Emitter' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var inherit = require( 'PHET_CORE/inherit' ); - var Property = require( 'AXON/Property' ); + var AtomIdentifier = require( 'SHRED/AtomIdentifier' ); var shred = require( 'SHRED/shred' ); var Tandem = require( 'TANDEM/Tandem' ); @@ -36,19 +36,19 @@ define( function( require ) { }, options ); // @public - this.protonCountProperty = new Property( options.protonCount, { + this.protonCountProperty = new NumberProperty( options.protonCount, { tandem: options.tandem.createTandem( 'protonCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ), - documentation: 'this property is updated by the model and should not be set by users' + documentation: 'this property is updated by the model and should not be set by users', + valueType: 'Integer' } ); - this.neutronCountProperty = new Property( options.neutronCount, { + this.neutronCountProperty = new NumberProperty( options.neutronCount, { tandem: options.tandem.createTandem( 'neutronCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ), + valueType: 'Integer', documentation: 'this property is updated by the model and should not be set by users' } ); - this.electronCountProperty = new Property( options.electronCount, { + this.electronCountProperty = new NumberProperty( options.electronCount, { tandem: options.tandem.createTandem( 'electronCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ), + valueType: 'Integer', documentation: 'this property is updated by the model and should not be set by users' } ); @@ -57,7 +57,8 @@ define( function( require ) { return protonCount - electronCount; }, { tandem: options.tandem.createTandem( 'chargeProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); @@ -66,7 +67,8 @@ define( function( require ) { return protonCount + neutronCount; }, { tandem: options.tandem.createTandem( 'massNumberProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); @@ -75,7 +77,8 @@ define( function( require ) { return protonCount + neutronCount + electronCount; }, { tandem: options.tandem.createTandem( 'particleCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); diff --git a/js/model/Particle.js b/js/model/Particle.js index 4ef17d6..c65e8df 100644 --- a/js/model/Particle.js +++ b/js/model/Particle.js @@ -9,15 +9,16 @@ define( function( require ) { 'use strict'; // modules - var inherit = require( 'PHET_CORE/inherit' ); + var NumberProperty = require( 'AXON/NumberProperty' ); var Property = require( 'AXON/Property' ); var Range = require( 'DOT/Range' ); - var ShredConstants = require( 'SHRED/ShredConstants' ); - var shred = require( 'SHRED/shred' ); - var Tandem = require( 'TANDEM/Tandem' ); - var Vector2 = require( 'DOT/Vector2' ); var TVector2 = require( 'DOT/TVector2' ); + var Vector2 = require( 'DOT/Vector2' ); + var inherit = require( 'PHET_CORE/inherit' ); var TParticle = require( 'SHRED/model/TParticle' ); + var shred = require( 'SHRED/shred' ); + var ShredConstants = require( 'SHRED/ShredConstants' ); + var Tandem = require( 'TANDEM/Tandem' ); // phet-io modules var TBoolean = require( 'ifphetio!PHET_IO/types/TBoolean' ); @@ -52,21 +53,14 @@ define( function( require ) { tandem: options.tandem && options.tandem.createTandem( 'destinationProperty' ), phetioValueType: TVector2 } ); - this.radiusProperty = new Property( - type === 'electron' ? ShredConstants.ELECTRON_RADIUS : ShredConstants.NUCLEON_RADIUS, - { - tandem: options.tandem && options.tandem.createTandem( 'radiusProperty' ), - phetioValueType: TNumber( { type: 'FloatingPoint' } ), - phetioInstanceDocumentation: 'changes to radius may not be reflected in view' - } - ); - this.animationVelocityProperty = new Property( DEFAULT_PARTICLE_VELOCITY, { + this.radiusProperty = new NumberProperty( type === 'electron' ? ShredConstants.ELECTRON_RADIUS : ShredConstants.NUCLEON_RADIUS, { + tandem: options.tandem && options.tandem.createTandem( 'radiusProperty' ), + phetioInstanceDocumentation: 'changes to radius may not be reflected in view' + } ); + this.animationVelocityProperty = new NumberProperty( DEFAULT_PARTICLE_VELOCITY, { tandem: options.tandem && options.tandem.createTandem( 'animationVelocityProperty' ), - phetioValueType: TNumber( { - type: 'FloatingPoint', - range: new Range( 0, 10 * DEFAULT_PARTICLE_VELOCITY ), // limited for instance proxies, code can handle any value - units: 'view-coordinates/second' - } ) + range: new Range( 0, 10 * DEFAULT_PARTICLE_VELOCITY ), // limited for instance proxies, code can handle any value + units: 'view-coordinates/second' } ); this.userControlledProperty = new Property( false, { tandem: options.tandem && options.tandem.createTandem( 'userControlledProperty' ), @@ -77,10 +71,9 @@ define( function( require ) { return value >= 0 && value <= options.maxZLayer; }, tandem: options.tandem && options.tandem.createTandem( 'zLayerProperty' ), - phetioValueType: TNumber( { - type: 'Integer', - range: new Range( 0, options.maxZLayer ) - } ) + valueType: 'Integer', + range: new Range( 0, options.maxZLayer ), + phetioValueType: TNumber } ); // Used in view, integer value, higher means further back. options.tandem.addInstance( this, TParticle ); diff --git a/js/model/ParticleAtom.js b/js/model/ParticleAtom.js index 2e58ec1..4c52c25 100644 --- a/js/model/ParticleAtom.js +++ b/js/model/ParticleAtom.js @@ -85,7 +85,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'protonCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); this.neutronCountProperty = new DerivedProperty( @@ -95,7 +96,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'neutronCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); this.electronCountProperty = new DerivedProperty( @@ -105,7 +107,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'electronCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); this.chargeProperty = new DerivedProperty( @@ -115,7 +118,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'chargeProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); this.massNumberProperty = new DerivedProperty( @@ -125,7 +129,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'massNumberProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } ); this.particleCountProperty = new DerivedProperty( @@ -135,7 +140,8 @@ define( function( require ) { }, { tandem: options.tandem.createTandem( 'particleCountProperty' ), - phetioValueType: TNumber( { type: 'Integer' } ) + valueType: 'Integer', + phetioValueType: TNumber } );