<commit_before>////////////////////////////////////////////////////////////////
// A sensor that sets a variable to 1 on contact and 0 otherwise
////////////////////////////////////////////////////////////////


var Box2D = require('box2dweb-commonjs').Box2D;
var constants = require('./../../../base/constants');

// Aliases
var b2Vec2 = Box2D.Common.Math.b2Vec2;
var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;


/**
 * Provides a whisker sensor that returns a high (1) value
 * on contact and low (0) otherwise
 * @class Whisker
 * @namespace Sensors.Base.Pressure
 * @constructor
 * @param {Object} agentObject The Agent object the sensor will
 * be attached to
 * @param {Object} specs Contains the specifications of the
 * sensor. The mandatory fields are:
 *
 *   - id: Identifier to store the sensor value
 *   - pos_x: x offset from the main body center
 *   - pos_y: y offset from the main body center
 *   - angle: angle with the main body
 *   - width: width of the sensor
 *   - height: height of the sensor
 */
function Whisker(agentObject, specs) {
  var sensorId, posX, posY, angle, width, height, whiskerShape;

  // Sensor specs
  sensorId = specs.id;
  posX     = specs.pos_x;
  posY     = specs.pos_y;
  angle    = specs.angle;
  width    = specs.width;
  height   = specs.height;

  whiskerShape = new b2PolygonShape();
  whiskerShape.SetAsOrientedBox(height, width, new b2Vec2(posX, posY), angle);
  whisker = new b2FixtureDef();

  whisker.shape = whiskerShape;
  whisker.isSensor = true;
  whisker.userData = {
    onBeginContact: function() {
      agentObject.setSensor(sensorId, 1);
    },
    onEndContact: function() {
      agentObject.setSensor(sensorId, 0);
    }
  };

  // Static objects only
  whisker.filter.maskBits = constants.MAP_OBJECT;

  agentObject.body.CreateFixture(whisker);
  return whisker;
}

exports.Whisker = Whisker;

<commit_msg>Initialize whisker value<commit_after>////////////////////////////////////////////////////////////////
// A sensor that sets a variable to 1 on contact and 0 otherwise
////////////////////////////////////////////////////////////////


var Box2D = require('box2dweb-commonjs').Box2D;
var constants = require('./../../../base/constants');

// Aliases
var b2Vec2 = Box2D.Common.Math.b2Vec2;
var b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape;
var b2FixtureDef = Box2D.Dynamics.b2FixtureDef;


/**
 * Provides a whisker sensor that returns a high (1) value
 * on contact and low (0) otherwise
 * @class Whisker
 * @namespace Sensors.Base.Pressure
 * @constructor
 * @param {Object} agentObject The Agent object the sensor will
 * be attached to
 * @param {Object} specs Contains the specifications of the
 * sensor. The mandatory fields are:
 *
 *   - id: Identifier to store the sensor value
 *   - pos_x: x offset from the main body center
 *   - pos_y: y offset from the main body center
 *   - angle: angle with the main body
 *   - width: width of the sensor
 *   - height: height of the sensor
 */
function Whisker(agentObject, specs) {
  var sensorId, posX, posY, angle, width, height, whiskerShape;

  // Sensor specs
  sensorId = specs.id;
  posX     = specs.pos_x;
  posY     = specs.pos_y;
  angle    = specs.angle;
  width    = specs.width;
  height   = specs.height;

  whiskerShape = new b2PolygonShape();
  whiskerShape.SetAsOrientedBox(height, width, new b2Vec2(posX, posY), angle);
  whisker = new b2FixtureDef();

  whisker.shape = whiskerShape;
  whisker.isSensor = true;
  whisker.userData = {
    onBeginContact: function() {
      agentObject.setSensor(sensorId, 1);
    },
    onEndContact: function() {
      agentObject.setSensor(sensorId, 0);
    }
  };

  // Initial value
  agentObject.setSensor(sensorId, 0);

  // Static objects only
  whisker.filter.maskBits = constants.MAP_OBJECT;

  agentObject.body.CreateFixture(whisker);
  return whisker;
}

exports.Whisker = Whisker;


{'fraction_non_alphanumeric': 0.16519099418163422, 'fraction_numerical': 0.012395648874272705, 'mean_word_length': 2.6076642335766422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '913889', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1240, 'n_words': 356}