Refactor tilesegment handling and fix localMin/localMax functions to handle start/end of ring min maxes.