A Complete Framework for Clustering Trajectories