<commit_before>const buffer = require("@turf/buffer");
const { featureCollection } = require("@turf/helpers");
const { flattenReduce } = require("@turf/meta");
const geojsonRbush = require("geojson-rbush");
const martinez = require("martinez-polygon-clipping");

const countries = require("./countries.json");

// break apart multi* geometries for faster intersections
const features = featureCollection(
  flattenReduce(
    countries,
    (acc, currentFeature) => acc.concat(currentFeature),
    []
  )
);

const COUNTRY_INDEX = geojsonRbush();

COUNTRY_INDEX.load(features);

module.exports = feature => {
  if (["Point", "LineString"].includes(feature.geometry.type)) {
    feature = buffer(feature, 0.000001, { units: "degrees" });
  }

  if (feature.properties.id === "576508727") {
    return ["IDN"];
  }

  return COUNTRY_INDEX.search(feature)
    .features.filter(x => {
      try {
        const i = martinez.intersection(
          x.geometry.coordinates,
          feature.geometry.coordinates
        );

        return i != null && i.length > 0;
      } catch (err) {
        // buffer to convert to a Polygon
        const i = martinez.intersection(
          x.geometry.coordinates,
          buffer(feature, 0.000001, { units: "degrees" }).geometry.coordinates
        );

        return i != null && i.length > 0;
      }
    })
    .map(x => x.properties.ADM0_A3);
};<commit_msg>Add a comment about the workaround<commit_after>const buffer = require("@turf/buffer");
const { featureCollection } = require("@turf/helpers");
const { flattenReduce } = require("@turf/meta");
const geojsonRbush = require("geojson-rbush");
const martinez = require("martinez-polygon-clipping");

const countries = require("./countries.json");

// break apart multi* geometries for faster intersections
const features = featureCollection(
  flattenReduce(
    countries,
    (acc, currentFeature) => acc.concat(currentFeature),
    []
  )
);

const COUNTRY_INDEX = geojsonRbush();

COUNTRY_INDEX.load(features);

module.exports = feature => {
  if (["Point", "LineString"].includes(feature.geometry.type)) {
    feature = buffer(feature, 0.000001, { units: "degrees" });
  }

  // workaround for https://github.com/w8r/martinez/issues/74
  if (feature.properties.id === "576508727") {
    return ["IDN"];
  }

  return COUNTRY_INDEX.search(feature)
    .features.filter(x => {
      try {
        const i = martinez.intersection(
          x.geometry.coordinates,
          feature.geometry.coordinates
        );

        return i != null && i.length > 0;
      } catch (err) {
        // buffer to convert to a Polygon
        const i = martinez.intersection(
          x.geometry.coordinates,
          buffer(feature, 0.000001, { units: "degrees" }).geometry.coordinates
        );

        return i != null && i.length > 0;
      }
    })
    .map(x => x.properties.ADM0_A3);
};
{'fraction_non_alphanumeric': 0.14647691773689692, 'fraction_numerical': 0.019784796945505032, 'mean_word_length': 3.01952580195258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 1, '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': '4087517', 'n_tokens_mistral': 957, 'n_tokens_neox': 878, 'n_words': 188}