Analyzing shapes as compositions of distances