<commit_before>/* 
takes a collection of polygons and returns a collection of donuts.

 foreach poly:
  foreach poly:
    poly1 = poly1.erase(poly2)
*/

var _ = require('lodash')
var t = {}
t.featurecollection = require('./featurecollection')
t.erase = require('./erase')
t.point = require('./point')
t.inside = require('./inside')

module.exports = function(polyFC, done){
  donuts = t.featurecollection([])
  _.each(polyFC.features, function(poly1){
    _.each(polyFC.features, function(poly2){
      contained(poly1, poly2, function(isContained){
        if(!_.isEqual(poly1, poly2) && isContained){
          if(!_.isEqual(poly1.properties, poly2.properties)){
            //console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
            //console.log(JSON.stringify(poly1))
            //console.log(JSON.stringify(poly2))
            t.erase(poly1, poly2, function(err, erased){
              var duplicate = _.some(donuts.features, erased)
              if(!duplicate && erased.geometry.type != 'GeometryCollection'){
                donuts.features.push(erased)
              }
            })
          }
        }
        else if(!_.isEqual(poly1, poly2)){
          var duplicate = _.some(donuts.features, poly1)
          if(!duplicate){
            donuts.features.push(poly1)
          }
        }
      })
    })
  })

  done(null, donuts)
}

function contained(poly1, poly2, done){
  var sampleVertex = t.point(poly2.geometry.coordinates[0][0][0], poly2.geometry.coordinates[0][0][1])
  t.inside(sampleVertex, poly1, function(err, isInside){
    done(isInside)
  })
}<commit_msg>cleaned up donuts<commit_after>/* 
takes a collection of polygons and returns a collection of donuts.

 foreach poly:
  foreach poly:
    poly1 = poly1.erase(poly2)
*/

var _ = require('lodash')
var t = {}
t.featurecollection = require('./featurecollection')
t.erase = require('./erase')
t.point = require('./point')
t.inside = require('./inside')

module.exports = function(polyFC, done){
  donuts = t.featurecollection([])
  _.each(polyFC.features, function(poly1){
    _.each(polyFC.features, function(poly2){
      contained(poly1, poly2, function(isContained){
        if(!_.isEqual(poly1, poly2) && isContained){
          if(!_.isEqual(poly1.properties, poly2.properties)){
            t.erase(poly1, poly2, function(err, erased){
              var duplicate = _.some(donuts.features, erased)
              if(!duplicate && erased.geometry.type != 'GeometryCollection'){
                donuts.features.push(erased)
              }
            })
          }
        }
        else if(!_.isEqual(poly1, poly2)){
          var duplicate = _.some(donuts.features, poly1)
          if(!duplicate){
            donuts.features.push(poly1)
          }
        }
      })
    })
  })
  done(null, donuts)
}

function contained(poly1, poly2, done){
  var sampleVertex = t.point(poly2.geometry.coordinates[0][0][0], poly2.geometry.coordinates[0][0][1])
  t.inside(sampleVertex, poly1, function(err, isInside){
    done(isInside)
  })
}
{'fraction_non_alphanumeric': 0.16326530612244897, 'fraction_numerical': 0.019091507570770244, 'mean_word_length': 2.715158924205379, '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': '1819319', 'n_tokens_mistral': 964, 'n_tokens_neox': 940, 'n_words': 171}