Quick code to try to have somehow a generic clustering code. Generic in the sense that we should be able to cluster easily different types of data (2D points, 3D points, lines, ...). Only requirement should be to provide a custom function to find the neighbors.
Demo:
Reference: