Skip to content

Commit

Permalink
Add JSDoc throughout, fix some formatting issues, and consolidate some
Browse files Browse the repository at this point in the history
documentation, see issue #27
  • Loading branch information
jessegreenberg committed Sep 23, 2015
1 parent 87ef161 commit 9978728
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 159 deletions.
128 changes: 97 additions & 31 deletions js/trig-tour/model/TrigTourModel.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright 2002-2015, University of Colorado Boulder
// Copyright 2002-2015, University of Colorad5o Boulder

/**
* Main model for Trig Tour Sim
*
* @author Michael Dubson (PhET)
*/
define( function( require ) {
Expand All @@ -13,34 +14,53 @@ define( function( require ) {
var Util = require( 'DOT/Util' );

/**
* Constructor for TrigTourModel.
*
* @constructor
* No parameter
*/
function TrigTourModel() {

// @public
PropertySet.call( this, {
angle: 0, // @public, total angle in radians, can be greater than 2*pi, or less than -2*pi
singularity: false // @public, indicates singularity in tan function at theta = +/- 90 degrees
angle: 0, // total angle in radians, can be greater than 2*pi, or less than -2*pi
singularity: false // indicates singularity in tan function at theta = +/- 90 degrees
// true if angle is close to +/-90 degrees
} );
this.smallAngle = 0; // @private, smallAngle = angle modulo 2*pi with 180 offset, is between -pi and +pi

this.smallAngle = 0; // @private, angle modulo 2*pi with 180 offset, is between -pi and +pi
this.previousAngle = 0; // @private, smallAngle in previous step, needed to compute total angle from smallAngle
this.rotationNumberFromPi = 0; //@private, nbr of turns around the unit circle, incremented at +/-180 deg,
this.rotationNumberFromPi = 0; //@private, number of turns around the unit circle, incremented at +/-180 deg,
//needed to compute (full) angle from smallAngle
this.fullTurnCount = 0; // @public, nbr of turns around unit circle, incremented at angle = 0 deg
this.halfTurnCount = 0; // @public, nbr of half turns around unit circle, incremented at small angle = 0 and 180
this.fullTurnCount = 0; // @public, number of turns around unit circle, incremented at angle = 0 deg
this.halfTurnCount = 0; // @public, number of half turns around unit circle, incremented at small angle = 0 and 180
}

return inherit( PropertySet, TrigTourModel, {

/**
* Returns cos of the total model angle in radians.
*
* @returns {number}
*/
cos: function() {
return Math.cos( this.angle );
},

/**
* Returns sin of the total model angle in radians.
*
* @returns {number}
*/
sin: function() {
return Math.sin( this.angle );
},

//Returns tangent of current angle. But when near +/-90 degrees, cuts off tan value at +/- maxValue.
//Must cut off value at +/- maxValue or else Safari Browser won't display properly.
/**
* Returns tangent of current model angle in radians. When near +/-90 degrees, cuts off tan value at +/- maxValue.
* Must cut off value at +/- maxValue or else Safari Browser won't display properly.
*
* @returns {number}
*/
tan: function() {
var tanValue = Math.tan( this.angle );
var maxValue = 350;
Expand All @@ -60,37 +80,65 @@ define( function( require ) {
return returnValue;
},

/**
* Get the current model angle in radians.
*
* @returns {number}
*/
getAngleInRadians: function() {
return this.angle;
},

/**
* Get the current model angle in degress.
*
* @returns {number}
*/
getAngleInDegrees: function() {
return this.angle * 180 / Math.PI;
return Util.toDegrees( this.angle );
},

//small angle in rads, between -pi and +pi
/**
* Returns the small angle in radians, between -pi and +pi
*
* @returns {number}
*/
getSmallAngleInRadians: function() {
return this.smallAngle;
},

//small angle in degrees between -180 and +180
/**
* Return the small angle in degrees between -180 and +180.
*
* @returns {number}
*/
getSmallAngleInDegrees: function() {
return this.smallAngle * 180 / Math.PI;
return Util.toDegrees( this.smallAngle );
},

//small angle in degrees 0 to +360
/**
* Convenience function, return the small angle in degrees bound by 0 to +360
*
* @returns {number}
*/
getSmallAngle0To360: function() {
if ( this.smallAngle > 0 ) {
return this.smallAngle * 180 / Math.PI;
return Util.toDegrees( this.smallAngle );
}
else {
return 360 + this.smallAngle * 180 / Math.PI;
return 360 + Util.toDegrees( this.smallAngle );
}
},

//set the full angle, the small angle and various turns counts, given the current full angle
setFullAngleInRadians: function( angleInRads ) { //argument is total angle, not small angle
/**
* Set the full angle, small angle, and various turns counts.
*
* @param {number} angleInRads - a new angle for the full model angle
*/
setFullAngleInRadians: function( angleInRads ) {
var remainderAngle = angleInRads % ( 2 * Math.PI );
this.fullTurnCount = Util.roundSymmetric( ( angleInRads - remainderAngle ) / (2 * Math.PI ) );
this.fullTurnCount = Util.roundSymmetric( ( angleInRads - remainderAngle ) / ( 2 * Math.PI ) );

if ( Math.abs( remainderAngle ) <= Math.PI ) {
this.rotationNumberFromPi = this.fullTurnCount;
}
Expand All @@ -108,18 +156,25 @@ define( function( require ) {
this.angle = angleInRads;
},

//set the full angle, and various turns counts, given the current small angle
setAngle: function( smallAngle ) { //smallAngle in rads
/**
* Set the full angle, and various turn counts, given the current small angle.
*
* @param {number} smallAngle
*/
setAngle: function( smallAngle ) {
this.smallAngle = smallAngle;
var comparisonAngle = 149 * Math.PI / 180; //must be less than (180-30)deg in order to handle special angle correctly

//must be less than (180-30)deg in order to handle special angle correctly
var comparisonAngle = 149 * Math.PI / 180;
if ( ( this.smallAngle < 0 ) && (this.previousAngle > comparisonAngle) ) {
this.rotationNumberFromPi += 1;
}
else if ( this.smallAngle > 0 && this.previousAngle < -comparisonAngle ) {
this.rotationNumberFromPi -= 1;
}

var targetAngle = this.rotationNumberFromPi * 2 * Math.PI + this.smallAngle; //don't want to trigger angle update yet
//don't want to trigger angle update yet
var targetAngle = this.rotationNumberFromPi * 2 * Math.PI + this.smallAngle;

//round to nearest half-degree; to do this, must convert to degrees and then back to rads
var roundedTargetAngle = targetAngle * 180 / Math.PI;
Expand All @@ -128,15 +183,21 @@ define( function( require ) {
roundedTargetAngle = Util.roundSymmetric( roundedTargetAngle * roundFactor ) / roundFactor;
targetAngle = roundedTargetAngle * Math.PI / 180;
var remainderAngle = targetAngle % ( 2 * Math.PI );

// set turn counts and angles
this.fullTurnCount = Util.roundSymmetric( ( targetAngle - remainderAngle ) / ( 2 * Math.PI ) );
remainderAngle = targetAngle % ( Math.PI );
this.halfTurnCount = Util.roundSymmetric( ( targetAngle - remainderAngle ) / ( Math.PI ) );
this.angle = targetAngle; //now can trigger angle update
this.previousAngle = smallAngle;
},

//given the small angle in rads, sets current angle to nearest special angle in rads; called from UnitCircleView
setSpecialAngleWithSmallAngle: function( smallAngle ) { //smallAngle in rads
/**
* Given the small angle in radians, set the current angle to nearest special angle in radians.
*
* @param {number} smallAngle - small angle in radians
*/
setSpecialAngleWithSmallAngle: function( smallAngle ) {
var smallAngleInDegs = smallAngle * 180 / Math.PI;
var nearestSpecialAngleInRads = 0;
var specialAngles = [ -150, -135, -120, -90, -60, -45, -30, 0, 30, 45, 60, 90, 120, 135, 150, 180 ];
Expand All @@ -155,9 +216,12 @@ define( function( require ) {
this.setAngle( nearestSpecialAngleInRads );
},


//Given the full angle, set angle to the nearest special angle; called from GraphView
setSpecialAngleWithFullAngle: function( fullAngle ) { //full angle in radians
/**
* Given the full angle, set angle to the nearest special angle.
*
* @param {number} fullAngle - full angle in radians
*/
setSpecialAngleWithFullAngle: function( fullAngle ) {
var remainderAngle = fullAngle % ( 2 * Math.PI );
var fullTurnsAngle = fullAngle - remainderAngle;
var remainderInDegrees = remainderAngle * 180 / Math.PI;
Expand All @@ -171,12 +235,13 @@ define( function( require ) {

for ( var i = 0; i <= specialAngles.length - 1; i++ ) {
if ( remainderInDegrees >= borders[ i ] && remainderInDegrees < borders[ i + 1 ] ) {
nearestSpecialAngleInDegrees = specialAngles[ i + 1 ];// * Math.PI / 180;
nearestSpecialAngleInDegrees = specialAngles[ i + 1 ];
}
if ( remainderInDegrees <= -borders[ i ] && remainderInDegrees > -borders[ i + 1 ] ) {
nearestSpecialAngleInDegrees = -specialAngles[ i + 1 ];// * Math.PI / 180;
nearestSpecialAngleInDegrees = -specialAngles[ i + 1 ];
}
}

//Must handle 0 and +/-360 deg angles as special cases.
if ( remainderInDegrees < 15 && remainderInDegrees >= -15 ) {
nearestSpecialAngleInDegrees = 0;
Expand All @@ -187,6 +252,7 @@ define( function( require ) {
else if ( remainderInDegrees < -345 ) {
nearestSpecialAngleInDegrees = -360;
}

var nearestSpecialAngleInRadians = nearestSpecialAngleInDegrees * Math.PI / 180;
var nearestFullAngle = fullTurnsAngle + nearestSpecialAngleInRadians;
this.setFullAngleInRadians( nearestFullAngle );
Expand Down
20 changes: 10 additions & 10 deletions js/trig-tour/view/ArrowLine.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// Copyright 2002-2015, University of Colorado Boulder

/**
* Vertical or horizontal arrow,
* consisting of a line and a triangular arrow-head,
* used in UnitCircleView and GraphView
* Created by Michael Dubson (PhET developer) on 6/16/2015.
* Vertical or horizontal arrow, consisting of a line and a triangular arrow-head.
*
* @author Michael Dubson (PhET developer) on 6/16/2015.
*/

define( function( require ) {
'use strict';

Expand All @@ -20,16 +18,18 @@ define( function( require ) {
var Util = require( 'DOT/Util' );

/**
* Constructor for ArrowLine which renders rotor as a scenery node.
* @param {Number} defaultLength of arrow in pixels
* @param {String} orientation = 'v' or 'h' for vertical or horizontal
* @param {Object} options passed to Line, plus extra options
* Constructor for ArrowLine which is an arrow node with a head that dynamically resizes to a fraction of the tail
* length.
*
* @param {number} defaultLength of arrow in pixels
* @param {string} orientation = 'v' or 'h' for vertical or horizontal
* @param {object} options passed to Line, plus extra options
* @constructor
*/
function ArrowLine( defaultLength, orientation, options ) {

var arrowLine = this;
this.vertical = ( orientation === 'v' );
this.vertical = ( orientation === 'v' ); // @private
options = _.extend( {
//if arrow length shorter than criticalFactor times arrow head length, then start scaling arrowLine
criticalFactor: 2,
Expand Down
40 changes: 20 additions & 20 deletions js/trig-tour/view/ControlPanel.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// Copyright 2002-2015, University of Colorado Boulder

/**
* Control Panel for Trig Tour sim
* on right side of stage
* Created by Michael Dubson (PhET developer) on 6/4/2015.
* Control Panel for Trig Tour sim, on right side of screenView
*
* @author Michael Dubson (PhET developer) on 6/4/2015.
*/
define( function( require ) {
'use strict';
Expand All @@ -17,6 +17,12 @@ define( function( require ) {
var PhetFont = require( 'SCENERY_PHET/PhetFont' );
var Text = require( 'SCENERY/nodes/Text' );
var VBox = require( 'SCENERY/nodes/VBox' );
var TrigTourColors = require( 'TRIG_TOUR/trig-tour/view/TrigTourColors' );

// constants
var DISPLAY_FONT = new PhetFont( 20 );
var TEXT_COLOR = TrigTourColors.TEXT_COLOR;
var PANEL_COLOR = TrigTourColors.PANEL_COLOR;

//strings
var cosStr = require( 'string!TRIG_TOUR/cos' );
Expand All @@ -25,12 +31,6 @@ define( function( require ) {
var labelsStr = require( 'string!TRIG_TOUR/labels' );
var gridStr = require( 'string!TRIG_TOUR/grid' );
var specialAnglesStr = require( 'string!TRIG_TOUR/specialAngles' );
var TrigTourColors = require( 'TRIG_TOUR/trig-tour/view/TrigTourColors' );

// constants
var DISPLAY_FONT = new PhetFont( 20 );
var TEXT_COLOR = TrigTourColors.TEXT_COLOR;
var PANEL_COLOR = TrigTourColors.PANEL_COLOR;

// Text nodes
var fontInfo = { font: DISPLAY_FONT, fill: TEXT_COLOR };
Expand All @@ -41,30 +41,30 @@ define( function( require ) {
var gridText = new Text( gridStr, fontInfo );
var specialAnglesText = new Text( specialAnglesStr, fontInfo );


/**
* Constructor for the control panel
* @param {Object} properties
*
* @param {ViewProperties} viewProperties
* @constructor
*/
function ControlPanel( properties ) {
function ControlPanel( viewProperties ) {

this.properties = properties;
this.viewProperties = viewProperties;

//A cluster of 3 radio buttons for displaying either cos, sin or tan
//properties.graph = 'cos'|'sin'|'tan'
//viewProperties.graph = 'cos'|'sin'|'tan'
var myRadioButtonOptions = { radius: 10, fontSize: 15, deselectedColor: 'white' };
var cosRadioButton = new AquaRadioButton( properties.graphProperty, 'cos', cosText, myRadioButtonOptions );
var sinRadioButton = new AquaRadioButton( properties.graphProperty, 'sin', sinText, myRadioButtonOptions );
var tanRadioButton = new AquaRadioButton( properties.graphProperty, 'tan', tanText, myRadioButtonOptions );
var cosRadioButton = new AquaRadioButton( viewProperties.graphProperty, 'cos', cosText, myRadioButtonOptions );
var sinRadioButton = new AquaRadioButton( viewProperties.graphProperty, 'sin', sinText, myRadioButtonOptions );
var tanRadioButton = new AquaRadioButton( viewProperties.graphProperty, 'tan', tanText, myRadioButtonOptions );

//3 checkboxes: Labels, Grid, Special Angles
var checkBoxOptions = { checkBoxColorBackground: 'white' };
var labelsCheckBox = new CheckBox( labelsText, properties.labelsVisibleProperty, checkBoxOptions );
var gridCheckBox = new CheckBox( gridText, properties.gridVisibleProperty, checkBoxOptions );
var labelsCheckBox = new CheckBox( labelsText, viewProperties.labelsVisibleProperty, checkBoxOptions );
var gridCheckBox = new CheckBox( gridText, viewProperties.gridVisibleProperty, checkBoxOptions );
var specialAnglesCheckBox = new CheckBox(
specialAnglesText,
properties.specialAnglesVisibleProperty,
viewProperties.specialAnglesVisibleProperty,
checkBoxOptions
);

Expand Down
Loading

0 comments on commit 9978728

Please sign in to comment.