public Collection<LuvPoint> getOrdered()
{
Collection<LuvPoint> result = new ArrayList<LuvPoint>(unorderedBoundary.size());
final Map<LuvPoint, Integer> distanses = new HashMap<LuvPoint, Integer>(unorderedBoundary.size());
LuvPoint centerPoint = calkcenter(cluster);
for (LuvPoint luvPoint : unorderedBoundary)
{
int cx = centerPoint.getX();
int cy = centerPoint.getY();
int nx = luvPoint.getX();
int ny = luvPoint.getY();
distanses.put(luvPoint, (cx - nx) * (cx - nx) + (cy - ny) * (cy - ny));
}
Set<LuvPoint> unprocesed = new HashSet<LuvPoint>(unorderedBoundary.size());
unprocesed.addAll(unorderedBoundary);
LuvPoint elem = null;
while (!unprocesed.isEmpty())
{
if (elem == null)
{
elem = unprocesed.iterator().next();
}
result.add(elem);
unprocesed.remove(elem);
Collection<LuvPoint> nearest = searchForNearest(elem, unprocesed);
if (!nearest.isEmpty())
{
Iterator<LuvPoint> nearests = nearest.iterator();
elem = nearests.next();
while (nearests.hasNext())
{
LuvPoint c = nearests.next();
if (distanses.get(c) > distanses.get(elem))
{
elem = c;
}
}