preSort method
Implementation
List<Coordinate> preSort(List<Coordinate> pts) {
Coordinate t;
// find the lowest point in the set. If two or more points have
// the same minimum y coordinate choose the one with the minimu x.
// This focal point is put in array location pts[0].
for (int i = 1; i < pts.length; i++) {
var pt0 = pts[0];
if ((pts[i].y < pt0.y) || ((pts[i].y == pt0.y) && (pts[i].x < pt0.x))) {
t = pt0;
pts[0] = pts[i];
pts[i] = t;
}
}
// sort the points radially around the focal point.
var radialComparator = RadialComparator(pts[0]);
var ptsTmp = pts.sublist(1);
ptsTmp.sort((a, b) => radialComparator.compare(a, b));
pts.setRange(1, pts.length, ptsTmp);
return pts;
}