<commit_before>var getCoord = require('turf-invariant').getCoord;
//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html

/**
 * Calculates the distance between two {@link Point|points} in degrees, radians,
 * miles, or kilometers. This uses the
 * [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula)
 * to account for global curvature.
 *
 * @module turf/distance
 * @category measurement
 * @param {Feature<Point>} from origin point
 * @param {Feature<Point>} to destination point
 * @param {String} [units=kilometers] can be degrees, radians, miles, or kilometers
 * @return {Number} distance between the two points
 * @example
 * var point1 = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "Point",
 *     "coordinates": [-75.343, 39.984]
 *   }
 * };
 * var point2 = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "Point",
 *     "coordinates": [-75.534, 39.123]
 *   }
 * };
 * var units = "miles";
 *
 * var points = {
 *   "type": "FeatureCollection",
 *   "features": [point1, point2]
 * };
 *
 * //=points
 *
 * var distance = turf.distance(point1, point2, units);
 *
 * //=distance
 */
module.exports = function (point1, point2, units) {
    var coordinates1 = getCoord(point1);
    var coordinates2 = getCoord(point2);
    var dLat = toRad(coordinates2[1] - coordinates1[1]);
    var dLon = toRad(coordinates2[0] - coordinates1[0]);
    var lat1 = toRad(coordinates1[1]);
    var lat2 = toRad(coordinates2[1]);

    var a = Math.pow(Math.sin(dLat / 2), 2) +
          Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    switch (units) {
    case 'miles':
        return c * 3960;
    case 'kilometers':
    case 'kilometres':
        return c * 6373;
    case 'degrees':
        return c * 57.2957795;
    case 'radians':
        return c;
    case undefined:
        return c * 6373;
    default:
        throw new Error('unknown option given to "units"');
    }
};

function toRad(degree) {
    return degree * Math.PI / 180;
}
<commit_msg>add inches, yards, metres units to distance function...unsure if configured correctly<commit_after>var getCoord = require('turf-invariant').getCoord;
//http://en.wikipedia.org/wiki/Haversine_formula
//http://www.movable-type.co.uk/scripts/latlong.html

/**
 * Calculates the distance between two {@link Point|points} in degrees, radians,
 * miles, or kilometers. This uses the
 * [Haversine formula](http://en.wikipedia.org/wiki/Haversine_formula)
 * to account for global curvature.
 *
 * @module turf/distance
 * @category measurement
 * @param {Feature<Point>} from origin point
 * @param {Feature<Point>} to destination point
 * @param {String} [units=kilometers] can be degrees, radians, miles, or kilometers
 * @return {Number} distance between the two points
 * @example
 * var point1 = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "Point",
 *     "coordinates": [-75.343, 39.984]
 *   }
 * };
 * var point2 = {
 *   "type": "Feature",
 *   "properties": {},
 *   "geometry": {
 *     "type": "Point",
 *     "coordinates": [-75.534, 39.123]
 *   }
 * };
 * var units = "miles";
 *
 * var points = {
 *   "type": "FeatureCollection",
 *   "features": [point1, point2]
 * };
 *
 * //=points
 *
 * var distance = turf.distance(point1, point2, units);
 *
 * //=distance
 */
module.exports = function (point1, point2, units) {
    var coordinates1 = getCoord(point1);
    var coordinates2 = getCoord(point2);
    var dLat = toRad(coordinates2[1] - coordinates1[1]);
    var dLon = toRad(coordinates2[0] - coordinates1[0]);
    var lat1 = toRad(coordinates1[1]);
    var lat2 = toRad(coordinates2[1]);

    var a = Math.pow(Math.sin(dLat / 2), 2) +
          Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

    switch (units) {
    case 'miles':
        return c * 3960;
    case 'kilometers':
    case 'kilometres':
        return c * 6373;
    case 'degrees':
        return c * 57.2957795;
    case 'radians':
        return c;
    case 'inches':
        return c * 250905600;
    case 'yards':
        return c * 6969600
    case 'meters':
    case 'metres':
        return c * 637300;
    case undefined:
        return c * 6373;
    default:
        throw new Error('unknown option given to "units"');
    }
};

function toRad(degree) {
    return degree * Math.PI / 180;
}

{'fraction_non_alphanumeric': 0.16327423943970235, 'fraction_numerical': 0.03939592908732764, 'mean_word_length': 2.9328743545611013, 'pattern_counts': {'":': 24, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6864518', 'n_tokens_mistral': 1658, 'n_tokens_neox': 1541, 'n_words': 391}