<commit_before>// Copyright 2013, University of Colorado

/**
 * Scenery node that represents a single-ended arrow.
 */
define( function( require ) {
  'use strict';

  // imports
  var assert = require( 'ASSERT/assert' )( 'scenery-phet' );
  var inherit = require( "PHET_CORE/inherit" );
  var Node = require( "SCENERY/nodes/Node" );
  var Path = require( "SCENERY/nodes/Path" );
  var Shape = require( "KITE/Shape" );
  var Vector2 = require( "DOT/Vector2" );
  var Rectangle = require( "SCENERY/nodes/Rectangle" );

  /**
   * @param {Vector2} tailLocation
   * @param {Vector2} tipLocation
   * @param {number} headHeight
   * @param {number} headWidth
   * @param {number} tailWidth
   * @constructor
   */
  function ArrowNode( tailLocation, tipLocation, headHeight, headWidth, tailWidth, options ) {

    this.tailLocation = tailLocation;
    this.tipLocation = tipLocation;
    this.headHeight = headHeight;
    this.headWidth = headWidth;
    this.tailWidth = tailWidth;

    // default options
    options = _.extend(
        {
          fill: 'black',
          stroke: 'black',
          lineWidth: 1
        }, options );

    // things you're likely to mess up, add more as needed
    assert && assert( headWidth >= tailWidth );

    // Call super constructor.
    Node.call( this, options );

    this.path = new Path( options );
    this.addChild( this.path );
    this.updateShape();
  }

  inherit( Node, ArrowNode, {
    updateShape: function(){
      this.path.shape = this._createArrowShape( this.tailLocation.x, this.tailLocation.y, this.tipLocation.x, this.tipLocation.y, this.tailWidth, this.headWidth, this.headHeight );
      this.addChild( this.path );
    },
    _createArrowShape: function ( tailX, tailY, tipX, tipY, tailWidth, headWidth, headHeight ) {   //All parameters are Number
      var arrowShape = new Shape();
      if ( tipX === tailX && tipY === tailY ) {
        return arrowShape;
      }
      var vector = new Vector2( tipX - tailX, tipY - tailY );
      var xHatUnit = vector.normalized();
      var yHatUnit = xHatUnit.rotated( Math.PI / 2 );
      var length = vector.magnitude();

      //Set up a coordinate frame that goes from the tail of the arrow to the tip.
      function getPoint( xHat, yHat ) {
        var x = xHatUnit.x * xHat + yHatUnit.x * yHat + tailX;
        var y = xHatUnit.y * xHat + yHatUnit.y * yHat + tailY;
        return new Vector2( x, y );
      }

      if ( headHeight > length / 2 ) {
        headHeight = length / 2;
      }

      var tailLength = length - headHeight;
      var points = [
        getPoint( 0, tailWidth / 2 ),
        getPoint( tailLength, tailWidth / 2 ),
        getPoint( tailLength, headWidth / 2 ),
        getPoint( length, 0 ),
        getPoint( tailLength, -headWidth / 2 ),
        getPoint( tailLength, -tailWidth / 2 ),
        getPoint( 0, -tailWidth / 2 )
      ];

      arrowShape.moveTo( points[0].x, points[0].y );
      var tail = _.tail( points );
      _.each( tail, function( element ) { arrowShape.lineTo( element.x, element.y ); } );
      arrowShape.close();

      return arrowShape;
    }
  } );

  return ArrowNode;
} );<commit_msg>Made some simplifications.<commit_after>// Copyright 2013, University of Colorado

/**
 * Scenery node that represents a single-ended arrow.
 */
define( function( require ) {
  'use strict';

  // imports
  var assert = require( 'ASSERT/assert' )( 'scenery-phet' );
  var inherit = require( "PHET_CORE/inherit" );
  var Node = require( "SCENERY/nodes/Node" );
  var Path = require( "SCENERY/nodes/Path" );
  var Shape = require( "KITE/Shape" );
  var Vector2 = require( "DOT/Vector2" );
  var Rectangle = require( "SCENERY/nodes/Rectangle" );

  /**
   * @param {number} tailX
   * @param {number} tailY
   * @param {number} tipX
   * @param {number} tipY
   * @param {number} headHeight
   * @param {number} headWidth
   * @param {number} tailWidth
   * @constructor
   */
  function ArrowNode( tailX, tailY, tipX, tipY, headHeight, headWidth, tailWidth, options ) {

    // default options
    options = _.extend(
        {
          fill: 'black',
          stroke: 'black',
          lineWidth: 1
        }, options );

    // things you're likely to mess up, add more as needed
    assert && assert( headWidth >= tailWidth );

    // Call super constructor.
    Node.call( this, options );

    // Function for creating arrow shape.  All parameters are of type number.
    var createArrowShape = function( tailX, tailY, tipX, tipY, tailWidth, headWidth, headHeight ) {
      var arrowShape = new Shape();
      if ( tipX === tailX && tipY === tailY ) {
        return arrowShape;
      }
      var vector = new Vector2( tipX - tailX, tipY - tailY );
      var xHatUnit = vector.normalized();
      var yHatUnit = xHatUnit.rotated( Math.PI / 2 );
      var length = vector.magnitude();

      //Set up a coordinate frame that goes from the tail of the arrow to the tip.
      function getPoint( xHat, yHat ) {
        var x = xHatUnit.x * xHat + yHatUnit.x * yHat + tailX;
        var y = xHatUnit.y * xHat + yHatUnit.y * yHat + tailY;
        return new Vector2( x, y );
      }

      if ( headHeight > length / 2 ) {
        headHeight = length / 2;
      }

      var tailLength = length - headHeight;
      var points = [
        getPoint( 0, tailWidth / 2 ),
        getPoint( tailLength, tailWidth / 2 ),
        getPoint( tailLength, headWidth / 2 ),
        getPoint( length, 0 ),
        getPoint( tailLength, -headWidth / 2 ),
        getPoint( tailLength, -tailWidth / 2 ),
        getPoint( 0, -tailWidth / 2 )
      ];

      arrowShape.moveTo( points[0].x, points[0].y );
      var tail = _.tail( points );
      _.each( tail, function( element ) { arrowShape.lineTo( element.x, element.y ); } );
      arrowShape.close();

      return arrowShape;
    }

    this.path = new Path( options );
    this.path.shape = createArrowShape( tailX, tailY, tipX, tipY, tailWidth, headWidth, headHeight );
    this.addChild( this.path );
  }

  inherit( Node, ArrowNode );

  return ArrowNode;
} );
{'fraction_non_alphanumeric': 0.1266490765171504, 'fraction_numerical': 0.0079155672823219, 'mean_word_length': 2.418827508455468, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '178998', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1899, 'n_words': 557}