I have one scenario as do cluster for the nearest CGPoint in UIView. So i have set of CGPoint NSArray, I trying to get the nearest value and do cluster but i could not get the logic : // my code
for (CGPoint firstObjOfCGPoint in cgPointGroupArray) {
for (CGPoint nextPoint in cgPointGroupArray) {
if (30>[self distanceBetween: firstObjOfCGPoint and:nextPoint]){
[shortestClusterArr addObject:nextPoint];
}
else{
[longestClusterArr addObject:nextPoint];
}
}
if(shortestClusterArr.count>2){
//clustered marker
[self addClusterMarker:shortestClusterArr];
}
else{
//dont cluster marker
}
}
}
//find distance
- (float)distanceBetween:(CGPoint)p1 and:(CGPoint)p2
{
return hypotf((p1.x-p2.x), (p1.y-p2.y));
}
Above code, looping time getting duplicate points as well override on the same object so if anyone knows the logic comment here,..