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 149ac3b commit eb08d2e
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 103 deletions.
2 changes: 1 addition & 1 deletion js/common/model/FocalPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ class FocalPoint {
}

geometricOptics.register( 'FocalPoint', FocalPoint );
export default FocalPoint;
export default FocalPoint;
23 changes: 8 additions & 15 deletions js/common/model/GeometricOpticsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ class GeometricOpticsModel {
* @param {Optic.Curve} curve - initial curve of optical element
* @param {Optic.Type} type - initial type of optical element
*/
constructor( opticPosition,
radiusOfCurvatureRange,
diameterRange,
indexOfRefractionRange,
curve,
type ) {
constructor( opticPosition, radiusOfCurvatureRange, diameterRange, indexOfRefractionRange, curve, type ) {

assert && assert( opticPosition instanceof Vector2, 'invalid position' );
assert && assert( radiusOfCurvatureRange instanceof RangeWithValue, 'invalid radiusOfCurvature' );
assert && assert( diameterRange instanceof RangeWithValue, 'invalid diameterRange' );
Expand Down Expand Up @@ -75,12 +71,7 @@ class GeometricOpticsModel {
};

// @public {Optic} - model of the optic
this.optic = new Optic( opticPosition,
radiusOfCurvatureRange,
diameterRange,
indexOfRefractionRange,
curve,
type );
this.optic = new Optic( opticPosition, radiusOfCurvatureRange, diameterRange, indexOfRefractionRange, curve, type );

// @public {SourceObject} the object/ source
this.sourceObject = new SourceObject( this.optic.positionProperty, this.representationProperty );
Expand Down Expand Up @@ -111,7 +102,8 @@ class GeometricOpticsModel {
);

// @public {LightRays} model of the light rays associated to the first source
this.firstLightRays = new LightRays( this.timeProperty,
this.firstLightRays = new LightRays(
this.timeProperty,
this.lightRayModeProperty,
this.representationProperty,
this.sourceObject.firstPositionProperty,
Expand All @@ -121,7 +113,8 @@ class GeometricOpticsModel {
);

// @public {LightRays} model of the light rays associated with the second source
this.secondLightRays = new LightRays( this.timeProperty,
this.secondLightRays = new LightRays(
this.timeProperty,
this.lightRayModeProperty,
this.representationProperty,
this.sourceObject.secondPositionProperty,
Expand Down Expand Up @@ -159,4 +152,4 @@ class GeometricOpticsModel {
}

geometricOptics.register( 'GeometricOpticsModel', GeometricOpticsModel );
export default GeometricOpticsModel;
export default GeometricOpticsModel;
17 changes: 5 additions & 12 deletions js/common/model/LightRay.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ class LightRay {
* @param {boolean} isProjectorScreenPresent - is there a projector screen in the play area
* @param {function} getProjectorScreenBisectorLine - returns a Shape that bisects the middle of projector screen
*/
constructor( initialRay,
time,
optic,
targetPoint,
isVirtual,
isPrincipalRayMode,
isProjectorScreenPresent,
constructor( initialRay, time, optic, targetPoint, isVirtual, isPrincipalRayMode, isProjectorScreenPresent,
getProjectorScreenBisectorLine ) {

// @public (read-only) - shape of the real rays - will be updated later
Expand All @@ -55,9 +49,8 @@ class LightRay {
// @private {Ray[]} - a collection of sequential rays
this.realRays = this.getRealRays( initialRay, firstPoint, optic, isPrincipalRayMode, targetPoint );

// if the last ray intercepts the projector screen, its final point will be set on the last ray
if ( isProjectorScreenPresent ) {

// if the last ray intercepts the projector screen, its final point will be set on the last ray
this.setFinalPointProjectorScreen( this.realRays, getProjectorScreenBisectorLine() );
}

Expand All @@ -79,7 +72,6 @@ class LightRay {

// process rays to convert them to virtualShape and realShape
this.raysToShape( distanceTraveled );

}

/**
Expand Down Expand Up @@ -411,6 +403,8 @@ class LightRay {
/**
* Has the light ray a virtual component (virtual ray)
* @private
* @param {boolean} isImageVirtual
* @param {Ray[]} realRays
* @returns {boolean}
*/
hasVirtualComponent( isImageVirtual, realRays ) {
Expand Down Expand Up @@ -477,9 +471,8 @@ class LightRay {

// add line to shape
shape.moveToPoint( ray.position ).lineToPoint( endPoint );

}
}

geometricOptics.register( 'LightRay', LightRay );
export default LightRay;
export default LightRay;
2 changes: 1 addition & 1 deletion js/common/model/LightRayMode.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ const LightRayMode = Enumeration.byKeys( [
] );

geometricOptics.register( 'LightRayMode', LightRayMode );
export default LightRayMode;
export default LightRayMode;
16 changes: 4 additions & 12 deletions js/common/model/LightRays.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,8 @@ class LightRays {
* @param {Optic} optic
* @param {Target} target - target model associated with this ray
*/
constructor( timeProperty,
lightRayModeProperty,
representationProperty,
sourceObjectPositionProperty,
projectorScreen,
optic,
target ) {
constructor( timeProperty, lightRayModeProperty, representationProperty, sourceObjectPositionProperty,
projectorScreen, optic, target ) {

// @private {Property.<Vector>} target position associated with this ray
this.targetPositionProperty = target.positionProperty;
Expand Down Expand Up @@ -120,11 +115,10 @@ class LightRays {

/**
* Gets the initial directions of the rays for the different light ray modes.
*
* @private
* @param {LightRayMode} lightRayMode
* @param {Vector2} sourcePosition
* @param {Optic} optic
* @param {LightRayMode} lightRayMode
* @returns {Vector2[]}
*/
getRayDirections( sourcePosition, optic, lightRayMode ) {
Expand Down Expand Up @@ -178,7 +172,6 @@ class LightRays {

// direction for ray going through the focal point
directions.push( sourceFirstFocalVector.normalized() );

}
else if ( lightRayMode === LightRayMode.MANY ) {

Expand Down Expand Up @@ -213,9 +206,8 @@ class LightRays {
rayShape.subpaths.forEach( subPath => {
typeRayShape.addSubpath( subPath );
} );

}
}

geometricOptics.register( 'LightRays', LightRays );
export default LightRays;
export default LightRays;
28 changes: 10 additions & 18 deletions js/common/model/Optic.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,16 @@ class Optic {
* @param {Optic.Curve} curve - initial curve of optical element - acceptable values (CONVEX and CONCAVE)
* @param {Optic.Type} type - type of optical element - acceptable values (MIRROR and LENS)
*/
constructor( initialPosition,
radiusOfCurvatureRange,
diameterRange,
indexOfRefractionRange,
curve,
type ) {
constructor( initialPosition, radiusOfCurvatureRange, diameterRange, indexOfRefractionRange, curve, type ) {

assert && assert( initialPosition instanceof Vector2, 'invalid initialPosition' );
assert && assert( radiusOfCurvatureRange instanceof RangeWithValue, 'invalid radiusOfCurvature' );
assert && assert( diameterRange instanceof RangeWithValue, 'invalid diameterRange' );

// @public {Property.<Vector2>} Position of the optical element
this.positionProperty = new Vector2Property( initialPosition );

// @public {Property.<number>} Radius of curvature of the optical element - The convention is positive as
// converging.
// @public {Property.<number>} Radius of curvature of the optical element. Positive is converging.
this.radiusOfCurvatureProperty = new NumberProperty( radiusOfCurvatureRange.defaultValue, {
range: radiusOfCurvatureRange
} );
Expand Down Expand Up @@ -80,18 +75,18 @@ class Optic {
}
);

// @public {Property.<boolean>} is the optical element converging.
// @public {DerivedProperty.<boolean>} is the optical element converging.
this.isConvergingProperty = new DerivedProperty( [ this.curveProperty ], curve => {
return this.isConverging( curve );
} );

// @public {Property.<number>} is the optical element converging.
// @public {DerivedProperty.<number>} is the optical element converging.
// +1 is the optical element is converging and -1 if it is diverging
this.convergingSignProperty = new DerivedProperty( [ this.curveProperty ], curve => {
return this.getConvergingSign( curve );
} );

// @public {Property.<OpticShapeCollection>} shapes (fill and outline) of the optical element
// @public {DerivedProperty.<OpticShapeCollection>} shapes (fill and outline) of the optical element
this.shapesProperty = new DerivedProperty( [
this.radiusOfCurvatureProperty,
this.diameterProperty,
Expand All @@ -107,7 +102,6 @@ class Optic {
}

/**
* Resets the model.
* @public
*/
reset() {
Expand Down Expand Up @@ -280,9 +274,8 @@ class Optic {
return this.indexOfRefractionProperty.range.getNormalizedValue( index );
}
else {

// return the maximum value for mirror
return 1;
//TODO hardcoded value!
return 1; // return the maximum value for mirror
}
}

Expand Down Expand Up @@ -338,8 +331,8 @@ class Optic {
spotPoint = isConcave ? leftPoint : rightPoint;
}
else {
// must be lens

// must be a lens
if ( isConcave ) {

// displacement vector from targetPoint to the right corner of the lens
Expand All @@ -361,7 +354,6 @@ class Optic {
// get the direction of the ray as measured from the source
spotPoint = opticPoint.plusXY( 0, offsetY );
}

else {
// must be a convex lens

Expand Down Expand Up @@ -389,4 +381,4 @@ Optic.Location = Enumeration.byKeys( [
'BOTTOM' ] );

geometricOptics.register( 'Optic', Optic );
export default Optic;
export default Optic;
12 changes: 4 additions & 8 deletions js/common/model/OpticShapeCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class OpticShapeCollection {
* @param {Object} [options]
*/
constructor( radius, diameter, curve, type, options ) {

if ( type === Optic.Type.LENS ) {
this.setLensShapes( radius, diameter, curve, options );
}
Expand Down Expand Up @@ -103,16 +102,14 @@ class OpticShapeCollection {
.close();

// @public (read-only)
this.frontShape = frontShape;
this.fillShape = fillShape;
this.outlineShape = frontShape;
this.frontShape = frontShape;
this.backShape = null;

}

/**
* Sets the shapes of a lens. In the case of a lens, the outline and fills shape are identical.
*
* The lens shape is approximated as a parabolic lens.
* The radius of curvature of the lens does necessarily match the value of radius and can be instead "hollywooded".
* This gives the flexibility to draw lenses with radius of curvature that is larger than diameter/2, a physical
Expand Down Expand Up @@ -171,10 +168,9 @@ class OpticShapeCollection {
.quadraticCurveToPoint( right, bottom )
.quadraticCurveToPoint( right, top )
.close();

}
else {
// implies that curve === Optic.Curve.CONCAVE
assert && assert( curve === Optic.Curve.CONCAVE );

const midWidth = halfWidth;

Expand Down Expand Up @@ -213,12 +209,12 @@ class OpticShapeCollection {
// the outline shape is the same as the fill shape for a lens

// @public (read-only)
this.frontShape = frontShape;
this.fillShape = outlineShape;
this.outlineShape = outlineShape;
this.frontShape = frontShape;
this.backShape = backShape;
}
}

geometricOptics.register( 'OpticShapeCollection', OpticShapeCollection );
export default OpticShapeCollection;
export default OpticShapeCollection;
19 changes: 8 additions & 11 deletions js/common/model/Ray.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@ class Ray extends Ray2 {
* @param {Vector2} direction - direction of the ray, must be a normalized vector.
* @param {Object} [options]
*/
constructor( position,
direction,
options ) {
constructor( position, direction, options ) {

options = merge( {
length: Infinity // semi infinite rays by default
length: Infinity // semi-infinite rays by default
}, options );

super( position, direction );

assert && assert( typeof options.length === 'number' );

super( position, direction );

// @public {number}
this.length = options.length;
}
Expand All @@ -53,8 +51,7 @@ class Ray extends Ray2 {
}

/**
* Gets the length of the ray,
* Note that the length may be Infinity
* Gets the length of the ray. Note that the length may be Infinity.
* @public
* @returns {number} length
*/
Expand All @@ -63,7 +60,7 @@ class Ray extends Ray2 {
}

/**
* Determines if the point is along the ray direction
* Determines if the point is along the ray direction.
* @public
* @param {Vector2} point
* @param {number} epsilon - tolerance value
Expand All @@ -75,7 +72,7 @@ class Ray extends Ray2 {
}

/**
* Gets distance from origin to point (point may not lay along the direction of the ray)
* Gets distance from origin to point. The point may not lay along the direction of the ray.
* @public
* @param {Vector2} point
* @returns {number} distance
Expand All @@ -87,4 +84,4 @@ class Ray extends Ray2 {
}

geometricOptics.register( 'Ray', Ray );
export default Ray;
export default Ray;
Loading

0 comments on commit eb08d2e

Please sign in to comment.