<commit_before>/*
Recognizer

Defines how different input devices are normalized into
pointer id, x, and y.

Keep all taaspace-related stuff in Manager.
Keep Recognizer compatible with all html elements.

Notes:
  [1] Count them the hard way to avoid difference between a possible counter
      and the actual number of pointers. An "easy" way would be to maintain
      a variable that keeps record on the number of fingers.
  [2] Clone always. Only the clone can be modified.
      Take this functional approach to avoid bugs. We experienced
      a situation where modification of the pointers caused
      suprising state changes outside of Recognizer.
*/

var clone = function (obj) {
  // Shallow object copy
  var k
  var res = {}

  for (k in obj) {
    if (obj.hasOwnProperty(k)) {
      res[k] = obj[k]
    }
  }

  return res
}

var cardinality = function (obj) {
  // Number of own properties
  var k
  var res = 0

  for (k in obj) {
    if (obj.hasOwnProperty(k)) {
      res += 1
    }
  }

  return res
}

var Recognizer = function (element, handlers) {
  // Parameters:
  //   element
  //     HTMLElement to listen to
  //   handlers
  //     start
  //       function (firstPointers)
  //     move
  //       function (prevPointers, nextPointers)
  //     end
  //       function (lastPointers)
  //

  // We need to remember listeners we make to be able to remove them
  // and only them.
  this.element = element
  this.listeners = {}

  // Gesture started
  var started = false

  // Mouse pressed down
  var mouseDown = false

  // Current active pointers
  var currPointers = {}

  // Touch support

  var onTouchStart = function (ev) {
    var cts, i, nextPointers
    ev.preventDefault()
    ev.stopPropagation()

    var nextPointers = clone(currPointers) // See [2]

    cts = ev.changedTouches
    for (i = 0; i < cts.length; i += 1) {
      nextPointers[cts[i].identifier] = [cts[i].pageX, cts[i].pageY]
    }

    if (!started) {
      started = true
      handlers.start(nextPointers)
    }

    currPointers = nextPointers
  }

  var onTouchMove = function (ev) {
    var cts, i, nextPointers
    ev.preventDefault()
    ev.stopPropagation()

    nextPointers = clone(currPointers)

    cts = ev.changedTouches
    for (i = 0; i < cts.length; i += 1) {
      nextPointers[cts[i].identifier] = [cts[i].pageX, cts[i].pageY]
    }

    if (started) {
      handlers.move(currPointers, nextPointers)
    }
<commit_msg>Remove extra var<commit_after>/*
Recognizer

Defines how different input devices are normalized into
pointer id, x, and y.

Keep all taaspace-related stuff in Manager.
Keep Recognizer compatible with all html elements.

Notes:
  [1] Count them the hard way to avoid difference between a possible counter
      and the actual number of pointers. An "easy" way would be to maintain
      a variable that keeps record on the number of fingers.
  [2] Clone always. Only the clone can be modified.
      Take this functional approach to avoid bugs. We experienced
      a situation where modification of the pointers caused
      suprising state changes outside of Recognizer.
*/

var clone = function (obj) {
  // Shallow object copy
  var k
  var res = {}

  for (k in obj) {
    if (obj.hasOwnProperty(k)) {
      res[k] = obj[k]
    }
  }

  return res
}

var cardinality = function (obj) {
  // Number of own properties
  var k
  var res = 0

  for (k in obj) {
    if (obj.hasOwnProperty(k)) {
      res += 1
    }
  }

  return res
}

var Recognizer = function (element, handlers) {
  // Parameters:
  //   element
  //     HTMLElement to listen to
  //   handlers
  //     start
  //       function (firstPointers)
  //     move
  //       function (prevPointers, nextPointers)
  //     end
  //       function (lastPointers)
  //

  // We need to remember listeners we make to be able to remove them
  // and only them.
  this.element = element
  this.listeners = {}

  // Gesture started
  var started = false

  // Mouse pressed down
  var mouseDown = false

  // Current active pointers
  var currPointers = {}

  // Touch support

  var onTouchStart = function (ev) {
    var cts, i, nextPointers
    ev.preventDefault()
    ev.stopPropagation()

    nextPointers = clone(currPointers) // See [2]

    cts = ev.changedTouches
    for (i = 0; i < cts.length; i += 1) {
      nextPointers[cts[i].identifier] = [cts[i].pageX, cts[i].pageY]
    }

    if (!started) {
      started = true
      handlers.start(nextPointers)
    }

    currPointers = nextPointers
  }

  var onTouchMove = function (ev) {
    var cts, i, nextPointers
    ev.preventDefault()
    ev.stopPropagation()

    nextPointers = clone(currPointers)

    cts = ev.changedTouches
    for (i = 0; i < cts.length; i += 1) {
      nextPointers[cts[i].identifier] = [cts[i].pageX, cts[i].pageY]
    }

    if (started) {
      handlers.move(currPointers, nextPointers)
    }

{'fraction_non_alphanumeric': 0.0985080727569998, 'fraction_numerical': 0.003678724708767627, 'mean_word_length': 2.4175977653631286, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5958027', 'n_tokens_mistral': 1646, 'n_tokens_neox': 1553, 'n_words': 525}