lib/get-transitive-data.js
function segmentDissimilarity (s1: Segment, s2: Segment, {
  patterns,
  stops
}: {
  patterns: Array<Pattern>,
  stops: Array<Stop>
}): number {
  const pat1 = patterns.find((p) => p.pattern_id === s1.pattern_id)
  const pat2 = patterns.find((p) => p.pattern_id === s2.pattern_id)

  if (!pat1 || !pat2) return Infinity

  const s1f = s1.from_stop_index
  const s1t = s1.to_stop_index
  const s2f = s2.from_stop_index
  const s2t = s2.to_stop_index

  if (s1f == null || s1t == null || s2f == null || s2t == null) return Infinity

  function findStop (id: string): ?Stop {
    return stops.find((stop) => stop.stop_id === id)
  }

  const from1 = findStop(pat1.stops[s1f].stop_id)
  const to1 = findStop(pat1.stops[s1t].stop_id)
  const from2 = findStop(pat2.stops[s2f].stop_id)
  const to2 = findStop(pat2.stops[s2t].stop_id)

  if (!from1 || !from2 || !to1 || !to2) return Infinity

  const d1 = stopDistance(from1, from2)
  const d2 = stopDistance(to1, to2)
  return Math.max(d1, d2)
}
function segmentDissimilarity (s1: Segment, s2: Segment, {
  patterns,
  stops
}: {
  patterns: Array<Pattern>,
  stops: Array<Stop>
}): number {
  const pat1 = patterns.find((p) => p.pattern_id === s1.pattern_id)
  const pat2 = patterns.find((p) => p.pattern_id === s2.pattern_id)

  if (!pat1 || !pat2) return Infinity

  const s1f = s1.from_stop_index
  const s1t = s1.to_stop_index
  const s2f = s2.from_stop_index
  const s2t = s2.to_stop_index

  if (s1f == null || s1t == null || s2f == null || s2t == null) return Infinity

  function findStop (id: string): ?Stop {
    return stops.find((stop) => stop.stop_id === id)
  }

  const from1 = findStop(pat1.stops[s1f].stop_id)
  const to1 = findStop(pat1.stops[s1t].stop_id)
  const from2 = findStop(pat2.stops[s2f].stop_id)
  const to2 = findStop(pat2.stops[s2t].stop_id)

  if (!from1 || !from2 || !to1 || !to2) return Infinity

  const d1 = stopDistance(from1, from2)
  const d2 = stopDistance(to1, to2)
  return Math.max(d1, d2)
}
return the dissimilarity between two individual transit segments (each with only a single pattern, not yet merged)