<commit_before>// Copyright 2018, University of Colorado Boulder

/**
 * Displays the roots of a quadratic as non-interactive points with coordinate labels.
 * There may be 0, 1 or 2 roots.
 *
 * @author <NAME> (PixelZoom, Inc.)
 */
define( require => {
  'use strict';

  // modules
  const Circle = require( 'SCENERY/nodes/Circle' );
  const DerivedProperty = require( 'AXON/DerivedProperty' );
  const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' );
  const CoordinatesNode = require( 'GRAPHING_QUADRATICS/common/view/CoordinatesNode' );
  const GQColors = require( 'GRAPHING_QUADRATICS/common/GQColors' );
  const GQConstants = require( 'GRAPHING_QUADRATICS/common/GQConstants' );
  const graphingQuadratics = require( 'GRAPHING_QUADRATICS/graphingQuadratics' );
  const Node = require( 'SCENERY/nodes/Node' );
  const NullableIO = require( 'TANDEM/types/NullableIO' );
  const Tandem = require( 'TANDEM/Tandem' );
  const Vector2 = require( 'DOT/Vector2' );
  const Vector2IO = require( 'DOT/Vector2IO' );

  // constants
  const COORDINATES_X_SPACING = 15; // between root point and its coordinates display

  class RootsNode extends Node {

    /**
     * @param {Property.<Quadratic>} quadraticProperty - the interactive quadratic
     * @param {Graph} graph
     * @param {ModelViewTransform2} modelViewTransform
     * @param {BooleanProperty} rootsVisibleProperty
     * @param {BooleanProperty} coordinatesVisibleProperty
     * @param {Object} [options]
     */
    constructor( quadraticProperty, graph, modelViewTransform,
                 rootsVisibleProperty, coordinatesVisibleProperty, options ) {

      options = _.extend( {
        radius: 10,
        tandem: Tandem.required
      }, options );

      // points
      const pointOptions = {
        fill: GQColors.ROOTS,
        center: modelViewTransform.modelToViewXY( graph.xRange.getCenter(), graph.yRange.getCenter() )
      };
      const leftRootNode = new Circle( options.radius, pointOptions );
      const rightRootNode = new Circle( options.radius, pointOptions );

      // coordinates corresponding to the quadratic's left or single root (if it has roots)
      const leftCoordinatesProperty = new DerivedProperty( [ quadraticProperty ],
        quadratic => ( quadratic.roots && quadratic.roots.length > 0 ) ? quadratic.roots[ 0 ] : null, {
          isValidValue: value => ( value instanceof Vector2 || value === null ),
          phetioType: DerivedPropertyIO( NullableIO( Vector2IO ) ),
          phetioDocumentation: 'coordinates displayed on the left (first) root, ' +
                               'null if there are no roots or if all points are roots'
        } );

      // coordinates corresponding to the quadratic's right root, if it has 2 roots
      const rightCoordinatesProperty = new DerivedProperty( [ quadraticProperty ],
        quadratic => ( quadratic.roots && quadratic.roots.length === 2 ) ? quadratic.roots[ 1 ] : null, {
          isValidValue: value => ( value instanceof Vector2 || value === null ),
          phetioType: DerivedPropertyIO( NullableIO( Vector2IO ) ),
          phetioDocumentation: 'coordinates displayed on the right (second) root, ' +
                               'null if there are less that two roots or if all points are roots'
        } );

      // coordinate displays
      const coordinatesOptions = {
        foregroundColor: 'white',
        backgroundColor: GQColors.ROOTS,
        decimals: GQConstants.ROOTS_DECIMALS
      };
      const leftCoordinatesNode = new CoordinatesNode( leftCoordinatesProperty, coordinatesOptions );
      const rightCoordinatesNode = new CoordinatesNode( rightCoordinatesProperty, coordinatesOptions );

      // decorate root with coordinates
      leftRootNode.addChild( leftCoordinatesNode );<commit_msg>factor out common options<commit_after>// Copyright 2018, University of Colorado Boulder

/**
 * Displays the roots of a quadratic as non-interactive points with coordinate labels.
 * There may be 0, 1 or 2 roots.
 *
 * @author <NAME> (PixelZoom, Inc.)
 */
define( require => {
  'use strict';

  // modules
  const Circle = require( 'SCENERY/nodes/Circle' );
  const DerivedProperty = require( 'AXON/DerivedProperty' );
  const DerivedPropertyIO = require( 'AXON/DerivedPropertyIO' );
  const CoordinatesNode = require( 'GRAPHING_QUADRATICS/common/view/CoordinatesNode' );
  const GQColors = require( 'GRAPHING_QUADRATICS/common/GQColors' );
  const GQConstants = require( 'GRAPHING_QUADRATICS/common/GQConstants' );
  const graphingQuadratics = require( 'GRAPHING_QUADRATICS/graphingQuadratics' );
  const Node = require( 'SCENERY/nodes/Node' );
  const NullableIO = require( 'TANDEM/types/NullableIO' );
  const Tandem = require( 'TANDEM/Tandem' );
  const Vector2 = require( 'DOT/Vector2' );
  const Vector2IO = require( 'DOT/Vector2IO' );

  // constants
  const COORDINATES_X_SPACING = 15; // between root point and its coordinates display

  class RootsNode extends Node {

    /**
     * @param {Property.<Quadratic>} quadraticProperty - the interactive quadratic
     * @param {Graph} graph
     * @param {ModelViewTransform2} modelViewTransform
     * @param {BooleanProperty} rootsVisibleProperty
     * @param {BooleanProperty} coordinatesVisibleProperty
     * @param {Object} [options]
     */
    constructor( quadraticProperty, graph, modelViewTransform,
                 rootsVisibleProperty, coordinatesVisibleProperty, options ) {

      options = _.extend( {
        radius: 10,
        tandem: Tandem.required
      }, options );

      // points
      const pointOptions = {
        fill: GQColors.ROOTS,
        center: modelViewTransform.modelToViewXY( graph.xRange.getCenter(), graph.yRange.getCenter() )
      };
      const leftRootNode = new Circle( options.radius, pointOptions );
      const rightRootNode = new Circle( options.radius, pointOptions );
      
      // options common to both Property instances
      const coordinatesPropertyOptions = {
        isValidValue: value => ( value instanceof Vector2 || value === null ),
        phetioType: DerivedPropertyIO( NullableIO( Vector2IO ) )
      };

      // coordinates corresponding to the quadratic's left or single root (if it has roots)
      const leftCoordinatesProperty = new DerivedProperty( [ quadraticProperty ],
        quadratic => ( quadratic.roots && quadratic.roots.length > 0 ) ? quadratic.roots[ 0 ] : null, 
        _.extend( {}, coordinatesPropertyOptions, {
          phetioDocumentation: 'coordinates displayed on the left (first) root, ' +
                               'null if there are no roots or if all points are roots'
        } ) );

      // coordinates corresponding to the quadratic's right root, if it has 2 roots
      const rightCoordinatesProperty = new DerivedProperty( [ quadraticProperty ],
        quadratic => ( quadratic.roots && quadratic.roots.length === 2 ) ? quadratic.roots[ 1 ] : null, 
        _.extend( {}, coordinatesPropertyOptions, {
          phetioDocumentation: 'coordinates displayed on the right (second) root, ' +
                               'null if there are less that two roots or if all points are roots'
        } ) );

      // options common to both CoordinatesNode instances 
      const coordinatesNodeOptions = {
        foregroundColor: 'white',
        backgroundColor: GQColors.ROOTS,
        decimals: GQConstants.ROOTS_DECIMALS
      };
      
      // coordinate displays
      const leftCoordinatesNode = new CoordinatesNode( leftCoordinatesProperty, coordinatesNodeOptions );
      const rightCoordinatesNode = new CoordinatesNode( rightCoordinatesProperty, coordinatesNodeOptions );

      // decorate root with coordinates
      leftRootNode.addChild( leftCoordinatesNode );
{'fraction_non_alphanumeric': 0.09509043927648579, 'fraction_numerical': 0.006201550387596899, 'mean_word_length': 3.135149572649573, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '501922', 'n_tokens_mistral': 2174, 'n_tokens_neox': 2064, 'n_words': 602}