def getOrderedSurroundingLoops(perimeterWidth, surroundingLoops):
 insides = []
 orderedSurroundingLoops = []
 for loopIndex in xrange(len(surroundingLoops)):
  surroundingLoop = surroundingLoops[loopIndex]
  otherLoops = []
  for beforeIndex in xrange(loopIndex):
   otherLoops.append(surroundingLoops[beforeIndex].boundary)
  for afterIndex in xrange((loopIndex + 1), len(surroundingLoops)):
   otherLoops.append(surroundingLoops[afterIndex].boundary)
  if isPathEntirelyInsideLoops(otherLoops, surroundingLoop.boundary):
   insides.append(surroundingLoop)
  else:
   orderedSurroundingLoops.append(surroundingLoop)
 for outside in orderedSurroundingLoops:
  outside.getFromInsideSurroundings(insides, perimeterWidth)
 return orderedSurroundingLoops

def getOrderedSurroundingLoops ( perimeterWidth , surroundingLoops ) : insides = [ ] orderedSurroundingLoops = [ ] for loopIndex in xrange ( len ( surroundingLoops ) ) : surroundingLoop = surroundingLoops [ loopIndex ] otherLoops = [ ] for beforeIndex in xrange ( loopIndex ) : otherLoops . append ( surroundingLoops [ beforeIndex ] . boundary ) for afterIndex in xrange ( ( loopIndex + 1 ) , len ( surroundingLoops ) ) : otherLoops . append ( surroundingLoops [ afterIndex ] . boundary ) if isPathEntirelyInsideLoops ( otherLoops , surroundingLoop . boundary ) : insides . append ( surroundingLoop ) else : orderedSurroundingLoops . append ( surroundingLoop ) for outside in orderedSurroundingLoops : outside . getFromInsideSurroundings ( insides , perimeterWidth ) return orderedSurroundingLoops
get ordered surrounding loops from surrounding loops .