<commit_before>/*exported Selection*/
var Selection = (function() {
  'use strict';

  var selection = {
    // Element to attach event listeners.
    el: null,
    // Array of objects to hit test.
    objects: [],
    // Array of selected objects.
    array: [],
    // Radius for valid hits.
    radius: 8,
  };

  selection.setElement = function( el ) {
    if ( !el ) {
      return;
    }

    // Remove event listeners from previous element.
    if ( selection.el ) {
      selection.el.removeEventListener( 'mousedown', onMouseDown );
      selection.el.removeEventListener( 'mousemove', onMouseMove );
      selection.el.removeEventListener( 'mouseup', onMouseUp );
    }

    selection.el = el;
    el.addEventListener( 'mousedown', onMouseDown );
    el.addEventListener( 'mousemove', onMouseMove );
    el.addEventListener( 'mouseup', onMouseUp );
  };

  var mouse = {
    x: 0,
    y: 0,

    down: false
  };

  function mousePosition( event ) {
    if ( !selection.el ) {
      return;
    }

    mouse.x = event.pageX - selection.el.offsetLeft;
    mouse.y = event.pageY - selection.el.offsetTop;
  }

  function onMouseDown( event ) {
    mousePosition( event );
    mouse.down = true;
  }

  function onMouseMove( event ) {
    mousePosition( event );
  }

  function onMouseUp() {
    mouse.down = false;
  }

  return selection;
}) ();
<commit_msg>Add Selection hit-testing and translation.<commit_after>/*globals Geometry*/
/*exported Selection*/
var Selection = (function() {
  'use strict';

  var selection = {
    // Element to attach event listeners.
    el: null,
    // Array of objects to hit test.
    objects: [],
    // Array of selected objects.
    array: [],
    // Offsets of selected objects.
    offsets: [],
    // Radius for valid hits.
    radius: 8,
  };

  selection.setElement = function( el ) {
    if ( !el ) {
      return;
    }

    // Remove event listeners from previous element.
    if ( selection.el ) {
      selection.el.removeEventListener( 'mousedown', onMouseDown );
      selection.el.removeEventListener( 'mousemove', onMouseMove );
      selection.el.removeEventListener( 'mouseup', onMouseUp );
    }

    selection.el = el;
    el.addEventListener( 'mousedown', onMouseDown );
    el.addEventListener( 'mousemove', onMouseMove );
    el.addEventListener( 'mouseup', onMouseUp );
  };

  var mouse = {
    x: 0,
    y: 0,

    down: false
  };

  function mousePosition( event ) {
    if ( !selection.el ) {
      return;
    }

    mouse.x = event.pageX - selection.el.offsetLeft;
    mouse.y = event.pageY - selection.el.offsetTop;
  }

  function onMouseDown( event ) {
    mousePosition( event );
    mouse.down = true;

    var radius = selection.radius;
    var radiusSquared = radius * radius;
    var object;
    var distanceSquared;
    for ( var i = 0, il = selection.objects.length; i < il; i++ ) {
      object = selection.objects[i];

      distanceSquared = Geometry.distanceSquared(
        mouse.x, mouse.y,
        object.x, object.y
      );

      if ( distanceSquared < radiusSquared ) {
        selection.array.push( object );
        selection.offsets.push({
          x: object.x - mouse.x,
          y: object.y - mouse.y
        });

        return;
      }
    }
  }

  function onMouseMove( event ) {
    mousePosition( event );

    selection.objects.forEach(function( object, index ) {
      object.x = mouse.x + selection.offsets[ index ].x;
      object.y = mouse.y + selection.offsets[ index ].y;
    });
  }

  function onMouseUp() {
    mouse.down = false;

    selection.array = [];
    selection.offsets = [];
  }

  return selection;
}) ();

{'fraction_non_alphanumeric': 0.12884615384615383, 'fraction_numerical': 0.0019230769230769232, 'mean_word_length': 2.3373052245646195, 'pattern_counts': {'":': 0, '<': 5, '<?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': '7080913', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1101, 'n_words': 279}