code: def td_tr(points, dist_threshold):
      
      if len(points) <= 2:
          return points
      else:
          max_dist_threshold = 0
          found_index = 0
          delta_e = time_dist(points[-1], points[0]) * I_3600
          d_lat = points[-1].lat - points[0].lat
          d_lon = points[-1].lon - points[0].lon
  
          for i in range(1, len(points)-1):
              delta_i = time_dist(points[i], points[0]) * I_3600
  
              di_de = delta_i / delta_e
              point = Point(
                  points[0].lat + d_lat * di_de,
                  points[0].lon + d_lon * di_de,
                  None
              )
  
              dist = loc_dist(points[i], point)
              if dist > max_dist_threshold:
                  max_dist_threshold = dist
                  found_index = i
  
          if max_dist_threshold > dist_threshold:
              one = td_tr(points[:found_index], dist_threshold)
              two = td_tr(points[found_index:], dist_threshold)
              one.extend(two)
              return one
          else:
              return [points[0], points[-1]]
docs: Top-Down Time-Ratio Trajectory Compression Algorithm
  
      Detailed in https://www.itc.nl/library/Papers_2003/peer_ref_conf/meratnia_new.pdf
  
      Args:
          points (:obj:`list` of :obj:`Point`): trajectory or part of it
          dist_threshold (float): max distance error, in meters
      Returns:
          :obj:`list` of :obj:`Point`, compressed trajectory