<commit_before>export const areaAt = (layout, position) => {
  for (let i = 0; i < layout.length; i++) {
    if (
      layout[i].x < position.x + position.w &&
      layout[i].x + layout[i].w > position.x &&
      layout[i].y < position.y + position.h &&
      layout[i].y + layout[i].h > position.y
    ) {
      return layout[i]
    }
  }
  return false
}

export const moveToFreePlace = (layout, item, maxX, maxY) => {
  var newItem = cloneItem(item)
  let hasResetY = false

  while (areaAt(layout, newItem)) {
    newItem.y = newItem.y + 1
    if (newItem.y > maxY) {
      if (hasResetY) {
        newItem.y = 0
        newItem.x = 0
        return newItem
      }
      newItem.y = 0
      hasResetY = true
    }
    if (areaAt(layout, newItem)) {
      newItem.x = newItem.x + 1
      if (newItem.x > maxX) {
        newItem.x = 0
      }
    }
  }
  return newItem
}

export const cloneItem = item => {
  return Object.assign({}, item)
}

export const cloneLayout = layout => {
  return layout.map(item => {
    return cloneItem(item)<commit_msg>Fix detection of free space<commit_after>export const areaAt = (layout, position) => {
  for (let i = 0; i < layout.length; i++) {
    if (
      layout[i].x < position.x + position.w &&
      layout[i].x + layout[i].w > position.x &&
      layout[i].y < position.y + position.h &&
      layout[i].y + layout[i].h > position.y
    ) {
      return layout[i]
    }
  }
  return false
}

export const moveToFreePlace = (layout, item, maxX, maxY) => {
  var newItem = cloneItem(item)
  let startX = newItem.x
  let startY = newItem.y

  while (areaAt(layout, newItem)) {
    newItem.y = newItem.y + 1
    if (newItem.y > maxY) {
      newItem.y = 0
    }
    if (newItem.y === startY) {
      newItem.x = newItem.x + 1
      if (newItem.x > maxX) {
        newItem.x = 0
      }
    }
    if (newItem.y === startY && newItem.x === startX) {
      newItem.y = -1
      newItem.x = -1
      return newItem
    }
  }
  return newItem
}

export const cloneItem = item => {
  return Object.assign({}, item)
}

export const cloneLayout = layout => {
  return layout.map(item => {
    return cloneItem(item)
{'fraction_non_alphanumeric': 0.14537854156990246, 'fraction_numerical': 0.006502554575011612, 'mean_word_length': 2.158357771260997, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '4840453', 'n_tokens_mistral': 790, 'n_tokens_neox': 774, 'n_words': 189}