Skip to content

Commit

Permalink
clean up formatting, comments, JSDoc, etc. #154
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelzoom committed Sep 15, 2021
1 parent 8461e4c commit 597db17
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 98 deletions.
16 changes: 6 additions & 10 deletions js/lens/LensScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ class LensScreen extends Screen {
constructor() {

// create convex lens for home screen icon
const iconNode = CurveControl.createIconNode(
Optic.Curve.CONVEX,
Optic.Type.LENS,
{
radius: 20,
diameter: 30,
outline: { stroke: 'black' }
} );
const iconNode = CurveControl.createIconNode( Optic.Curve.CONVEX, Optic.Type.LENS, {
radius: 20,
diameter: 30,
outline: { stroke: 'black' }
} );

const options = {

name: geometricOpticsStrings.screen.lens,
homeScreenIcon: new ScreenIcon( iconNode ),
backgroundColorProperty: GeometricOpticsColors.screenBackgroundColorProperty
Expand All @@ -44,4 +40,4 @@ class LensScreen extends Screen {
}

geometricOptics.register( 'LensScreen', LensScreen );
export default LensScreen;
export default LensScreen;
10 changes: 5 additions & 5 deletions js/lens/model/Guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class Guide {
return opticPosition.plusXY( 0, locationSign * opticDiameter / 2 );
} );

// @public (read-only) {Property.<number>} angle of rotation of the incident guide with respect to the positive
// x-axis
// @public (read-only) {DerivedProperty.<number>}
// angle of rotation of the incident guide with respect to the positive x-axis
this.incidentAngleProperty = new DerivedProperty( [ objectPositionProperty, this.fulcrumPositionProperty ],
( objectPosition, fulcrumPosition ) => {
const displacementVector = objectPosition.minus( fulcrumPosition );
return displacementVector.getAngle();
} );

// @public (read-only) {Property.<number>} find the angle of the transmitted guide with respect to the positive
// x-axis
// @public (read-only) {DerivedProperty.<number>}
// find the angle of the transmitted guide with respect to the positive x-axis
this.transmittedAngleProperty = new DerivedProperty( [ optic.focalLengthProperty,
optic.diameterProperty,
this.incidentAngleProperty ],
Expand Down Expand Up @@ -97,4 +97,4 @@ class Guide {
Guide.Location = Enumeration.byKeys( [ 'TOP', 'BOTTOM' ] );

geometricOptics.register( 'Guide', Guide );
export default Guide;
export default Guide;
38 changes: 15 additions & 23 deletions js/lens/model/LensModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,36 @@ import Optic from '../../common/model/Optic.js';
import geometricOptics from '../../geometricOptics.js';
import Guide from './Guide.js';

const INDEX_OF_REFRACTION_RANGE = GeometricOpticsConstants.LENS_INDEX_OF_REFRACTION_RANGE;
const RADIUS_OF_CURVATURE_RANGE = GeometricOpticsConstants.LENS_RADIUS_OF_CURVATURE_RANGE;
const DIAMETER_RANGE = GeometricOpticsConstants.LENS_DIAMETER_RANGE;
const INITIAL_CURVATURE_TYPE = GeometricOpticsConstants.LENS_INITIAL_CURVATURE_TYPE;
const INITIAL_POSITION = GeometricOpticsConstants.LENS_INITIAL_POSITION;

class LensModel extends GeometricOpticsModel {

constructor() {

super( INITIAL_POSITION, RADIUS_OF_CURVATURE_RANGE, DIAMETER_RANGE,
INDEX_OF_REFRACTION_RANGE, INITIAL_CURVATURE_TYPE, Optic.Type.LENS );
super(
GeometricOpticsConstants.LENS_INITIAL_POSITION,
GeometricOpticsConstants.LENS_RADIUS_OF_CURVATURE_RANGE,
GeometricOpticsConstants.LENS_DIAMETER_RANGE,
GeometricOpticsConstants.LENS_INDEX_OF_REFRACTION_RANGE,
GeometricOpticsConstants.LENS_INITIAL_CURVATURE_TYPE,
Optic.Type.LENS
);

// @public {Guide} model for top guide associated with the first source/object
this.firstTopGuide = new Guide( this.sourceObject.firstPositionProperty, this.optic );

// @public {Guide} model for bottom guide associated with the first source/object
this.firstBottomGuide = new Guide( this.sourceObject.firstPositionProperty, this.optic,
{ location: Guide.Location.BOTTOM } );
this.firstBottomGuide = new Guide( this.sourceObject.firstPositionProperty, this.optic, {
location: Guide.Location.BOTTOM
} );

// @public {Guide} model for top guide associated with the second source/object
this.secondTopGuide = new Guide( this.sourceObject.secondPositionProperty, this.optic );

// @public {Guide} model for bottom guide associated with the second source/object
this.secondBottomGuide = new Guide( this.sourceObject.secondPositionProperty, this.optic,
{ location: Guide.Location.BOTTOM } );

}

/**
* REVIEW: you don't need to override just to call to super.
* Resets the model.
* @public
*/
reset() {
super.reset();
this.secondBottomGuide = new Guide( this.sourceObject.secondPositionProperty, this.optic, {
location: Guide.Location.BOTTOM
} );
}
}

geometricOptics.register( 'LensModel', LensModel );
export default LensModel;
export default LensModel;
9 changes: 4 additions & 5 deletions js/lens/model/ProjectorScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import GeometricOpticsConstants from '../../common/GeometricOpticsConstants.js';
import geometricOptics from '../../geometricOptics.js';
import Spotlight from './Spotlight.js';

// constants
const MASK_CORNERS = GeometricOpticsConstants.MASK_CORNERS;
const INITIAL_POSITION = GeometricOpticsConstants.PROJECTOR_INITIAL_POSITION;

Expand All @@ -26,10 +27,8 @@ class ProjectorScreen {
* @param {Property.<Vector2>} secondTargetPositionProperty
* @param {Optic} optic
*/
constructor( firstSourcePositionProperty,
secondSourcePositionProperty,
firstTargetPositionProperty,
secondTargetPositionProperty,
constructor( firstSourcePositionProperty, secondSourcePositionProperty,
firstTargetPositionProperty, secondTargetPositionProperty,
optic ) {

// @public {Property.<Vector2>} position of the center of the screen
Expand Down Expand Up @@ -109,4 +108,4 @@ class ProjectorScreen {
}

geometricOptics.register( 'ProjectorScreen', ProjectorScreen );
export default ProjectorScreen;
export default ProjectorScreen;
14 changes: 3 additions & 11 deletions js/lens/model/Spotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import GeometricOpticsConstants from '../../common/GeometricOpticsConstants.js';
import Optic from '../../common/model/Optic.js';
import geometricOptics from '../../geometricOptics.js';

const FULL_BRIGHT_SPOT_HEIGHT = GeometricOpticsConstants.FULL_BRIGHT_SPOT_HEIGHT;

class Spotlight {

/**
Expand All @@ -25,11 +23,7 @@ class Spotlight {
* @param {Optic} optic
* @param {function} getScreenShape - returns the shape of the screen {Shape}
*/
constructor( sourcePositionProperty,
screenPositionProperty,
targetPositionProperty,
optic,
getScreenShape ) {
constructor( sourcePositionProperty, screenPositionProperty, targetPositionProperty, optic, getScreenShape ) {

// @private {function}
this.getScreenShape = getScreenShape;
Expand Down Expand Up @@ -63,7 +57,6 @@ class Spotlight {
( screenPosition, opticPosition, opticDiameter, targetPosition ) => {
return this.getLightIntensity( screenPosition, opticPosition, opticDiameter, targetPosition );
} );

}

/**
Expand Down Expand Up @@ -134,7 +127,6 @@ class Spotlight {
*/
getIntersectPosition( screenPosition, point, targetPosition ) {
const blend = this.getRatio( screenPosition, point, targetPosition );

return point.blend( targetPosition, blend );
}

Expand Down Expand Up @@ -221,10 +213,10 @@ class Spotlight {
else {

// intensity saturates to 1 for a spotlight height less than FULL_BRIGHT_SPOT_HEIGHT
return Math.min( 1, FULL_BRIGHT_SPOT_HEIGHT / spotlightHeight );
return Math.min( 1, GeometricOpticsConstants.FULL_BRIGHT_SPOT_HEIGHT / spotlightHeight );
}
}
}

geometricOptics.register( 'Spotlight', Spotlight );
export default Spotlight;
export default Spotlight;
11 changes: 3 additions & 8 deletions js/lens/view/GuideNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ import Rectangle from '../../../../scenery/js/nodes/Rectangle.js';
import GeometricOpticsConstants from '../../common/GeometricOpticsConstants.js';
import geometricOptics from '../../geometricOptics.js';

const GUIDE_FULCRUM_RADIUS = GeometricOpticsConstants.GUIDE_FULCRUM_RADIUS;
const GUIDE_RECTANGLE_WIDTH = GeometricOpticsConstants.GUIDE_RECTANGLE_WIDTH;
const GUIDE_RECTANGLE_HEIGHT = GeometricOpticsConstants.GUIDE_RECTANGLE_HEIGHT;

class GuideNode extends Node {

/**
Expand All @@ -41,11 +37,11 @@ class GuideNode extends Node {
super();

// width and height of the guide rectangles
const viewRectangleWidth = modelViewTransform.modelToViewDeltaX( GUIDE_RECTANGLE_WIDTH );
const viewRectangleHeight = Math.abs( modelViewTransform.modelToViewDeltaY( GUIDE_RECTANGLE_HEIGHT ) );
const viewRectangleWidth = modelViewTransform.modelToViewDeltaX( GeometricOpticsConstants.GUIDE_RECTANGLE_WIDTH );
const viewRectangleHeight = Math.abs( modelViewTransform.modelToViewDeltaY( GeometricOpticsConstants.GUIDE_RECTANGLE_HEIGHT ) );

// create fulcrum circle
const fulcrumCircle = new Circle( GUIDE_FULCRUM_RADIUS, options.circle );
const fulcrumCircle = new Circle( GeometricOpticsConstants.GUIDE_FULCRUM_RADIUS, options.circle );

// create two rectangles, with left center side laying on fulcrum circle (initially)
const incidentRectangle = new Rectangle( fulcrumCircle.x, fulcrumCircle.y - viewRectangleHeight / 2, viewRectangleWidth, viewRectangleHeight, options.rectangle );
Expand Down Expand Up @@ -117,7 +113,6 @@ class GuideNode extends Node {

// update guides visibility based on checkbox
visibleProperty.linkAttribute( this, 'visible' );

}
}

Expand Down
2 changes: 1 addition & 1 deletion js/lens/view/LensScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ class LensScreenView extends GeometricOpticsScreenView {
}

geometricOptics.register( 'LensScreenView', LensScreenView );
export default LensScreenView;
export default LensScreenView;
12 changes: 3 additions & 9 deletions js/lens/view/ProjectorScreenNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ class ProjectorScreenNode extends Node {
* @param {ModelViewTransform2} modelViewTransform
* @param {Object} [options]
*/
constructor( projectorScreen,
representationProperty,
enableFirstSpotlightProperty,
enableSecondSpotlightProperty,
secondSourceVisibleProperty,
visibleModelBoundsProperty,
modelViewTransform,
options ) {
constructor( projectorScreen, representationProperty, enableFirstSpotlightProperty, enableSecondSpotlightProperty,
secondSourceVisibleProperty, visibleModelBoundsProperty, modelViewTransform, options ) {

options = merge( {
cursor: 'pointer'
Expand Down Expand Up @@ -155,4 +149,4 @@ class ProjectorScreenNode extends Node {
}

geometricOptics.register( 'ProjectorScreenNode', ProjectorScreenNode );
export default ProjectorScreenNode;
export default ProjectorScreenNode;
15 changes: 6 additions & 9 deletions js/mirror/MirrorScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@ class MirrorScreen extends Screen {
constructor() {

// create concave mirror for home screen icon
const iconNode = CurveControl.createIconNode(
Optic.Curve.CONCAVE,
Optic.Type.MIRROR,
{
radius: 20,
diameter: 30,
outline: { stroke: 'black' }
} );
const iconNode = CurveControl.createIconNode( Optic.Curve.CONCAVE, Optic.Type.MIRROR, {
radius: 20,
diameter: 30,
outline: { stroke: 'black' }
} );

const options = {
name: geometricOpticsStrings.screen.mirror,
Expand All @@ -43,4 +40,4 @@ class MirrorScreen extends Screen {
}

geometricOptics.register( 'MirrorScreen', MirrorScreen );
export default MirrorScreen;
export default MirrorScreen;
25 changes: 9 additions & 16 deletions js/mirror/model/MirrorModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import GeometricOpticsModel from '../../common/model/GeometricOpticsModel.js';
import Optic from '../../common/model/Optic.js';
import geometricOptics from '../../geometricOptics.js';

const INITIAL_POSITION = GeometricOpticsConstants.MIRROR_INITIAL_POSITION;
const RADIUS_OF_CURVATURE_RANGE = GeometricOpticsConstants.MIRROR_RADIUS_OF_CURVATURE_RANGE;
const DIAMETER_RANGE = GeometricOpticsConstants.MIRROR_DIAMETER_RANGE;
const INITIAL_CURVATURE_TYPE = GeometricOpticsConstants.MIRROR_INITIAL_CURVATURE_TYPE;

class MirrorModel extends GeometricOpticsModel {

constructor() {
Expand All @@ -24,18 +19,16 @@ class MirrorModel extends GeometricOpticsModel {
// its focal length is equivalent to a lens with an index of refraction of 2
const indexOfRefractionRange = new RangeWithValue( 2, 2, 2 );

super( INITIAL_POSITION, RADIUS_OF_CURVATURE_RANGE, DIAMETER_RANGE,
indexOfRefractionRange, INITIAL_CURVATURE_TYPE, Optic.Type.MIRROR );
}

/**
* Resets the model.
* @public
*/
reset() {
super.reset();
super(
GeometricOpticsConstants.MIRROR_INITIAL_POSITION,
GeometricOpticsConstants.MIRROR_RADIUS_OF_CURVATURE_RANGE,
GeometricOpticsConstants.MIRROR_DIAMETER_RANGE,
indexOfRefractionRange,
GeometricOpticsConstants.MIRROR_INITIAL_CURVATURE_TYPE,
Optic.Type.MIRROR
);
}
}

geometricOptics.register( 'MirrorModel', MirrorModel );
export default MirrorModel;
export default MirrorModel;
2 changes: 1 addition & 1 deletion js/mirror/view/MirrorScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class MirrorScreenView extends GeometricOpticsScreenView {
}

geometricOptics.register( 'MirrorScreenView', MirrorScreenView );
export default MirrorScreenView;
export default MirrorScreenView;

0 comments on commit 597db17

Please sign in to comment.