<commit_before>EPSILON = 1e-5
COPLANAR = 0
FRONT = 1
BACK = 2
SPANNING = 3

# Call the callback with no arguments
# then return the first value.
# Used to construct chainable
# callbacks
returning = (value, fn) ->
  fn()
  value

class Timelimit
  constructor: (@timeout) -> "NOTHING"

  check: =>
    return unless @started?
    returning (elapsed = (Date.now() - @started)), =>
      if elapsed >= @timeout ? Infinity
        throw new Error("Timeout reached: #{elapsed}/#{@timeout}")

  start: =>
    @started ?= Date.now()
    @tasks ?= 0
    @tasks += 1
    do @check

  finish: =>
    throw new Error("Finished more tasks than started") if @tasks? and @tasks < 1
    @tasks -= 1
    elapsed = @check()
    @done ?= 0
    @done += 1
    if @tasks == 0
      console.log "All #{@done} tasks finished. #{elapsed}/#{@timeout ? 'Inf'}ms"
      @started = @done = undefined

  doTask: (block) =>
    do @start
    result = block()
    do @finish
    result


##
## ThreBSP Driver
#
# Can be instantiated with THREE.Geometry,
# THREE.Mesh or a ThreeBSP.Node
class window.ThreeBSP
  constructor: (treeIsh, @matrix, @options={}) ->
    if @matrix? and not (@matrix instanceof THREE.Matrix4)
      @options = @matrix
      @matrix = undefined

    @options ?= {}
    @matrix ?= new THREE.Matrix4()

    # Start a timer if one wasn't passed
    @options.timer ?= new Timelimit(@options.timer?.timeout ? @options.timeout)

    @tree   = @toTree treeIsh

  toTree: (treeIsh) =>
    return treeIsh if treeIsh instanceof ThreeBSP.Node
    polygons = []
    geometry =
      if treeIsh instanceof THREE.Geometry
        treeIsh
      else if treeIsh instanceof THREE.Mesh
        treeIsh.updateMatrix()
        @matrix = treeIsh.matrix.clone()
        treeIsh.geometry

    for face, i in geometry.faces<commit_msg>ThreeBSP.withTimer(t, fn) helper to replace a timer during an operation<commit_after>EPSILON = 1e-5
COPLANAR = 0
FRONT = 1
BACK = 2
SPANNING = 3

# Call the callback with no arguments
# then return the first value.
# Used to construct chainable
# callbacks
returning = (value, fn) ->
  fn()
  value

class Timelimit
  constructor: (@timeout) -> "NOTHING"

  check: =>
    return unless @started?
    returning (elapsed = (Date.now() - @started)), =>
      if elapsed >= @timeout ? Infinity
        throw new Error("Timeout reached: #{elapsed}/#{@timeout}")

  start: =>
    @started ?= Date.now()
    @tasks ?= 0
    @tasks += 1
    do @check

  finish: =>
    throw new Error("Finished more tasks than started") if @tasks? and @tasks < 1
    @tasks -= 1
    elapsed = @check()
    @done ?= 0
    @done += 1
    if @tasks == 0
      console.log "All #{@done} tasks finished. #{elapsed}/#{@timeout ? 'Inf'}ms"
      @started = @done = undefined

  doTask: (block) =>
    do @start
    result = block()
    do @finish
    result


##
## ThreBSP Driver
#
# Can be instantiated with THREE.Geometry,
# THREE.Mesh or a ThreeBSP.Node
class window.ThreeBSP
  constructor: (treeIsh, @matrix, @options={}) ->
    if @matrix? and not (@matrix instanceof THREE.Matrix4)
      @options = @matrix
      @matrix = undefined

    @options ?= {}
    @matrix ?= new THREE.Matrix4()

    # Start a timer if one wasn't passed
    @options.timer ?= new Timelimit(@options.timer?.timeout ? @options.timeout)

    @tree   = @toTree treeIsh

  # Evaluate block after replacing @timer with new_timer
  # then put @timer back after block returns
  withTimer: (new_timer, block) =>
    old_timer = @options.timer
    try
      @options.timer = new_timer
      do block
    finally
      @options.timer = old_timer

  toTree: (treeIsh) =>
    return treeIsh if treeIsh instanceof ThreeBSP.Node
    polygons = []
    geometry =
      if treeIsh instanceof THREE.Geometry
        treeIsh
      else if treeIsh instanceof THREE.Mesh
        treeIsh.updateMatrix()
        @matrix = treeIsh.matrix.clone()
        treeIsh.geometry

    for face, i in geometry.faces
{'fraction_non_alphanumeric': 0.12214321990858304, 'fraction_numerical': 0.007618080243778568, 'mean_word_length': 2.7514285714285713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 24, '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': '725432', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1253, 'n_words': 395}