From 20888bbb01a95e0f778a7358503b048b66192dd6 Mon Sep 17 00:00:00 2001 From: Chris Malley Date: Thu, 23 Dec 2021 10:21:46 -0700 Subject: [PATCH] add debugOpticalAxis query param, https://github.com/phetsims/geometric-optics/issues/283 --- js/common/GOQueryParameters.ts | 6 ++++++ js/common/view/OpticalAxisForegroundNode.ts | 11 +++++++++-- js/common/view/OpticalAxisNode.ts | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/js/common/GOQueryParameters.ts b/js/common/GOQueryParameters.ts index 80e7a8d9..4a34a096 100644 --- a/js/common/GOQueryParameters.ts +++ b/js/common/GOQueryParameters.ts @@ -60,6 +60,12 @@ const SCHEMA = { type: 'number', defaultValue: 400, isValidValue: ( value: number ) => ( value >= 100 ) + }, + + // The optical axis is drawn using 2 Nodes, OpticalAxisNode and OpticalAxisForegroundNode. + // This flag uses 'red' stroke for the segments drawn by OpticalAxisForegroundNode. + debugOpticalAxis: { + type: 'flag' } }; diff --git a/js/common/view/OpticalAxisForegroundNode.ts b/js/common/view/OpticalAxisForegroundNode.ts index bd60e65a..bdec6f92 100644 --- a/js/common/view/OpticalAxisForegroundNode.ts +++ b/js/common/view/OpticalAxisForegroundNode.ts @@ -14,11 +14,13 @@ import Property from '../../../../axon/js/Property.js'; import Bounds2 from '../../../../dot/js/Bounds2.js'; import Vector2 from '../../../../dot/js/Vector2.js'; import Shape from '../../../../kite/js/Shape.js'; +import merge from '../../../../phet-core/js/merge.js'; import ModelViewTransform2 from '../../../../phetcommon/js/view/ModelViewTransform2.js'; import geometricOptics from '../../geometricOptics.js'; import Barrier from '../model/Barrier.js'; import Representation from '../model/Representation.js'; import OpticalAxisNode, { OpticalAxisNodeOptions } from './OpticalAxisNode.js'; +import GOQueryParameters from '../GOQueryParameters.js'; class OpticalAxisForegroundNode extends OpticalAxisNode { @@ -31,7 +33,7 @@ class OpticalAxisForegroundNode extends OpticalAxisNode { * @param barrier * @param modelBoundsProperty * @param modelViewTransform - * @param options + * @param providedOptions */ constructor( opticPositionProperty: IReadOnlyProperty, representationProperty: IReadOnlyProperty, @@ -41,7 +43,12 @@ class OpticalAxisForegroundNode extends OpticalAxisNode { barrier: Barrier | null, modelBoundsProperty: IReadOnlyProperty, modelViewTransform: ModelViewTransform2, - options: OpticalAxisNodeOptions ) { + providedOptions: OpticalAxisNodeOptions ) { + + const options = merge( {}, providedOptions ) as OpticalAxisNodeOptions; + if ( GOQueryParameters.debugOpticalAxis ) { + options.stroke = 'red'; + } // create optical axis line, with arbitrary length values. super( opticPositionProperty, modelBoundsProperty, modelViewTransform, options ); diff --git a/js/common/view/OpticalAxisNode.ts b/js/common/view/OpticalAxisNode.ts index e3512b9a..9f830b01 100644 --- a/js/common/view/OpticalAxisNode.ts +++ b/js/common/view/OpticalAxisNode.ts @@ -21,6 +21,7 @@ import GOColors from '../GOColors.js'; import GOConstants from '../GOConstants.js'; type OpticalAxisNodeOptions = { + stroke?: ColorDef, visibleProperty: IProperty };