<commit_before># this funky syntax is to prevent `Leap` from resolving to
# `Jax.Input.Leap` within the class definition.
Jax.Input.Leap = class _Leap extends Jax.Input
  Jax.Input.devices.push this

  alias: 'leap'

  ###
  Resets captures and tracking variables. Used for teardown.
  ###
  _reset: ->
    @_captures = []
    @_hands = {}

  ###
  Removes duplicate captures from the captures list, so that events are not
  processed more than once per frame.
  ###
  _clearDuplicateCaptures: ->
    for capture in @_captures
      lastIndex = @_captures.lastIndexOf(capture)
      if @_captures.indexOf(capture) isnt lastIndex
        @_captures.splice lastIndex, 1
        return @_clearDuplicateCaptures()
    true

  constructor: ->
    super arguments...
    @_frameRotatedEvent = {}
    @_frameScaledEvent = {}
    @_frameTranslatedEvent = {}
    @_handAddedEvent = {}
    @_handRemovedEvent = {}
    @_frameEvent = {}
    @_handUpdatedEvent = {}
    @_handRotatedEvents = []
    @_handScaledEvents = []
    @_handTranslatedEvents = []
    @_gestureCircledEvents = []
    @_gestureSwipedEvents = []
    @_gestureScreenTappedEvents = []
    @_gestureKeyTappedEvents = []
    @_reset()

  update: (timechange) ->
    super timechange
    @lastFrame = @currentFrame

  startLooping: ->
    return if @looping
    # TODO don't enable gestures if they are not being used
    Leap.loop {enableGestures: true}, (data) => @loop data
    @looping = true

  stopListening: ->
    super()
    @_reset()

  register: (controller) ->
    if typeof(Leap) is 'undefined'
      console.log 'Your controller is listening for Leap Motion actions, but Leap could not be found.'
      console.log '  Did you include leap.js?'
      return
    
    if controller.on_leap_frame
      @startLooping()
      @_captures.push 'captureFrame'
      @on 'frame', (data) => controller.on_leap_frame data
    if controller.leap_frame_rotated
      @startLooping()
      @_captures.push 'captureFrameRotation'
      @on 'frameRotate', (data) -> controller.leap_frame_rotated data
    if controller.leap_frame_scaled
      @startLooping()
      @_captures.push 'captureFrameScale'
      @on 'frameScale', (data) -> controller.leap_frame_scaled data
    if func = controller.leap_frame_translated || controller.leap_frame_moved
      @startLooping()
      @_captures.push 'captureFrameTranslate'
      @on 'frameTranslate', (data) -> func.call controller, data
    if controller.leap_hand_added
      @startLooping()
      @_captures.push 'captureHandAdd'
      @on 'handAdd', (data) -> controller.leap_hand_added data
    if controller.leap_hand_removed
      @startLooping()
      @_captures.push 'captureHandAdd'
      @_captures.push 'captureHandRemove'
      @on 'handRemove', (data) -> controller.leap_hand_removed data
    if controller.leap_hands_updated
      @startLooping()
      @_captures.push 'captureHandAdd'
      @_captures.push 'captureHandRemove'
      @_captures.push 'captureHandUpdate'
      @on 'handUpdate', (data) -> controller.leap_hands_updated data
    if controller.leap_hand_rotated
      @startLooping()
      @_captures.push 'captureHandRotate'
      @on 'handRotate', (events) ->
        for event in events
          controller.leap_hand_rotated event
        true
    if controller.leap_hand_scaled
      @startLooping()
      @_captures.push 'captureHandScale'
      @on 'handScale', (events) ->
        for event in events
          controller.leap_hand_scaled event
        true
    if func = controller.leap_hand_translated || controller.leap_hand_moved
      @startLooping()
      @_captures.push 'captureHandTranslate'
      @on 'handTranslate', (events) ->
        for event in events
          func.call controller, event
        true
    if controller.leap_gesture_circled
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureCircle', (events) ->
        for event in events
          controller.leap_gesture_circled event
        true
    if controller.leap_gesture_swiped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureSwipe', (events) ->
        for event in events
          controller.leap_gesture_swiped event
        true
    if controller.leap_gesture_key_tapped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureKeyTap', (events) ->
        for event in events
          controller.leap_gesture_key_tapped event
        true
    if controller.leap_gesture_screen_tapped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureScreenTap', (events) ->
        for event in events
          controller.leap_gesture_screen_tapped event
        true
    @_clearDuplicateCaptures()

  loop: (frame) ->
    @currentFrame = frame
    for capture in @_captures
      @[capture] frame<commit_msg>refactor leap input, maybe a little more comprehensible (?)<commit_after># this funky syntax is to prevent `Leap` from resolving to
# `Jax.Input.Leap` within the class definition.
Jax.Input.Leap = class _Leap extends Jax.Input
  Jax.Input.devices.push this

  alias: 'leap'

  ###
  Resets captures and tracking variables. Used for teardown.
  ###
  _reset: ->
    @_captures = []
    @_hands = {}

  ###
  Removes duplicate captures from the captures list, so that events are not
  processed more than once per frame.
  ###
  _clearDuplicateCaptures: ->
    for capture in @_captures
      lastIndex = @_captures.lastIndexOf(capture)
      if @_captures.indexOf(capture) isnt lastIndex
        @_captures.splice lastIndex, 1
        return @_clearDuplicateCaptures()
    true

  constructor: ->
    super arguments...
    @_frameRotatedEvent = {}
    @_frameScaledEvent = {}
    @_frameTranslatedEvent = {}
    @_handAddedEvent = {}
    @_handRemovedEvent = {}
    @_frameEvent = {}
    @_handUpdatedEvent = {}
    @_handRotatedEvents = []
    @_handScaledEvents = []
    @_handTranslatedEvents = []
    @_gestureCircledEvents = []
    @_gestureSwipedEvents = []
    @_gestureScreenTappedEvents = []
    @_gestureKeyTappedEvents = []
    @_reset()

  update: (timechange) ->
    super timechange
    @lastFrame = @currentFrame

  startLooping: ->
    return if @looping
    # TODO don't enable gestures if they are not being used
    Leap.loop {enableGestures: true}, (data) => @loop data
    @looping = true

  stopListening: ->
    super()
    @_reset()

  register: (controller) ->
    if typeof(Leap) is 'undefined'
      console.log 'Your controller is listening for Leap Motion actions, but Leap could not be found.'
      console.log '  Did you include leap.js?'
      return
    
    @registerLeapFrame           controller
    @registerFrameRotated        controller
    @registerFrameScaled         controller
    @registerFrameTranslated     controller
    @registerHandAdded           controller
    @registerHandRemoved         controller
    @registerHandsUpdated        controller
    @registerHandRotated         controller
    @registerHandScaled          controller
    @registerHandTranslated      controller
    @registerGestureCircled      controller
    @registerGestureSwiped       controller
    @registerGestureKeyTapped    controller
    @registerGestureScreenTapped controller
    @_clearDuplicateCaptures()

  registerLeapFrame: (controller) ->
    if controller.on_leap_frame
      @startLooping()
      @_captures.push 'captureFrame'
      @on 'frame', (data) => controller.on_leap_frame data

  registerFrameRotated: (controller) ->
    if controller.leap_frame_rotated
      @startLooping()
      @_captures.push 'captureFrameRotation'
      @on 'frameRotate', (data) -> controller.leap_frame_rotated data

  registerFrameScaled: (controller) ->
    if controller.leap_frame_scaled
      @startLooping()
      @_captures.push 'captureFrameScale'
      @on 'frameScale', (data) -> controller.leap_frame_scaled data

  registerFrameTranslated: (controller) ->
    if controller.leap_frame_translated || controller.leap_frame_moved
      @startLooping()
      @_captures.push 'captureFrameTranslate'
      @on 'frameTranslate', (data) ->
        (controller.leap_frame_translated || controller.leap_frame_moved) data

  registerHandAdded: (controller) ->
    if controller.leap_hand_added
      @startLooping()
      @_captures.push 'captureHandAdd'
      @on 'handAdd', (data) -> controller.leap_hand_added data

  registerHandRemoved: (controller) ->
    if controller.leap_hand_removed
      @startLooping()
      @_captures.push 'captureHandAdd'
      @_captures.push 'captureHandRemove'
      @on 'handRemove', (data) -> controller.leap_hand_removed data

  registerHandsUpdated: (controller) ->
    if controller.leap_hands_updated
      @startLooping()
      @_captures.push 'captureHandAdd'
      @_captures.push 'captureHandRemove'
      @_captures.push 'captureHandUpdate'
      @on 'handUpdate', (data) -> controller.leap_hands_updated data

  registerHandRotated: (controller) ->
    if controller.leap_hand_rotated
      @startLooping()
      @_captures.push 'captureHandRotate'
      @on 'handRotate', (events) ->
        for event in events
          controller.leap_hand_rotated event
        true

  registerHandScaled: (controller) ->
    if controller.leap_hand_scaled
      @startLooping()
      @_captures.push 'captureHandScale'
      @on 'handScale', (events) ->
        for event in events
          controller.leap_hand_scaled event
        true

  registerHandTranslated: (controller) ->
    if controller.leap_hand_translated || controller.leap_hand_moved
      @startLooping()
      @_captures.push 'captureHandTranslate'
      @on 'handTranslate', (events) ->
        for event in events
          (controller.leap_hand_translated || controller.leap_hand_moved) event
        true

  registerGestureCircled: (controller) ->
    if controller.leap_gesture_circled
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureCircle', (events) ->
        for event in events
          controller.leap_gesture_circled event
        true

  registerGestureSwiped: (controller) ->
    if controller.leap_gesture_swiped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureSwipe', (events) ->
        for event in events
          controller.leap_gesture_swiped event
        true

  registerGestureKeyTapped: (controller) ->
    if controller.leap_gesture_key_tapped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureKeyTap', (events) ->
        for event in events
          controller.leap_gesture_key_tapped event
        true

  registerGestureScreenTapped: (controller) ->
    if controller.leap_gesture_screen_tapped
      @startLooping()
      @_captures.push 'captureGestures'
      @on 'gestureScreenTap', (events) ->
        for event in events
          controller.leap_gesture_screen_tapped event
        true

  loop: (frame) ->
    @currentFrame = frame
    for capture in @_captures
      @[capture] frame
{'fraction_non_alphanumeric': 0.09238338192419825, 'fraction_numerical': 0.00018221574344023323, 'mean_word_length': 2.9556756756756757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 63, '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': '4150310', 'n_tokens_mistral': 3464, 'n_tokens_neox': 3327, 'n_words': 751}