Qualitative polyline similarity testing with applications to query-by-sketch, indexing and classification