<commit_before>var turfEnvelope = require('turf-envelope');
var turfCentroid = require('turf-centroid');

module.exports = function render() {
  var isStillAlive = this.ctx.map && this.ctx.map.getSource('mapbox-gl-draw-hot') !== undefined;
  if (isStillAlive) { // checks to make sure we still have a map
    var mode = this.ctx.events.currentModeName();
    this.ctx.ui.setClass({
      mode: mode
    });

    var features = {
      hot: [],
      cold: []
    };

    var renderCold = this.isDirty;

    var nextHistory = {};

    var pusher = (geojson) => {

      var about = geojson.properties;

      if (about.meta === 'too-small') {
        geojson.geometry = about.point.geometry;
      }

      delete about.point;

      geojson.properties = about;

      var key = about.id + '.' + about.parent + '.' + about.coord_path + '.' + (about.meta === 'too-small' ? 'feature' : about.meta);
      var value = JSON.stringify(geojson);

      var past = this.renderHistory[key];

      if (past === undefined) {
        past = { changed: 4};
      }

      var next = {
        value: value,
        changed: past.changed
      };

      if (past.value !== value && next.changed < 4) {
        next.changed ++;
      }
      else if (past.value === value && next.changed > 0) {
        next.changed--;
      }

      if (next.changed < 2) {
        features.cold.push(geojson);
        renderCold = renderCold ? true : next.changed !== past.changed;
      }
      else {
        renderCold = renderCold ? true : past.changed < 2;
        features.hot.push(geojson);
      }
      nextHistory[key] = next;
    };

    var changed = [];

    this.featureIds.forEach((id) => {
      let featureInternal = this.features[id].internal(mode);
      var coords = JSON.stringify(featureInternal.geometry.coordinates);

      if (this.ctx.store.needsUpdate(featureInternal)) {
        this.featureHistory[id] = coords;
        if (this.features[id].isValid()) {
          changed.push(this.features[id].toGeoJSON());
        }
      }

      if (featureInternal.geometry.type !== 'Point' && this.features[id].isValid()) {
        var envelope = turfEnvelope({
          type: 'FeatureCollection',
          features: [featureInternal]
        });

        var topLeftCoord = envelope.geometry.coordinates[0][0];
        var bottomRightCoord = envelope.geometry.coordinates[0][2];

        var topLeftPixels = this.ctx.map.project({
          lng: topLeftCoord[0],
          lat: topLeftCoord[1]
        });

        var bottomRightPixels = this.ctx.map.project({
          lng: bottomRightCoord[0],
          lat: bottomRightCoord[1]
        });

        var dx = Math.abs(topLeftPixels.x - bottomRightPixels.x);
        var dy = Math.abs(topLeftPixels.y - bottomRightPixels.y);

        var distance = Math.pow((dx * dx) + (dy * dy), .5);

        if (distance < 10) {<commit_msg>Fix issue where the draw.changed event payload returned all features instead of just the changed features.<commit_after>var turfEnvelope = require('turf-envelope');
var turfCentroid = require('turf-centroid');

module.exports = function render() {
  var isStillAlive = this.ctx.map && this.ctx.map.getSource('mapbox-gl-draw-hot') !== undefined;
  if (isStillAlive) { // checks to make sure we still have a map
    var mode = this.ctx.events.currentModeName();
    this.ctx.ui.setClass({
      mode: mode
    });

    var features = {
      hot: [],
      cold: []
    };

    var renderCold = this.isDirty;

    var nextHistory = {};

    var pusher = (geojson) => {

      var about = geojson.properties;

      if (about.meta === 'too-small') {
        geojson.geometry = about.point.geometry;
      }

      delete about.point;

      geojson.properties = about;

      var key = about.id + '.' + about.parent + '.' + about.coord_path + '.' + (about.meta === 'too-small' ? 'feature' : about.meta);
      var value = JSON.stringify(geojson);

      var past = this.renderHistory[key];

      if (past === undefined) {
        past = { changed: 4};
      }

      var next = {
        value: value,
        changed: past.changed
      };

      if (past.value !== value && next.changed < 4) {
        next.changed ++;
      }
      else if (past.value === value && next.changed > 0) {
        next.changed--;
      }

      if (next.changed < 2) {
        features.cold.push(geojson);
        renderCold = renderCold ? true : next.changed !== past.changed;
      }
      else {
        renderCold = renderCold ? true : past.changed < 2;
        features.hot.push(geojson);
      }
      nextHistory[key] = next;
    };

    var changed = [];

    this.featureIds.forEach((id) => {
      let feature = this.features[id];
      let featureInternal = feature.internal(mode);
      var coords = JSON.stringify(featureInternal.geometry.coordinates);

      if (feature.isValid() && this.ctx.store.needsUpdate(feature.toGeoJSON())) {
        this.featureHistory[id] = coords;
        changed.push(feature.toGeoJSON());
      }

      if (featureInternal.geometry.type !== 'Point' && this.features[id].isValid()) {
        var envelope = turfEnvelope({
          type: 'FeatureCollection',
          features: [featureInternal]
        });

        var topLeftCoord = envelope.geometry.coordinates[0][0];
        var bottomRightCoord = envelope.geometry.coordinates[0][2];

        var topLeftPixels = this.ctx.map.project({
          lng: topLeftCoord[0],
          lat: topLeftCoord[1]
        });

        var bottomRightPixels = this.ctx.map.project({
          lng: bottomRightCoord[0],
          lat: bottomRightCoord[1]
        });

        var dx = Math.abs(topLeftPixels.x - bottomRightPixels.x);
        var dy = Math.abs(topLeftPixels.y - bottomRightPixels.y);

        var distance = Math.pow((dx * dx) + (dy * dy), .5);

        if (distance < 10) {
{'fraction_non_alphanumeric': 0.14356775300171526, 'fraction_numerical': 0.005488850771869639, 'mean_word_length': 2.230470914127424, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, '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': '5724504', 'n_tokens_mistral': 1840, 'n_tokens_neox': 1741, 'n_words': 373}