dbscan static method
DBSCAN clustering algorithm.
Returns a list of clusters, where each cluster is a list of LatLng points.
Implementation
static List<List<LatLng>> dbscan(List<LatLng> points, double eps, int minPoints) {
const distance = Distance();
final clusters = <List<LatLng>>[];
final visited = <LatLng>{};
final noise = <LatLng>[];
for (final point in points) {
if (visited.contains(point)) continue;
visited.add(point);
final neighbors = _regionQuery(point, points, eps, distance);
if (neighbors.length < minPoints) {
// Mark point as noise if it does not have enough neighbors.
noise.add(point);
} else {
// Create a new cluster and expand it.
final cluster = <LatLng>[];
clusters.add(cluster);
_expandCluster(point, neighbors, cluster, points, eps, minPoints, visited, distance);
}
}
return clusters;
}