> After thinking far too long about how I can sort coordinates reliability, I chose the easy way out:<p>In addition to the code, please also give a plain language description: "We ensure that the first coordinate is the lexicographically smallest (i.e. most westward point). For line strings, reverse the coordinate list to make it so, and for polygons, rotate the coordinates to make it so."<p>> val reordered = coordinates.subList(index, coordinates.size - 1) + coordinates.subList(0, index)<p>This should say + coordinates.subList(0, index + 1), and then you can get rid of the code that checks for first != last.