<commit_before>interface LatLng {
  lat: number
  lng: number
}

const EARTH_RADIUS_IN_METERS = 6371e3

const toRadians = (degrees: number): number => degrees * (Math.PI / 180)

const haversineDistance = (point1: LatLng, point2: LatLng): number => {
  const φ1 = toRadians(point1.lat)
  const φ2 = toRadians(point2.lat)
  const Δφ = toRadians(point2.lat - point1.lat)
  const Δλ = toRadians(point2.lng - point1.lng)

  const a =
    Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
    Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2)
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))

  return EARTH_RADIUS_IN_METERS * c
}

export { haversineDistance as distance }
<commit_msg>Add docs to geo lib functions<commit_after>interface LatLng {
  lat: number
  lng: number
}

const EARTH_RADIUS_IN_METERS = 6371e3 // https://en.wikipedia.org/wiki/Earth_radius#Mean_radius

/**
 * Convert angular distance from degrees to radians
 *
 * @param {number} degrees - decimal degrees
 * @returns {number} radians
 */
const toRadians = (degrees: number): number => degrees * (Math.PI / 180)

/**
 * Calculates the haversine (spherical) distance between two geographic points.
 * Arguments are supplied as `LatLng` objects, with coordinates specified
 * as `lat` and `lng` properties in decimal degrees.
 *
 * See:
 * https://en.wikipedia.org/wiki/Haversine_formula
 * https://www.movable-type.co.uk/scripts/latlong.html
 *
 * @param {LatLng} point1 - an object with `lat` and `lng` properties
 * @param {LatLng} point2 - an object with `lat` and `lng` properties
 * @returns {number} Distance between point1 and point2, in meters
 */
const haversineDistance = (point1: LatLng, point2: LatLng): number => {
  const φ1 = toRadians(point1.lat)
  const φ2 = toRadians(point2.lat)
  const Δφ = toRadians(point2.lat - point1.lat)
  const Δλ = toRadians(point2.lng - point1.lng)

  const a =
    Math.sin(Δφ / 2) * Math.sin(Δφ / 2) +
    Math.cos(φ1) * Math.cos(φ2) * Math.sin(Δλ / 2) * Math.sin(Δλ / 2)
  const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a))

  return EARTH_RADIUS_IN_METERS * c
}

export { haversineDistance as distance }

{'fraction_non_alphanumeric': 0.131369798971482, 'fraction_numerical': 0.027115474520804116, 'mean_word_length': 3.692982456140351, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '77244', 'n_tokens_mistral': 855, 'n_tokens_neox': 804, 'n_words': 205}