2
我有一个CGPoint数组,并且希望根据离外部点最近的距离对它进行排序。我做了以下,但它返回不正确的结果。根据外部点对CGPoint数组进行排序
NSArray *sortedArray = [self.availableRenderPoints sortedArrayUsingComparator:^NSComparisonResult(NSValue *obj1, NSValue *obj2)
{
CGPoint p1 = [obj1 CGPointValue];
CGPoint p2 = [obj2 CGPointValue];
CGFloat distance1 = ccpDistance(startPoint, p1);
CGFloat distance2 = ccpDistance(startPoint, p2);
if (distance1 <= distance2) return p1.y < p2.y;
if (distance2 <= distance1) return p2.y < p1.y;
return p1.x < p2.x;
}];
这怎么能根据距离startPoint最近的距离排序?
应该可能只是'<(不是'<=') – Wain
@ Wain:是的,愚蠢的错误,更正了(谢谢!) –