Skip to content

Commit

Permalink
ensure right margin is not exceeded for code (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
veillette committed Jul 29, 2021
1 parent 9d74f52 commit 8b8e2e9
Show file tree
Hide file tree
Showing 19 changed files with 122 additions and 47 deletions.
12 changes: 8 additions & 4 deletions js/common/model/GeometricOpticsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ class GeometricOpticsModel {
// @public {Object} rulers for the simulations
this.rulers = {
horizontal: new Ruler( HORIZONTAL_RULER_INITIAL_POSITION, HORIZONTAL_RULER_LENGTH ),
vertical: new Ruler( VERTICAL_RULER_INITIAL_POSITION, VERTICAL_RULER_LENGTH, { orientation: Ruler.Orientation.VERTICAL } )
vertical: new Ruler( VERTICAL_RULER_INITIAL_POSITION, VERTICAL_RULER_LENGTH,
{ orientation: Ruler.Orientation.VERTICAL } )
};

// @public {Optic} - model of the optic
Expand All @@ -99,13 +100,16 @@ class GeometricOpticsModel {
this.firstFocalPoint = new FocalPoint( this.optic.positionProperty, this.optic.focalLengthProperty, tandem );

// @public {FocalPoint} second principal focal point
this.secondFocalPoint = new FocalPoint( this.optic.positionProperty, this.optic.focalLengthProperty, tandem, { multiplicativeFactor: -1 } );
this.secondFocalPoint = new FocalPoint( this.optic.positionProperty,
this.optic.focalLengthProperty, tandem, { multiplicativeFactor: -1 } );

// @public {Target} model of the target/image associated with the first source
this.firstTarget = new Target( this.sourceObject.firstPositionProperty, this.optic, this.representationProperty, tandem );
this.firstTarget = new Target( this.sourceObject.firstPositionProperty,
this.optic, this.representationProperty, tandem );

// @public {Target} target/ image associated with the second source
this.secondTarget = new Target( this.sourceObject.secondPositionProperty, this.optic, this.representationProperty, tandem );
this.secondTarget = new Target( this.sourceObject.secondPositionProperty,
this.optic, this.representationProperty, tandem );

// @public {ProjectorScreen} model of the projector screen and spotlights
this.projectorScreen = new ProjectorScreen(
Expand Down
3 changes: 2 additions & 1 deletion js/common/model/Optic.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class Optic {
*/
static getMirrorShapes( radius, diameter, curve, options ) {

assert && assert( radius > diameter / 2, 'the radius of curvature is too small when compared to the diameter' );
assert && assert( radius > diameter / 2,
'the radius of curvature is too small when compared to the diameter' );

options = merge( {
thickness: 5 // horizontal separation between the two edges of the surfaces at the middle part
Expand Down
4 changes: 3 additions & 1 deletion js/common/model/SourceObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ class SourceObject {
setSecondPoint( representationProperty, position ) {
if ( representationProperty.value.isObject ) {
const unconstrainedVerticalOffset = position.y - this.firstPositionProperty.value.y;
this.verticalOffsetProperty.value = Utils.clamp( unconstrainedVerticalOffset, verticalOffsetRange.min, verticalOffsetRange.max );
this.verticalOffsetProperty.value = Utils.clamp( unconstrainedVerticalOffset,
verticalOffsetRange.min,
verticalOffsetRange.max );
}
else {
this.unconstrainedSecondSourcePositionProperty.value = position;
Expand Down
22 changes: 13 additions & 9 deletions js/common/model/Target.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ class Target {
* @param {Property.<representation>} representationProperty
* @param {Tandem} tandem
*/
constructor( objectPositionProperty, optic, representationProperty, tandem ) {
constructor( objectPositionProperty,
optic,
representationProperty,
tandem ) {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

// @private {Property.<Vector2>} position of the object/source
Expand Down Expand Up @@ -127,17 +130,18 @@ class Target {

// light intensity of the image (Hollywood) - a value between 0 and 1
// @public (read-only) {Property.<number>}
this.lightIntensityProperty = new DerivedProperty( [ this.scaleProperty, optic.diameterProperty ], ( scale, diameter ) => {
this.lightIntensityProperty = new DerivedProperty( [ this.scaleProperty, optic.diameterProperty ],
( scale, diameter ) => {

// effect of the distance on the opacity, hollywooded as 1/scale for upscaled image
const distanceFactor = Math.min( 1, Math.abs( 1 / scale ) );
// effect of the distance on the opacity, hollywooded as 1/scale for upscaled image
const distanceFactor = Math.min( 1, Math.abs( 1 / scale ) );

// effect of the diameter of the optic on the light intensity of the image (also hollywooded)
const diameterFactor = optic.getNormalizedDiameter( diameter );
// effect of the diameter of the optic on the light intensity of the image (also hollywooded)
const diameterFactor = optic.getNormalizedDiameter( diameter );

// product of the two factors
return distanceFactor * diameterFactor;
} );
// product of the two factors
return distanceFactor * diameterFactor;
} );

// @public (read-only) {Property.<HTMLImageElement|null>}
// determine the image with appropriate orientation to select for the display
Expand Down
6 changes: 4 additions & 2 deletions js/common/view/CurveControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ class CurveControl extends RectangularRadioButtonGroup {
options.strutLength - 2 * options.buttonContentYMargin );

// make sure the spacer is larger than icon
assert && assert( iconSpacer.width > iconNode.width, 'spacer width is smaller than icon content' );
assert && assert( iconSpacer.height > iconNode.height, 'spacer height is smaller than icon content' );
assert && assert( iconSpacer.width > iconNode.width,
'spacer width is smaller than icon content' );
assert && assert( iconSpacer.height > iconNode.height,
'spacer height is smaller than icon content' );

// center the icon in the spacer
iconNode.center = iconSpacer.center;
Expand Down
6 changes: 5 additions & 1 deletion js/common/view/FocalPointNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class FocalPointNode extends PlusNode {
* @param {Tandem} tandem
* @param {Object} [options]
*/
constructor( focalPoint, visibleProperty, modelViewTransform, tandem, options ) {
constructor( focalPoint,
visibleProperty,
modelViewTransform,
tandem,
options ) {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

// options for plus Node. Rotated by 45 degrees to create an X shape.
Expand Down
8 changes: 5 additions & 3 deletions js/common/view/GeometricOpticsControlPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class GeometricOpticsControlPanel extends Panel {
*/
const createCheckboxGroupItem = ( string, property, options ) => {
options = merge( {
icon: null // {null||Node}
icon: null // {null|Node}
}, options );

// text for the checkbox
Expand All @@ -207,10 +207,12 @@ class GeometricOpticsControlPanel extends Panel {

// create checkbox group for visibility settings
const checkboxGroupItems = [
createCheckboxGroupItem( focalPointString, visibleProperties.visibleFocalPointProperty, { icon: focalPointIcon } ),
createCheckboxGroupItem( focalPointString, visibleProperties.visibleFocalPointProperty,
{ icon: focalPointIcon } ),
createCheckboxGroupItem( virtualImageString, visibleProperties.visibleVirtualImageProperty ),
createCheckboxGroupItem( labelsString, visibleProperties.visibleLabelsProperty ),
createCheckboxGroupItem( secondSourceString, visibleProperties.visibleSecondSourceProperty, { icon: secondSourcePointIcon } ),
createCheckboxGroupItem( secondSourceString, visibleProperties.visibleSecondSourceProperty,
{ icon: secondSourcePointIcon } ),
createCheckboxGroupItem( guidesString, visibleProperties.visibleGuidesProperty )
];

Expand Down
10 changes: 8 additions & 2 deletions js/common/view/GeometricOpticsRulerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,18 @@ class GeometricOpticsRulerNode extends RulerNode {

// if vertical the left and right bounds of the ruler stay within visible bounds
// minimum visible length of the ruler is always showing inside top and bottom visible bounds.
return visibleBounds.withOffsets( 0, -MINIMUM_VISIBLE_LENGTH, -this.width, -MINIMUM_VISIBLE_LENGTH + this.height );
return visibleBounds.withOffsets( 0,
-MINIMUM_VISIBLE_LENGTH,
-this.width,
-MINIMUM_VISIBLE_LENGTH + this.height );
}
else {
// if horizontal ruler, the bottom and top bounds of the ruler stay within visible bounds
// minimum visible length of the ruler is always showing inside left and right visible bounds.
return visibleBounds.withOffsets( this.width - MINIMUM_VISIBLE_LENGTH, 0, -MINIMUM_VISIBLE_LENGTH, -this.height );
return visibleBounds.withOffsets( this.width - MINIMUM_VISIBLE_LENGTH,
0,
-MINIMUM_VISIBLE_LENGTH,
-this.height );
}
}
);
Expand Down
6 changes: 5 additions & 1 deletion js/common/view/GeometricOpticsScreenView.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@ class GeometricOpticsScreenView extends ScreenView {
const opticalAxisLine = new OpticalAxisLine( model.optic.positionProperty,
this.playAreaModelBoundsProperty, this.modelViewTransform );

const opticNode = new OpticNode( model.optic, model.lightRayModeProperty, this.playAreaModelBoundsProperty, this.modelViewTransform, tandem );
const opticNode = new OpticNode( model.optic,
model.lightRayModeProperty,
this.playAreaModelBoundsProperty,
this.modelViewTransform,
tandem );

// create the light rays associated with the object
const lightRaysNode = new LightRaysNode( model.firstLightRays,
Expand Down
9 changes: 7 additions & 2 deletions js/common/view/LabelNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ class LabelNode extends Node {
* @param {Property.<ModelViewTransform2>} modelViewTransformProperty
* @param {Object} [options]
*/
constructor( string, positionProperty, visibleProperty, modelViewTransformProperty, options ) {
constructor( string,
positionProperty,
visibleProperty,
modelViewTransformProperty,
options ) {

options = merge( {
text: {
Expand Down Expand Up @@ -99,7 +103,8 @@ class LabelNode extends Node {
* @private
*/
setLabelPosition() {
this.centerTop = this.modelViewTransformProperty.value.modelToViewPosition( this.positionProperty.value ).plusXY( 0, this.options.labelOffset );
this.centerTop = this.modelViewTransformProperty.value.modelToViewPosition( this.positionProperty.value )
.plusXY( 0, this.options.labelOffset );
}

/**
Expand Down
21 changes: 16 additions & 5 deletions js/common/view/LabelsNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,17 @@ class LabelsNode extends Node {
modelViewTransformProperty );

// define optic label position
const opticLabelPositionProperty = new DerivedProperty( [ model.optic.positionProperty, model.optic.diameterProperty ], ( position, diameter ) =>
position.minusXY( 0, diameter / 2 )
const opticLabelPositionProperty = new DerivedProperty(
[ model.optic.positionProperty, model.optic.diameterProperty ],
( position, diameter ) =>
position.minusXY( 0, diameter / 2 )
);

// create optic label with empty string
const opticLabel = new LabelNode( '', opticLabelPositionProperty, new BooleanProperty( true ), modelViewTransformProperty );
const opticLabel = new LabelNode( '',
opticLabelPositionProperty,
new BooleanProperty( true ),
modelViewTransformProperty );

// update the label string of the optic
model.optic.curveProperty.link( curve => {
Expand All @@ -86,15 +91,21 @@ class LabelsNode extends Node {
bounds => bounds.centerTop );

// create image label
const imageLabel = new LabelNode( imageString, imageLabelPositionProperty, new BooleanProperty( true ), modelViewTransformProperty );
const imageLabel = new LabelNode( imageString,
imageLabelPositionProperty,
new BooleanProperty( true ),
modelViewTransformProperty );

// define object label position
const objectLabelPositionProperty = new DerivedProperty( [ model.sourceObject.boundsProperty ],
// because the we use a Y inverted reference frame, the bottom of the image is the top of the model bounds.
bounds => bounds.centerTop );

// create object label
const objectLabel = new LabelNode( objectString, objectLabelPositionProperty, new BooleanProperty( true ), modelViewTransformProperty );
const objectLabel = new LabelNode( objectString,
objectLabelPositionProperty,
new BooleanProperty( true ),
modelViewTransformProperty );

// update the visibility of the object and image labels
Property.multilink( [
Expand Down
6 changes: 5 additions & 1 deletion js/common/view/LightRaysNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ class LightRaysNode extends Node {
* @param {Tandem} tandem
* @param {Object} [options]
*/
constructor( lightRays, visibleVirtualImageProperty, modelViewTransform, tandem, options ) {
constructor( lightRays,
visibleVirtualImageProperty,
modelViewTransform,
tandem,
options ) {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

options = merge( {
Expand Down
7 changes: 6 additions & 1 deletion js/common/view/OpticNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ class OpticNode extends Node {
* @param {Tandem} tandem
* @param {Object} [options]
*/
constructor( optic, lightRayModeProperty, playAreaModelBoundsProperty, modelViewTransform, tandem, options ) {
constructor( optic,
lightRayModeProperty,
playAreaModelBoundsProperty,
modelViewTransform,
tandem,
options ) {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

options = merge( {
Expand Down
4 changes: 3 additions & 1 deletion js/common/view/OpticalAxisLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ class OpticalAxisLine extends Line {
* @param {Property.<Bounds2>} visibleModelBoundsProperty
* @param {ModelViewTransform2} modelViewTransform
*/
constructor( opticPositionProperty, visibleModelBoundsProperty, modelViewTransform ) {
constructor( opticPositionProperty,
visibleModelBoundsProperty,
modelViewTransform ) {

// create optical axis line, with arbitrary length values.
super( 0, 0, 1, 0, {
Expand Down
24 changes: 17 additions & 7 deletions js/common/view/ToolboxPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ class ToolboxPanel extends Panel {
const verticalRulerIconNode = ToolboxPanel.getRulerIcon( true );

// increase touchArea and mouseArea for both rulers
horizontalRulerIconNode.touchArea = horizontalRulerIconNode.localBounds.dilatedXY( options.touchAreaDilationX, options.touchAreaDilationY );
horizontalRulerIconNode.mouseArea = horizontalRulerIconNode.localBounds.dilatedXY( options.mouseAreaDilationX, options.mouseAreaDilationY );
verticalRulerIconNode.touchArea = verticalRulerIconNode.localBounds.dilatedXY( options.touchAreaDilationX, options.touchAreaDilationY );
verticalRulerIconNode.mouseArea = verticalRulerIconNode.localBounds.dilatedXY( options.mouseAreaDilationX, options.mouseAreaDilationY );
horizontalRulerIconNode.touchArea = horizontalRulerIconNode.localBounds.dilatedXY(
options.touchAreaDilationX, options.touchAreaDilationY );
horizontalRulerIconNode.mouseArea = horizontalRulerIconNode.localBounds.dilatedXY(
options.mouseAreaDilationX, options.mouseAreaDilationY );
verticalRulerIconNode.touchArea = verticalRulerIconNode.localBounds.dilatedXY(
options.touchAreaDilationX, options.touchAreaDilationY );
verticalRulerIconNode.mouseArea = verticalRulerIconNode.localBounds.dilatedXY(
options.mouseAreaDilationX, options.mouseAreaDilationY );

// create the content for the panel
const toolbox = new HBox( {
Expand All @@ -62,7 +66,9 @@ class ToolboxPanel extends Panel {
* @param {GeometricOpticsRulerNode} rulerNode
* @param {Property.<boolean>} visibleRulerProperty - visibility associated with the rulerNode (not icon)
*/
const createForwardListener = ( iconNode, rulerNode, visibleRulerProperty ) => {
const createForwardListener = ( iconNode,
rulerNode,
visibleRulerProperty ) => {

// ruler node and icon node have opposite visibilities
visibleRulerProperty.link( visible => {
Expand All @@ -87,8 +93,12 @@ class ToolboxPanel extends Panel {
};

// attach a create a Forward listener on each icon
createForwardListener( horizontalRulerIconNode, rulersLayer.horizontalRulerNode, rulersLayer.visibleHorizontalProperty );
createForwardListener( verticalRulerIconNode, rulersLayer.verticalRulerNode, rulersLayer.visibleVerticalProperty );
createForwardListener( horizontalRulerIconNode,
rulersLayer.horizontalRulerNode,
rulersLayer.visibleHorizontalProperty );
createForwardListener( verticalRulerIconNode,
rulersLayer.verticalRulerNode,
rulersLayer.visibleVerticalProperty );
}

/**
Expand Down
5 changes: 4 additions & 1 deletion js/common/view/TrackingDiskNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ class TrackingDiskNode extends Circle {
* @param {Tandem} tandem
* @param {Object} [options]
* */
constructor( positionProperty, modelViewTransform, tandem, options ) {
constructor( positionProperty,
modelViewTransform,
tandem,
options ) {
assert && assert( tandem instanceof Tandem, 'invalid tandem' );

options = merge( {
Expand Down
4 changes: 3 additions & 1 deletion js/lens/model/Guide.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ class Guide {

// @public (read-only) {Property.<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 ],
this.transmittedAngleProperty = new DerivedProperty( [ optic.focalLengthProperty,
optic.diameterProperty,
this.incidentAngleProperty ],
( focalLength, diameter, incidentAngle ) => {

// transmitted angle if the optic was a blank.
Expand Down
6 changes: 4 additions & 2 deletions js/lens/model/LensModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ class LensModel extends GeometricOpticsModel {
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 } );
this.secondBottomGuide = new Guide( this.sourceObject.secondPositionProperty, this.optic,
{ location: Guide.Location.BOTTOM } );

}

Expand Down
6 changes: 4 additions & 2 deletions js/lens/model/Spotlight.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ class Spotlight {
getDiskParameters( screenPosition, opticPosition, opticDiameter, targetPosition ) {

// get the extremum points on the optic
const extremumTopOpticPoint = this.optic.getExtremumPoint( this.sourcePositionProperty.value, targetPosition, { location: Optic.Location.TOP } );
const extremumBottomOpticPoint = this.optic.getExtremumPoint( this.sourcePositionProperty.value, targetPosition, { location: Optic.Location.BOTTOM } );
const extremumTopOpticPoint = this.optic.getExtremumPoint( this.sourcePositionProperty.value, targetPosition,
{ location: Optic.Location.TOP } );
const extremumBottomOpticPoint = this.optic.getExtremumPoint( this.sourcePositionProperty.value, targetPosition,
{ location: Optic.Location.BOTTOM } );

// determine the top and bottom position of the unclipped disk
const diskTopPosition = this.getIntersectPosition( screenPosition, extremumTopOpticPoint, targetPosition );
Expand Down

0 comments on commit 8b8e2e9

Please sign in to comment.