<commit_before>var bbox2extent = require('bbox2extent')
var bbox = [Infinity, Infinity, -Infinity, -Infinity]

module.exports = function (collection, callback) {
  // fallback if features passed directly
  var features = collection.features ? collection.features : collection

  features.forEach(function (f, i) {
    if (!f.geometry) return

    var isPoint = f.geometry.type === 'Point'
    var isLine = f.geometry.type === 'LineString'
    var isMultiLine = f.geometry.type === 'MultiLineString'
    var isPolygon = f.geometry.type === 'Polygon'
    var isMultiPolygon = f.geometry.type === 'MultiPolygon'
    var coords = f.geometry.coordinates

    if (isPoint) extend(bbox, coords)

    if (isLine || isMultiLine) {
      if (isMultiLine) coords = coords[0]
      coords.forEach(function (c, j) {
        extend(bbox, c)
      })
    }

    if (isPolygon || isMultiPolygon) {
      coords = isMultiPolygon ? coords[0][0] : coords[0]
      coords.forEach(function (c, j) {
        extend(bbox, c)
      })
    }
  })

  var extent = bbox2extent(bbox)

  if (callback) callback(null, extent)
  else return extent
}

function extend (bbox, coord) {
  bbox[0] = Math.min(bbox[0], coord[0])
  bbox[1] = Math.min(bbox[1], coord[1])
  bbox[2] = Math.max(bbox[2], coord[0])
  bbox[3] = Math.max(bbox[3], coord[1])
}<commit_msg>forcing all non-multi geometries to be multi<commit_after>var bbox2extent = require('bbox2extent')
var bbox = [Infinity, Infinity, -Infinity, -Infinity]

module.exports = function (collection, callback) {
  // fallback if features passed directly
  var features = collection.features ? collection.features : collection

  features.forEach(function (f, i) {
    if (!f.geometry) return

    var isPoint = f.geometry.type === 'Point'
    var isMultiPoint = f.geometry.type === 'MultiPoint'
    var isLine = f.geometry.type === 'LineString'
    var isMultiLine = f.geometry.type === 'MultiLineString'
    var isPolygon = f.geometry.type === 'Polygon'
    var isMultiPolygon = f.geometry.type === 'MultiPolygon'
    var coords = f.geometry.coordinates

    if (isPoint || isMultiPoint) {
      if (isPoint) coords = [[[coords]]]
      loop(bbox, coords)
    }

    if (isLine || isMultiLine) {
      if (isLine) coords = [[coords]]
      loop(bbox, coords)
    }

    if (isPolygon || isMultiPolygon) {
      if (isPolygon) coords = [coords]
      loop(bbox, coords)
    }
  })

  var extent = bbox2extent(bbox)

  if (callback) callback(null, extent)
  else return extent
}

function loop (bbox, coords) {
  coords.forEach(function (r, j) {
    r[0].forEach(function (c, k) {
      extend(bbox, c)
    })
  })
}

function extend (bbox, coord) {
  bbox[0] = Math.min(bbox[0], coord[0])
  bbox[1] = Math.min(bbox[1], coord[1])
  bbox[2] = Math.max(bbox[2], coord[0])
  bbox[3] = Math.max(bbox[3], coord[1])
}
{'fraction_non_alphanumeric': 0.1485148514851485, 'fraction_numerical': 0.012376237623762377, 'mean_word_length': 3.3256880733944953, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3531863', 'n_tokens_mistral': 1023, 'n_tokens_neox': 1004, 'n_words': 233}